From 3505582dd725a99f01d56d4d52d487ef02bae459 Mon Sep 17 00:00:00 2001 From: anirudh Date: Fri, 25 Oct 2024 18:20:57 +0530 Subject: [PATCH] test: update runner for user inputs and add tests --- tahini/run_tests.sh | 9 +++++++-- tahini/tests/input.tah | 1 + tahini/tests/input.txt | 1 + tahini/tests/input2.tah | 4 ++++ tahini/tests/input2.txt | 1 + 5 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 tahini/tests/input.tah create mode 100644 tahini/tests/input.txt create mode 100644 tahini/tests/input2.tah create mode 100644 tahini/tests/input2.txt diff --git a/tahini/run_tests.sh b/tahini/run_tests.sh index 4966150..fbf1ad9 100755 --- a/tahini/run_tests.sh +++ b/tahini/run_tests.sh @@ -20,10 +20,15 @@ fi # Function to run a single test run_test() { local test_file=$1 + local input_file="${test_file%.tah}.txt" local expected_output=$(grep -E '^// ' "$test_file" | sed 's/^\/\/ //') - # Run the JAR file and capture both stdout and stderr - local actual_output=$(java -jar "$JAR_PATH" "$test_file" 2>&1) + # Run the JAR file with input redirection and capture both stdout and stderr + if [ -f "$input_file" ]; then + local actual_output=$(java -jar "$JAR_PATH" "$test_file" < "$input_file" 2>&1) + else + local actual_output=$(java -jar "$JAR_PATH" "$test_file" 2>&1) + fi if [ "$expected_output" == "$actual_output" ]; then echo -e "\033[32mTest $test_file passed.\033[0m" diff --git a/tahini/tests/input.tah b/tahini/tests/input.tah new file mode 100644 index 0000000..0ec402e --- /dev/null +++ b/tahini/tests/input.tah @@ -0,0 +1 @@ +input(); diff --git a/tahini/tests/input.txt b/tahini/tests/input.txt new file mode 100644 index 0000000..d9ad33a --- /dev/null +++ b/tahini/tests/input.txt @@ -0,0 +1 @@ +aziraphale diff --git a/tahini/tests/input2.tah b/tahini/tests/input2.tah new file mode 100644 index 0000000..07385a3 --- /dev/null +++ b/tahini/tests/input2.tah @@ -0,0 +1,4 @@ +var name = input(); +print name; + +// aziraphale diff --git a/tahini/tests/input2.txt b/tahini/tests/input2.txt new file mode 100644 index 0000000..d9ad33a --- /dev/null +++ b/tahini/tests/input2.txt @@ -0,0 +1 @@ +aziraphale