-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·130 lines (114 loc) · 3.84 KB
/
Copy pathtest.sh
File metadata and controls
executable file
·130 lines (114 loc) · 3.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/bin/bash
# Parse arguments for --clean flag
for arg in "$@"
do
if [ "$arg" == "--clean" ]; then
echo "Cleaning build..."
make clean
fi
done
# Build the compiler first
make
# Colors
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m' # No Color
echo "Running ROX Tests..."
echo "--------------------------------"
fail_count=0
run_test() {
file=$1
echo -n "Testing $file... "
# Run the test and capture output/exit code
output=$(./rox run "$file" 2>&1)
exit_code=$?
if [ $exit_code -eq 0 ]; then
echo -e "${GREEN}PASSED${NC}"
else
echo -e "${RED}FAILED${NC}"
echo "$output"
fail_count=$((fail_count + 1))
fi
}
test_fail() {
file=$1
expected_error=$2
echo -n "Testing expected fail $file... "
output=$(./rox run "$file" 2>&1)
exit_code=$?
if [ $exit_code -ne 0 ]; then
if [ -n "$expected_error" ]; then
if echo "$output" | grep -q "$expected_error"; then
echo -e "${GREEN}PASSED (Failed as expected with correct error)${NC}"
else
echo -e "${RED}FAILED (Failed but with wrong error)${NC}"
echo "Expected error containing: $expected_error"
echo "Actual output:"
echo "$output"
fail_count=$((fail_count + 1))
fi
else
echo -e "${GREEN}PASSED (Failed as expected)${NC}"
fi
else
echo -e "${RED}FAILED (Should have failed but passed)${NC}"
echo "$output"
fail_count=$((fail_count + 1))
fi
}
# Run verified algorithms
run_test "test/binary_search.rox"
run_test "test/good_test.rox"
run_test "test/longest_substring.rox"
run_test "test/max_subarray.rox"
run_test "test/test_break.rox"
run_test "test/test_continue.rox"
run_test "test/test_cpp_collision.rox"
run_test "test/test_cpp_keywords.rox"
run_test "test/test_dict.rox"
run_test "test/test_format_not.rox"
run_test "test/test_format_out.rox"
run_test "test/test_format.rox"
run_test "test/test_functions_as_values.rox"
run_test "test/test_list_set.rox"
run_test "test/test_math.rox"
run_test "test/test_pop.rox"
run_test "test/test_regression.rox"
run_test "test/test_result_error.rox"
run_test "test/test_string.rox"
run_test "test/test_range.rox"
run_test "test/test_for_in_list.rox"
run_test "test/types_record_basic.rox"
run_test "test/types_composition_nested.rox"
run_test "test/types_copy_semantics.rox"
run_test "test/types_functions_not_methods.rox"
run_test "test/types_field_mutation.rox"
run_test "test/types_default_record.rox"
run_test "test/types_default_primitives.rox"
run_test "test/types_default_nested.rox"
run_test "test/two_sum.rox"
run_test "test/valid_parentheses.rox"
run_test "test/test_flow_sensitive_return.rox"
# run tests that should fail
test_fail "test/test_roxv26_prefix.rox"
test_fail "test/test_string_fail.rox"
test_fail "test/test_flow_invalid_1.rox" "getValue(res) is unsafe"
test_fail "test/test_flow_invalid_2.rox" "getValue(res) is unsafe"
test_fail "test/test_dict_fail.rox" "Type Error: Dictionary value type mismatch"
test_fail "test/test_list_append_fail.rox" "Type Error: List append type mismatch"
test_fail "test/test_range_fail.rox" "range() step cannot be 0"
test_fail "test/test_iterate_mutate_fail.rox" "Cannot mutate"
test_fail "test/types_missing_field_fail.rox" "Missing field"
test_fail "test/types_unknown_field_fail.rox" "Unknown field"
test_fail "test/types_duplicate_field_fail.rox" "Duplicate field"
test_fail "test/types_field_type_mismatch_fail.rox" "Type Error"
test_fail "test/types_unknown_field_access_fail.rox" "Unknown field"
test_fail "test/types_uninitialized_fail.rox" "Uninitialized record"
echo "--------------------------------"
if [ $fail_count -eq 0 ]; then
echo -e "${GREEN}All tests passed!${NC}"
exit 0
else
echo -e "${RED}$fail_count tests failed.${NC}"
exit 1
fi