summary refs log tree commit diff stats
path: root/build.sh
diff options
context:
space:
mode:
authorSoniEx2 <endermoneymod@gmail.com>2024-06-04 23:48:59 -0300
committerSoniEx2 <endermoneymod@gmail.com>2024-06-04 23:48:59 -0300
commitdba1285ca98d7a325f05b77b805089b3edd61867 (patch)
treef5ddfbd1c86a7db464dc1c459c38c5e256e49089 /build.sh
parent5eecbd6ef771a54b455d96f4033212062d7c3f8f (diff)
Implement cratera REPL
Diffstat (limited to 'build.sh')
-rwxr-xr-xbuild.sh53
1 files changed, 45 insertions, 8 deletions
diff --git a/build.sh b/build.sh
index 6f70eb0..06686dd 100755
--- a/build.sh
+++ b/build.sh
@@ -21,22 +21,52 @@ do_build() {
 	else
 		printf "#!%s %s\n" "$ENV_WRAPPER" "$LUA_INTERPRETER" >out/bin/cratera || exit 1
 	fi
-	cat src/bin/cratera.lua >>out/bin/cratera || exit 1
+	tail -n +2 src/bin/cratera.lua >>out/bin/cratera || exit 1
 	chmod +x out/bin/cratera || exit 1
 	env -i "$LUA_INTERPRETER" src/host/genpath.lua >out/lua/cratera/prebuilt/path.lua || exit 1
 }
 
+test_wrapper() {
+	eval "$@" || {
+		printf 'Test failed:'
+		printf ' %s' "$@"
+		printf '\n'
+		exit 2
+	}
+}
+
 do_test() {
 	# FIXME this does NOT handle LUA_PATH correctly.
 	# FIXME nor LUA_INIT.
 	mkdir -p out/test || exit 2
-	# these tests use the regular lua interpreter
-	LUA_PATH='./out/lua/?.lua;./out/lua/?/init.lua;;' "$LUA_INTERPRETER" test/testp.lua || exit 2
-	LUA_PATH='./out/lua/?.lua;./out/lua/?/init.lua;;' "$LUA_INTERPRETER" test/testc.lua || exit 2
-	LUA_PATH='./out/lua/?.lua;./out/lua/?/init.lua;;' "$LUA_INTERPRETER" test/testbc.lua || exit 2
-	LUA_PATH='./out/lua/?.lua;./out/lua/?/init.lua;;' CRATERA_PATH='./test/?.cratera;./out/cratera/?.cratera;;' "$LUA_INTERPRETER" test/test_bootstrap.lua || exit 2
-	# these tests use the cratera interpreter
-	LUA_PATH='./out/lua/?.lua;./out/lua/?/init.lua;;' out/bin/cratera test/tests.cratera || exit 2
+	(
+		export LUA_PATH='./out/lua/?.lua;./out/lua/?/init.lua;;'
+		export CRATERA_PATH='./test/?.cratera;./out/cratera/?.cratera;;'
+		# these tests use the regular lua interpreter
+		"$LUA_INTERPRETER" test/testp.lua || exit 2
+		"$LUA_INTERPRETER" test/testc.lua || exit 2
+		"$LUA_INTERPRETER" test/testbc.lua || exit 2
+		"$LUA_INTERPRETER" test/test_bootstrap.lua || exit 2
+		# these tests use the cratera interpreter
+		test_wrapper 'out/bin/cratera -v | grep Cratera'
+		test_wrapper 'out/bin/cratera -invalid 2>&1 | grep usage'
+		test_wrapper 'out/bin/cratera -void 2>&1 | grep usage'
+		test_wrapper 'out/bin/cratera -e 2>&1 | grep usage'
+		test_wrapper '! out/bin/cratera -e '\''error("hello")'\'''
+		test_wrapper 'out/bin/cratera -e '\''arg[3] = nil'\'' -e '\''print("still prints")'\'
+		test_wrapper 'out/bin/cratera -e '\''print(craterapath)'\'''
+		test_wrapper 'out/bin/cratera test/tests.cratera'
+		test_wrapper 'out/bin/cratera test/interp-error.cratera string 2>&1 | grep '\''5: string'\'
+		test_wrapper 'out/bin/cratera test/interp-error.cratera nil 2>&1 | grep '\''nil value'\'
+		test_wrapper 'out/bin/cratera test/interp-error.cratera table 2>&1 | grep '\''table value'\'
+		test_wrapper 'out/bin/cratera test/interp-error.cratera metaerror 2>&1 | grep '\''overflow\|handling'\'
+		test_wrapper 'printf '\''_PROMPT=setmetatable({}, {__tostring=error})\n'\'' | out/bin/cratera -i 2>&1 ' # | grep '\''overflow\|handling'\'
+	) || exit 2
+}
+
+do_interp() {
+	shift
+	LUA_PATH='./out/lua/?.lua;./out/lua/?/init.lua;;' CRATERA_PATH='./test/?.cratera;./out/cratera/?.cratera;;' out/bin/cratera "$@" || exit 3
 }
 
 case "$1" in
@@ -50,6 +80,13 @@ case "$1" in
 			'The currently selected env wrapper is:' \
 			"$(printf '    ENV_WRAPPER=%s' "$ENV_WRAPPER")"
 		;;
+	interp)
+		do_build
+		do_interp "$@"
+		;;
+	interp-only)
+		do_interp "$@"
+		;;
 	test-only)
 		do_test
 		;;