Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "feat: user input" #107

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion run_valgrind_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions test_cases/slorp_char.brainrot
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
skibidi main {
yap chr;
slorp(chr);
yapping("You typed: %c", chr);
bussin 0;
}
6 changes: 6 additions & 0 deletions test_cases/slorp_double.brainrot
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
skibidi main {
gigachad num;
slorp(num);
yapping("You typed: %f", num);
bussin 0;
}
6 changes: 6 additions & 0 deletions test_cases/slorp_float.brainrot
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
skibidi main {
chad num;
slorp(num);
yapping("You typed: %f", num);
bussin 0;
}
6 changes: 6 additions & 0 deletions test_cases/slorp_int.brainrot
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
skibidi main {
rizz num;
slorp(num);
yapping("You typed: %d", num);
bussin 0;
}
6 changes: 6 additions & 0 deletions test_cases/slorp_short.brainrot
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
skibidi main {
smol num;
slorp(num);
yapping("You typed: %d", num);
bussin 0;
}
6 changes: 6 additions & 0 deletions test_cases/slorp_string.brainrot
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
skibidi main {
yap string[32];
slorp(string);
yapping("You typed: %s", string);
bussin 0;
}
8 changes: 7 additions & 1 deletion tests/expected_results.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
28 changes: 19 additions & 9 deletions tests/test_brainrot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading