diff --git a/bin/pwd/pwd.c b/bin/pwd/pwd.c --- a/bin/pwd/pwd.c +++ b/bin/pwd/pwd.c @@ -112,5 +112,7 @@ printf("%s\n", pwd); else err(1, "."); + if (fflush(stdout) != 0) + err(1, "stdout"); exit(0); } diff --git a/bin/pwd/tests/pwd_test.sh b/bin/pwd/tests/pwd_test.sh --- a/bin/pwd/tests/pwd_test.sh +++ b/bin/pwd/tests/pwd_test.sh @@ -66,8 +66,29 @@ atf_check -o inline:"$root/phy/baz\n" pwd -L } +atf_test_case stdout +stdout_head() +{ + atf_set descr "error writing to stdout" +} +stdout_body() +{ + pwd=$(which pwd) + [ -f "$pwd" ] || atf_skip "unable to distinguish binary from builtin" + ( + trap "" PIPE + # Give true(1) some time to exit. + sleep 1 + $pwd 2>stderr + echo $? >result + ) | true + atf_check -o inline:"1\n" cat result + atf_check -o match:"stdout" cat stderr +} + atf_init_test_cases() { atf_add_test_case logical atf_add_test_case physical + atf_add_test_case stdout }