From c780cbb6acd0e0526f2d305138190392bdc8cdd7 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 24 Jan 2026 01:43:01 +0900 Subject: refactor: organize test files --- tests/cli.sh | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 tests/cli.sh (limited to 'tests/cli.sh') diff --git a/tests/cli.sh b/tests/cli.sh new file mode 100644 index 0000000..fc8a481 --- /dev/null +++ b/tests/cli.sh @@ -0,0 +1,79 @@ +# --version +expected="ducc v0.3.0" + +if [[ "$("$ducc" --version)" != "$expected" ]]; then + echo "invalid output" >&2 + exit 1 +fi + +# assembly output +cat > foo.c <<'EOF' +int main() {} +EOF + +"$ducc" -o bar.s foo.c +if [[ $? -ne 0 ]]; then + exit 1 +fi +gcc -o a.out bar.s +./a.out "$@" +exit_code=$? + +if [[ $exit_code -ne 0 ]]; then + echo "invalid exit code: $exit_code" >&2 + exit 1 +fi + +# argc/argv +cat <<'EOF' > expected +argc = 4 +argv[1] = hoge +argv[2] = piyo +argv[3] = fuga +EOF +test_diff hoge piyo fuga<<'EOF' +int printf(); + +int main(int argc, char** argv) { + printf("argc = %d\n", argc); + int i; + for (i = 1; i < argc; ++i) { + printf("argv[%d] = %s\n", i, argv[i]); + } + return 0; +} +EOF + +# compile errors +cat <<'EOF' > expected +main.c:2: undefined function: f +EOF +test_compile_error <<'EOF' +int main() { + f(); +} +EOF + +# TODO: improve error message +# cat <<'EOF' > expected +# main.c:1: expected ';' or '{', but got '}' +# EOF +cat <<'EOF' > expected +main.c:1: expected ';', but got '}' +EOF + +test_compile_error <<'EOF' +int main() } +EOF + +# TODO: improve error message +# cat <<'EOF' > expected +# main.c:1: expected ';' or '{', but got '}' +# EOF +cat <<'EOF' > expected +main.c:1: expected ';', but got '123' +EOF + +test_compile_error <<'EOF' +int main() 123 +EOF -- cgit v1.3-1-g0d28