fix build script exiting before all tests are completed.

This commit is contained in:
koniifer 2025-02-01 00:10:51 +00:00
parent 08a912a872
commit 48b788abf7
2 changed files with 32 additions and 8 deletions

21
build
View file

@ -183,7 +183,7 @@ EOF
}
run_test() {
file=$1 name=$2 output="" rc=0
file=$1 name=$2 output="" rc=0 failed=0
parse_test "$file"
hbc "$file" $hbc_flags >"$BUILD_PATH/test/$name.o" || return 1
$linker "$BUILD_PATH/test/$name.o" -o "$BUILD_PATH/test/$name" || return 1
@ -193,7 +193,7 @@ run_test() {
rc=$?
[ $rc -eq 124 ] && {
error "timeout"
return 1
failed=1
}
else
output=$("$BUILD_PATH/test/$name" $args_input 2>&1)
@ -202,14 +202,15 @@ run_test() {
[ "$rc" != "$exit_code" ] && {
error "exit code $rc != $exit_code"
return 1
failed=1
}
[ -n "$stdout_expected" ] && [ "$output" != "$stdout_expected" ] && {
error "output mismatch
expected: $stdout_expected
got: $output"
return 1
failed=1
}
return $failed
}
# todo: this spawns every test all at once. consider limiting to $(nproc) tests at once.
@ -217,15 +218,19 @@ do_tests() {
detect_linker
mkdir -p "$BUILD_PATH/test" || die "failed to create test dir"
find "${TEST_DIR}/${test#all}" -type f | while IFS= read -r file; do
tmpfile=$(mktemp) || die "Failed to create temporary file"
find "${TEST_DIR}/${test#all}" -type f >"$tmpfile" || die "Find command failed"
while IFS= read -r file; do
[ -f "$file" ] || continue
test_name=$(basename "$file" .hb)
log "Testing $test_name"
(run_test "$file" "$test_name") &
done
wait
}
done <"$tmpfile"
wait
rm -r "$tmpfile" "$BUILD_PATH/test"
}
do_build() {
mkdir -p "$BUILD_PATH/$target" || die "failed to create $BUILD_PATH/$target"
[ -w "$BUILD_PATH/$target" ] || die "no write permission"

View file

@ -0,0 +1,19 @@
/*
* exit: 0
*/
$unix_timestamp := fn(year: uint, month: u8, day: u8, hour: u8, minute: u8, second: u8): uint {
is_leap := year % 4 == 0 & (year % 100 != 0 | year % 400 == 0)
days_since_epoch := (year - 1970) * 365 + (year - 1) / 4 - (year - 1) / 100 + (year - 1) / 400 - 477
idx := month - 1
sum_nonleap := (idx < 2) * idx * 31 + (idx >= 2) * (59 + (153 * (idx - 2) + 2) / 5)
total_days := days_since_epoch + day + sum_nonleap + is_leap * (month > 2)
return total_days * 86400 + hour * 3600 + minute * 60 + second
}
main := fn(): u8 {
r0 := unix_timestamp(2025, 1, 31, 21, 53, 26) != 1738360406
r1 := unix_timestamp(1970, 1, 1, 0, 0, 0) != 0
r2 := unix_timestamp(2038, 1, 19, 3, 14, 8) != 1 << 31
return r0 | r1 | r2
}