aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/001-missing_arguments.sh7
-rw-r--r--tests/002-too_many_arguments.sh9
-rw-r--r--tests/003-unknown_option.sh9
-rw-r--r--tests/004-missing_argument_for_option.sh10
-rw-r--r--tests/005-incorrect_buffer_size.sh11
-rw-r--r--tests/006-incorrect_sector_size.sh11
-rw-r--r--tests/Makefile8
-rw-r--r--tests/assert.sh19
8 files changed, 81 insertions, 3 deletions
diff --git a/tests/001-missing_arguments.sh b/tests/001-missing_arguments.sh
index baa7af1..8e00bf0 100644
--- a/tests/001-missing_arguments.sh
+++ b/tests/001-missing_arguments.sh
@@ -1,7 +1,10 @@
#!/bin/sh
+source ./assert.sh
+
PROGRAM_EXEC="$1"
-$PROGRAM_EXEC 1>/dev/null 2>&1
+assert_error "missing arguments" $PROGRAM_EXEC
+assert_error "missing arguments" $PROGRAM_EXEC arg
-[ $? -ne 0 ] && exit 0 || exit 1
+exit 0
diff --git a/tests/002-too_many_arguments.sh b/tests/002-too_many_arguments.sh
new file mode 100644
index 0000000..b6a1990
--- /dev/null
+++ b/tests/002-too_many_arguments.sh
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+source ./assert.sh
+
+PROGRAM_EXEC="$1"
+
+assert_error "too many arguments" $PROGRAM_EXEC arg1 arg2 arg3 arg4
+
+exit 0
diff --git a/tests/003-unknown_option.sh b/tests/003-unknown_option.sh
new file mode 100644
index 0000000..919f125
--- /dev/null
+++ b/tests/003-unknown_option.sh
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+source ./assert.sh
+
+PROGRAM_EXEC="$1"
+
+assert_error "unknown option '-x'" $PROGRAM_EXEC -x ref out
+
+exit 0
diff --git a/tests/004-missing_argument_for_option.sh b/tests/004-missing_argument_for_option.sh
new file mode 100644
index 0000000..071ea07
--- /dev/null
+++ b/tests/004-missing_argument_for_option.sh
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+source ./assert.sh
+
+PROGRAM_EXEC="$1"
+
+assert_error "missing argument for option '-b'" $PROGRAM_EXEC -b
+assert_error "missing argument for option '-s'" $PROGRAM_EXEC -s
+
+exit 0
diff --git a/tests/005-incorrect_buffer_size.sh b/tests/005-incorrect_buffer_size.sh
new file mode 100644
index 0000000..8c88b54
--- /dev/null
+++ b/tests/005-incorrect_buffer_size.sh
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+source ./assert.sh
+
+PROGRAM_EXEC="$1"
+
+assert_error "incorrect sector size" $PROGRAM_EXEC -s abc123 ref out
+assert_error "sector size cannot be 0" $PROGRAM_EXEC -s 0 ref out
+assert_error "sector size cannot larger than buffer size" $PROGRAM_EXEC -s 2 -b 1 ref out
+
+exit 0
diff --git a/tests/006-incorrect_sector_size.sh b/tests/006-incorrect_sector_size.sh
new file mode 100644
index 0000000..484c09e
--- /dev/null
+++ b/tests/006-incorrect_sector_size.sh
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+source ./assert.sh
+
+PROGRAM_EXEC="$1"
+
+assert_error "incorrect buffer size" $PROGRAM_EXEC -b abc123 ref out
+assert_error "buffer size cannot be 0" $PROGRAM_EXEC -b 0 ref out
+assert_error "buffer size is not multiple of sector size" $PROGRAM_EXEC -b 3 -s 2 ref out
+
+exit 0
diff --git a/tests/Makefile b/tests/Makefile
index eb009c1..fb58ff6 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -1,4 +1,10 @@
PROGRAM_EXEC=../src/$(PROGRAM_NAME)
all:
- sh ./001-missing_arguments.sh $(PROGRAM_EXEC)
+ for t in [0-9]*.sh ; do \
+ echo $$t; \
+ sh ./$$t ../src/diff-dd; \
+ # Testing of the return value must return true on the test failure. \
+ # If the return value is zero, it means a successful test. \
+ [ $$? -ne 0 ] && exit 1 || true; \
+ done
diff --git a/tests/assert.sh b/tests/assert.sh
new file mode 100644
index 0000000..ba73f41
--- /dev/null
+++ b/tests/assert.sh
@@ -0,0 +1,19 @@
+function assert_error()
+{
+ expected_stderr="$1"
+
+ shift 1
+ actual_stderr="$("$@" 2>&1 1>/dev/null)"
+ retval=$?
+ is_stderr_expected="$(echo "$actual_stderr" | grep -i "$expected_stderr")"
+
+ if [ $retval -eq 0 ]; then
+ echo "assert_error: Return value is $retval, expected != 0"
+ exit 1
+ elif [ -z "$is_stderr_expected" ]; then
+ echo "assert_error: stderr does not contain expected string"
+ echo " actual: $actual_stderr"
+ echo " expected: $expected_stderr"
+ exit 1
+ fi
+}