Skip to content

Commit

Permalink
test: update runner for user inputs and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
anirudhgray committed Oct 25, 2024
1 parent 8fa4635 commit 3505582
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 2 deletions.
9 changes: 7 additions & 2 deletions tahini/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions tahini/tests/input.tah
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
input();
1 change: 1 addition & 0 deletions tahini/tests/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
aziraphale
4 changes: 4 additions & 0 deletions tahini/tests/input2.tah
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var name = input();
print name;

// aziraphale
1 change: 1 addition & 0 deletions tahini/tests/input2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
aziraphale

0 comments on commit 3505582

Please sign in to comment.