Skip to content

Commit

Permalink
hack the test script
Browse files Browse the repository at this point in the history
  • Loading branch information
Akuli committed Dec 3, 2023
1 parent 4576308 commit e563148
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 15 deletions.
2 changes: 1 addition & 1 deletion examples/aoc2023/day01/part1.jou
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ def main() -> int:
result += 10*(*first - '0')
result += *last - '0'

printf("%d\n", result)
printf("%d\n", result) # Output: 54630
return 0
3 changes: 1 addition & 2 deletions examples/aoc2023/day01/part2.jou
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,5 @@ def main() -> int:
result += 10*parse_prefix_digit(first)
result += parse_prefix_digit(last)

printf("%d\n", result)
printf("%d\n", result) # Output: 54770
return 0

2 changes: 1 addition & 1 deletion examples/aoc2023/day02/part1.jou
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ def main() -> int:
if game_is_possible(&id_end[1]):
result += game_id

printf("%d\n", result)
printf("%d\n", result) # Output: 1853
return 0
2 changes: 1 addition & 1 deletion examples/aoc2023/day02/part2.jou
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ def main() -> int:
game = parse_game(&id_end[1])
result += game.get_power()

printf("%d\n", result)
printf("%d\n", result) # Output: 72706
return 0
2 changes: 1 addition & 1 deletion examples/aoc2023/day03/part1.jou
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,5 @@ def main() -> int:
start = end # skip rest of number

free(input)
printf("%d\n", sum)
printf("%d\n", sum) # Output: 556057
return 0
3 changes: 1 addition & 2 deletions examples/aoc2023/day03/part2.jou
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,10 @@ def main() -> int:
continue

adjacent = find_adjacent_numbers(input, p)
printf("adjacent = [%d,%d,%d,%d,...]\n", adjacent[0], adjacent[1], adjacent[2], adjacent[3])
if adjacent[0] != -1 and adjacent[1] != -1 and adjacent[2] == -1:
# it is a gear
sum += adjacent[0] * adjacent[1]

free(input)
printf("%d\n", sum)
printf("%d\n", sum) # Output: 82824352
return 0
30 changes: 23 additions & 7 deletions runtests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ set -e -o pipefail

function usage() {
echo "Usage: $0 [--valgrind] [--verbose] [--dont-run-make] [TEMPLATE]" >&2
echo "TEMPLATE can be e.g. './jou %s', where %s will be replaced by a jou file." >&2
echo "TEMPLATE can be e.g. 'jou %s', where %s will be replaced by a jou file." >&2
echo "When the command runs, 'jou' points at the executable in repository root."
exit 2
}

Expand All @@ -33,9 +34,9 @@ done
if [ $# == 0 ]; then
# No arguments --> run tests in the basic/simple way
if [[ "$OS" =~ Windows ]]; then
command_template='./jou.exe %s'
command_template='jou.exe %s'
else
command_template='./jou %s'
command_template='jou %s'
fi
elif [ $# == 1 ]; then
command_template="$1"
Expand Down Expand Up @@ -139,11 +140,21 @@ function run_test()
local correct_exit_code="$2"
local counter="$3"

local dir=.
if [[ "$joufile" =~ ^examples/aoc ]]; then
dir=$(dirname $joufile)
joufile=$(basename $joufile)
fi

local command diffpath
command="$(printf "$command_template" $joufile)"
diffpath=tmp/tests/diff$(printf "%04d" $counter).txt # consistent alphabetical order

printf "\n\n\x1b[33m*** Command: %s ***\x1b[0m\n\n" "$command" > $diffpath
local command_msg="Command: $command"
if [ $dir != . ]; then
command_msg="$command_msg [in $dir]"
fi
printf "\n\n\x1b[33m*** %s ***\x1b[0m\n\n" "$command_msg" > $diffpath

# Skip tests when:
# * the test is supposed to crash, but optimizations are enabled (unpredictable by design)
Expand All @@ -160,8 +171,13 @@ function run_test()

show_run $joufile
if diff --text -u --color=always \
<(generate_expected_output $joufile $correct_exit_code | tr -d '\r') \
<(ulimit -v 500000 2>/dev/null; bash -c "$command; echo Exit code: \$?" 2>&1 | post_process_output $joufile | tr -d '\r') \
<(cd $dir; generate_expected_output $joufile $correct_exit_code | tr -d '\r') \
<(
export PATH="$PWD:$PATH"
cd $dir
ulimit -v 500000 2>/dev/null
bash -c "$command; echo Exit code: \$?" 2>&1 | post_process_output $joufile | tr -d '\r'
) \
&>> $diffpath
then
show_ok $joufile
Expand All @@ -173,7 +189,7 @@ function run_test()
}

counter=0
for joufile in examples/*.jou tests/*/*.jou; do
for joufile in examples/*.jou examples/aoc2023/day*/*.jou tests/*/*.jou; do
case $joufile in
examples/* | tests/should_succeed/*) correct_exit_code=0; ;;
*) correct_exit_code=1; ;; # compiler or runtime error
Expand Down

0 comments on commit e563148

Please sign in to comment.