aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xtests/t0001-shebang.t46
-rwxr-xr-xtests/t0002-fail.t25
-rwxr-xr-xtests/t0010-check_args.t23
-rwxr-xr-xtests/t0100-redo.t11
4 files changed, 105 insertions, 0 deletions
diff --git a/tests/t0001-shebang.t b/tests/t0001-shebang.t
new file mode 100755
index 0000000..31a40a5
--- /dev/null
+++ b/tests/t0001-shebang.t
@@ -0,0 +1,46 @@
+#!/bin/sh -e
+# Copyright (c) 2015 Tharre
+#
+# This software may be modified and distributed under the terms
+# of the MIT license. See the LICENSE file for details.
+
+test_description='Test if shebang line is honored.
+
+Requires /proc/<pid>/cmdline, so it may not work on some platforms'
+
+. ./sharness.sh
+
+cat > "shebang.do" <<'EOF'
+#!/bin/sh
+cat /proc/$$/cmdline | tr "\0" " " | cut -d' ' -f1,2
+EOF
+
+cat > "shebang2.do" <<'EOF'
+cat /proc/$$/cmdline | tr "\0" " " | cut -d' ' -f1,2
+EOF
+
+cat > "echo.do" <<'EOF'
+#!/usr/bin/env echo
+EOF
+
+test_expect_success "/bin/sh exists" "
+ test -e /bin/sh
+"
+
+test_expect_success "/usr/bin/env exists" "
+ test -e /usr/bin/env
+"
+
+test_expect_success "/proc/<pid>/cmdline reports correct shebang" "
+ redo shebang | grep -q '/bin/sh shebang.do'
+"
+
+test_expect_success "'/bin/sh -e' is used if no shebang is specified" "
+ redo shebang2 | grep -q 'bin/sh -e'
+"
+
+test_expect_success "'/usr/bin/env echo' works" "
+ redo echo | grep -q echo.do
+"
+
+test_done
diff --git a/tests/t0002-fail.t b/tests/t0002-fail.t
new file mode 100755
index 0000000..c8ed4a2
--- /dev/null
+++ b/tests/t0002-fail.t
@@ -0,0 +1,25 @@
+#!/bin/sh -e
+# Copyright (c) 2015 Tharre
+#
+# This software may be modified and distributed under the terms
+# of the MIT license. See the LICENSE file for details.
+
+test_description='Abort if do-script returns nonzero'
+
+. ./sharness.sh
+
+cat > "fail.do" <<'EOF'
+#!/bin/sh -e
+echo "fail" > $3
+exit 1
+EOF
+
+test_expect_success "return nonzero" "
+ test_must_fail redo fail
+"
+
+test_expect_success "target file was not created" "
+ test_must_fail test -e fail
+"
+
+test_done
diff --git a/tests/t0010-check_args.t b/tests/t0010-check_args.t
new file mode 100755
index 0000000..feae935
--- /dev/null
+++ b/tests/t0010-check_args.t
@@ -0,0 +1,23 @@
+#!/bin/sh -e
+# Copyright (c) 2015 Tharre
+#
+# This software may be modified and distributed under the terms
+# of the MIT license. See the LICENSE file for details.
+
+test_description='Check arguments supplied to the do-script'
+
+. ./sharness.sh
+
+mkdir d &&
+cat > "d/check_args.ext1.ext2.do" <<'EOF'
+#!/bin/sh -e
+[ "$1" = "check_args.ext1.ext2" ]
+[ "$2" = "check_args.ext1" ]
+[ "$3" != "check_args.ext1.ext2" ]
+EOF
+
+test_expect_success "check arguments" "
+ redo d/check_args.ext1.ext2
+"
+
+test_done
diff --git a/tests/t0100-redo.t b/tests/t0100-redo.t
new file mode 100755
index 0000000..f830580
--- /dev/null
+++ b/tests/t0100-redo.t
@@ -0,0 +1,11 @@
+#!/bin/sh -e
+# Copyright (c) 2015 Tharre
+#
+# This software may be modified and distributed under the terms
+# of the MIT license. See the LICENSE file for details.
+
+test_description='Redo tests'
+
+. ./sharness.sh
+
+test_done