Skip to content

Commit

Permalink
Add negative-zero.c test to document bug
Browse files Browse the repository at this point in the history
  • Loading branch information
laurenthuberdeau committed Aug 31, 2024
1 parent 0348374 commit 9e51438
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ run_tests() {
else # Run all tests for other backends
run_tests_in_folder "tests/_exe"
fi
# Folder containing tests that expose bugs in pnut or shells
run_tests_in_folder "tests/_bug"

echo "Summary:"
echo "===================="
Expand Down
26 changes: 26 additions & 0 deletions tests/_bug/negative-zero.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// On ksh, when assigning the negative value of a variable containing 0 (i.e.
// -0) to a variable using arithmetic expansion, the variable is assigned the
// string `-0` instead of 0. Other shells assign 0 as expected.

// expect_failure_for: ksh
int return0() {
int a = 0;
return -a;
}

void putstring(char *s) {
while (*s) {
putchar(*s);
s = s + 1;
}
}

void main() {
// Workaround: use `return0() + 0 == 0`.
// This forces the result of return0 to be in an arithmetic expansion which removes the `-` from `-0`.
if (return0() == 0) {
putstring("zero\n");
} else {
putstring("non-zero\n");
}
}
1 change: 1 addition & 0 deletions tests/_bug/negative-zero.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
zero

0 comments on commit 9e51438

Please sign in to comment.