M meson.build => meson.build +3 -1
@@ 75,7 75,7 @@ mrsh = declare_dependency(
include_directories: mrsh_inc,
)
-executable(
+mrsh_exe = executable(
'mrsh',
files([
'main.c',
@@ 92,6 92,8 @@ executable(
dependencies: [mrsh],
)
+subdir('test')
+
pkgconfig = import('pkgconfig')
pkgconfig.generate(
libraries: lib_mrsh,
A test/data/if.sh => test/data/if.sh +10 -0
@@ 0,0 1,10 @@
+#!/bin/sh
+
+if true; then echo 1a; fi
+if true; then echo 2a; else echo 2b; fi
+if false; then echo 3a; else echo 3b; fi
+if false; then echo 4a; elif true; then echo 4b; else echo 4c; fi
+
+if false; then
+ echo 5a
+fi
A test/data/loop.sh => test/data/loop.sh +5 -0
@@ 0,0 1,5 @@
+#!/bin/sh
+
+while [ $n -ne 10 ]; do
+ echo a
+done
A test/data/word.sh => test/data/word.sh +11 -0
@@ 0,0 1,11 @@
+#!/bin/sh
+
+# This is a comment
+
+echo a b c
+echo d # e f
+echo 'a b c'
+echo "a b c"
+
+echo a"*"b'c"'
+echo "a\"b\\" "'hey'" '"hey"' '#' \''a'
A test/meson.build => test/meson.build +16 -0
@@ 0,0 1,16 @@
+test_exe = find_program('./test.sh')
+ref_exe = find_program('sh', required: false)
+
+test_files = [
+ 'if.sh',
+ 'loop.sh',
+ 'word.sh',
+]
+
+foreach test_file : test_files
+ test(
+ test_file,
+ test_exe,
+ args: [mrsh_exe.full_path(), ref_exe.path(), 'data/'+test_file],
+ )
+endforeach
A test/test.sh => test/test.sh +23 -0
@@ 0,0 1,23 @@
+#!/bin/sh
+
+dir=$(dirname "$0")
+
+mrsh="$1"
+ref="$2"
+testcase="$dir/$3"
+
+mrsh_out=$("$mrsh" "$testcase")
+mrsh_ret=$?
+ref_out=$("$ref" "$testcase")
+ref_ret=$?
+if [ "$mrsh_ret" != "$ref_ret" ] || [ "$mrsh_out" != "$ref_out" ] ; then
+ echo >&2 "$testcase: mismatch"
+ echo >&2 ""
+ echo >&2 "mrsh: $mrsh_ret"
+ echo >&2 "$mrsh_out"
+ echo >&2 ""
+ echo >&2 "ref: $ref_ret"
+ echo >&2 "$ref_out"
+ echo >&2 ""
+ exit 1
+fi