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

Add negative-zero.c test to document ksh bug #73

Merged
merged 1 commit into from
Aug 31, 2024
Merged
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
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
Loading