~emersion/mrsh-dev

Add check target to makefile v1 PROPOSED

Drew DeVault: 1
 Add check target to makefile

 6 files changed, 39 insertions(+), 16 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~emersion/mrsh-dev/patches/6555/mbox | git am -3
Learn more about email & git

[PATCH] Add check target to makefile Export this patch

---
 Makefile               | 22 +++++++++++++++++++++-
 configure              |  3 +++
 test/conformance/if.sh | 16 ++++++++--------
 test/harness.sh        |  6 +++---
 test/meson.build       |  2 +-
 test/pipeline.sh       |  6 +++---
 6 files changed, 39 insertions(+), 16 deletions(-)
 mode change 100644 => 100755 test/harness.sh

diff --git a/Makefile b/Makefile
index c8522a7..7e9b6dd 100644
--- a/Makefile
+++ b/Makefile
@@ -91,6 +91,19 @@ public_includes=\
 		include/mrsh/parser.h \
 		include/mrsh/shell.h
 
+tests=\
+		test/conformance/if.sh \
+		test/case.sh \
+		test/command.sh \
+		test/for.sh \
+		test/function.sh \
+		test/loop.sh \
+		test/pipeline.sh \
+		test/subshell.sh \
+		test/syntax.sh \
+		test/ulimit.sh \
+		test/word.sh
+
 include $(OUTDIR)/cppcache
 
 $(OUTDIR)/libmrsh.a: $(libmrsh_objects)
@@ -123,6 +136,13 @@ highlight: $(OUTDIR)/libmrsh.a $(highlight_objects)
 
 all: mrsh highlight libmrsh.so.$(SOVERSION) $(OUTDIR)/mrsh.pc
 
+check: mrsh $(tests)
+	@for t in $(tests); do \
+		printf '%-30s... ' "$$t" && \
+		MRSH=./mrsh REF_SH=$${REF_SH:-sh} ./test/harness.sh $$t >/dev/null && \
+		echo OK || echo FAIL; \
+	done
+
 install: mrsh libmrsh.so.$(SOVERSION) $(OUTDIR)/mrsh.pc
 	mkdir -p $(BINDIR) $(LIBDIR) $(INCDIR)/mrsh $(PCDIR)
 	install -m755 mrsh $(BINDIR)/mrsh
@@ -139,4 +159,4 @@ clean:
 		$(highlight_objects) \
 		mrsh higlight libmrsh.so.$(SOVERSION) $(OUTDIR)/mrsh.pc
 
-.PHONY: all install clean
+.PHONY: all install clean check
diff --git a/configure b/configure
index 7cb2ba6..327a64e 100755
--- a/configure
+++ b/configure
@@ -16,6 +16,9 @@ do
 		--prefix=*)
 			PREFIX=${arg#*=}
 			;;
+		--without-readline)
+			use_readline=0
+			;;
 		--with-readline=*)
 			use_readline=1
 			readline=${arg#*=}
diff --git a/test/conformance/if.sh b/test/conformance/if.sh
index 258fbd7..0be4160 100644
--- a/test/conformance/if.sh
+++ b/test/conformance/if.sh
@@ -7,20 +7,20 @@
 # pass
 # pass
 
-echo >&2 "-> if..fi with true condition"
+echo "-> if..fi with true condition"
 if true
 then
 	echo pass
 fi
 
-echo >&2 "-> if..fi with false condition"
+echo "-> if..fi with false condition"
 if false
 then
 	echo >&2 "fail: This branch should not have run" && exit 1
 fi
 echo pass
 
-echo >&2 "-> if..else..fi with true condition"
+echo "-> if..else..fi with true condition"
 if true
 then
 	echo pass
@@ -28,7 +28,7 @@ else
 	echo >&2 "fail: This branch should not have run" && exit 1
 fi
 
-echo >&2 "-> if..else..fi with false condition"
+echo "-> if..else..fi with false condition"
 if false
 then
 	echo >&2 "fail: This branch should not have run" && exit 1
@@ -36,7 +36,7 @@ else
 	echo pass
 fi
 
-echo >&2 "-> if..else..fi with true condition"
+echo "-> if..else..fi with true condition"
 if true
 then
 	echo pass
@@ -44,7 +44,7 @@ else
 	echo >&2 "fail: This branch should not have run" && exit 1
 fi
 
-echo >&2 "-> if..else..elif..fi with false condition"
+echo "-> if..else..elif..fi with false condition"
 if false
 then
 	echo >&2 "fail: This branch should not have run" && exit 1
@@ -55,7 +55,7 @@ else
 	echo >&2 "fail: This branch should not have run" && exit 1
 fi
 
-echo >&2 "-> test exit status"
+echo "-> test exit status"
 if true
 then
 	( exit 10 )
@@ -71,7 +71,7 @@ else
 fi
 [ $# -eq 20 ] || { echo >&2 "fail: Expected status code = 20" && exit 1; }
 
-echo >&2 "-> test alternate syntax"
+echo "-> test alternate syntax"
 # These tests are only expected to parse, they do not make assertions
 if true; then true; fi
 if true; then true; else true; fi
diff --git a/test/harness.sh b/test/harness.sh
old mode 100644
new mode 100755
index d05a744..885aa74
--- a/test/harness.sh
+++ b/test/harness.sh
@@ -1,11 +1,11 @@
 #!/bin/sh
 dir=$(dirname "$0")
-testcase="$dir/$1"
+testcase="$1"
 
-echo >&2 "Running with mrsh"
+echo "Running with mrsh"
 mrsh_out=$("$MRSH" "$testcase")
 mrsh_ret=$?
-echo >&2 "Running with reference shell"
+echo "Running with reference shell"
 ref_out=$("$REF_SH" "$testcase")
 ref_ret=$?
 if [ $mrsh_ret -ne $ref_ret ] || [ "$mrsh_out" != "$ref_out" ]
diff --git a/test/meson.build b/test/meson.build
index 8496992..6a7134e 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -18,7 +18,7 @@ test_files = [
 
 foreach test_file : test_files
 	test(
-		test_file,
+		join_paths(meson.current_source_dir(), test_file),
 		harness,
 		env: [
 			'MRSH=@0@'.format(mrsh_exe.full_path()),
diff --git a/test/pipeline.sh b/test/pipeline.sh
index 2cd56a7..ebfbd93 100644
--- a/test/pipeline.sh
+++ b/test/pipeline.sh
@@ -1,12 +1,12 @@
 #!/bin/sh
 
-echo >&2 "Pipeline with 1 command"
+echo "Pipeline with 1 command"
 echo "a b c d"
 
-echo >&2 "Pipeline with 2 commands"
+echo "Pipeline with 2 commands"
 echo "a b c d" | sed s/b/B/
 
-echo >&2 "Pipeline with 3 commands"
+echo "Pipeline with 3 commands"
 echo "a b c d" | sed s/b/B/ | sed s/c/C/
 
 # https://github.com/emersion/mrsh/issues/100
-- 
2.22.0
View this thread in the archives