diff --git a/run_valgrind_tests.sh b/run_valgrind_tests.sh index 33911ce..f68866d 100755 --- a/run_valgrind_tests.sh +++ b/run_valgrind_tests.sh @@ -2,6 +2,10 @@ for f in test_cases/*.brainrot; do echo "Running Valgrind on $f..." - valgrind --leak-check=full --error-exitcode=1 ./brainrot "$f" + if [[ $(basename "$f") == slorp_int* ]]; then + echo "42" | valgrind --leak-check=full --error-exitcode=1 ./brainrot "$f" + else + valgrind --leak-check=full --error-exitcode=1 ./brainrot "$f" + fi echo done \ No newline at end of file diff --git a/test_cases/slorp_char.brainrot b/test_cases/slorp_char.brainrot new file mode 100644 index 0000000..bb14347 --- /dev/null +++ b/test_cases/slorp_char.brainrot @@ -0,0 +1,6 @@ +skibidi main { + yap chr; + slorp(chr); + yapping("You typed: %c", chr); + bussin 0; +} diff --git a/test_cases/slorp_double.brainrot b/test_cases/slorp_double.brainrot new file mode 100644 index 0000000..a0cf581 --- /dev/null +++ b/test_cases/slorp_double.brainrot @@ -0,0 +1,6 @@ +skibidi main { + gigachad num; + slorp(num); + yapping("You typed: %f", num); + bussin 0; +} diff --git a/test_cases/slorp_float.brainrot b/test_cases/slorp_float.brainrot new file mode 100644 index 0000000..6b26793 --- /dev/null +++ b/test_cases/slorp_float.brainrot @@ -0,0 +1,6 @@ +skibidi main { + chad num; + slorp(num); + yapping("You typed: %f", num); + bussin 0; +} diff --git a/test_cases/slorp_int.brainrot b/test_cases/slorp_int.brainrot new file mode 100644 index 0000000..304b1c2 --- /dev/null +++ b/test_cases/slorp_int.brainrot @@ -0,0 +1,6 @@ +skibidi main { + rizz num; + slorp(num); + yapping("You typed: %d", num); + bussin 0; +} diff --git a/test_cases/slorp_short.brainrot b/test_cases/slorp_short.brainrot new file mode 100644 index 0000000..6593d83 --- /dev/null +++ b/test_cases/slorp_short.brainrot @@ -0,0 +1,6 @@ +skibidi main { + smol num; + slorp(num); + yapping("You typed: %d", num); + bussin 0; +} diff --git a/test_cases/slorp_string.brainrot b/test_cases/slorp_string.brainrot new file mode 100644 index 0000000..c6fad07 --- /dev/null +++ b/test_cases/slorp_string.brainrot @@ -0,0 +1,6 @@ +skibidi main { + yap string[32]; + slorp(string); + yapping("You typed: %s", string); + bussin 0; +} diff --git a/tests/expected_results.json b/tests/expected_results.json index 31d1a6c..4bc6063 100644 --- a/tests/expected_results.json +++ b/tests/expected_results.json @@ -42,5 +42,11 @@ "add_two_numbers": "3", "mul_two_numbers": "11.400000", "max_gigachad": "5.000000", - "is_prime": "W" + "is_prime": "W", + "slorp_int": "You typed: 42", + "slorp_short": "You typed: 69", + "slorp_float": "You typed: 3.140000", + "slorp_double": "You typed: 3.141592", + "slorp_char": "You typed: c", + "slorp_string": "You typed: skibidi bop bop yes yes" } diff --git a/tests/test_brainrot.py b/tests/test_brainrot.py index 6f9a961..e4b9d67 100644 --- a/tests/test_brainrot.py +++ b/tests/test_brainrot.py @@ -17,24 +17,34 @@ def test_brainrot_examples(example, expected_output): brainrot_path = os.path.abspath(os.path.join(script_dir, "../brainrot")) example_file_path = os.path.abspath(os.path.join(script_dir, f"../test_cases/{example}.brainrot")) - command = f"{brainrot_path} {example_file_path}" - + + if example.startswith("slorp_int"): + command = f"echo '42' | {brainrot_path} {example_file_path}" + elif example.startswith("slorp_short"): + command = f"echo '69' | {brainrot_path} {example_file_path}" + elif example.startswith("slorp_float"): + command = f"echo '3.14' | {brainrot_path} {example_file_path}" + elif example.startswith("slorp_double"): + command = f"echo '3.141592' | {brainrot_path} {example_file_path}" + elif example.startswith("slorp_char"): + command = f"echo 'c' | {brainrot_path} {example_file_path}" + elif example.startswith("slorp_string"): + command = f"echo 'skibidi bop bop yes yes' | {brainrot_path} {example_file_path}" + else: + command = f"{brainrot_path} {example_file_path}" + result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, shell=True) - - # Go back to original logic - only use stderr if stdout is empty actual_output = result.stdout.strip() if result.stdout.strip() else result.stderr.strip() - - # Special case: if output contains "Stderr:", we need both + if "Stderr:" in expected_output and result.stdout.strip(): actual_output = f"{result.stdout.strip()}\nStderr:\n{result.stderr.strip()}" - + assert actual_output == expected_output.strip(), ( f"Output for {example} did not match.\n" f"Expected:\n{expected_output}\n" f"Actual:\n{actual_output}" ) - - # Only check return code for non-error cases + if "Error:" not in expected_output: assert result.returncode == 0, ( f"Command for {example} failed with return code {result.returncode}\n"