Skip to content

Commit 9a6eb2e

Browse files
committed
Smoke-test what _helpless receives for a long failed command
Nothing exercised _help50 itself: the head/tail cap and the new command-line argument were only checked by hand under a pty. Drive _help50 directly in the image instead, with a fabricated typescript and a fake _helpless, and assert that a command printing 3000 lines then an error yields the command line as the second argument and, as the first, output that starts at the program's first line, carries the omission marker, drops the middle, and ends with the error. Also check that a failed command with no output yields an empty first argument, which is what the codespace's empty-output check depends on. The check fails against the previous help50.sh.
1 parent b19958b commit 9a6eb2e

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

‎tests/smoke.sh‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,27 @@ run "$IMAGE" bash --login -c 'valgrind python x.py < /dev/null; test $? -eq 1' 2
2525
echo "- _fold wraps without a terminal"
2626
run "$IMAGE" bash --login -c '. /opt/cs50/lib/cli; TERM= _fold "$(printf "a %.0s" {1..100})"' | head -n 1 | grep -qE '^.{1,80}$'
2727

28+
echo "- _helpless gets the end of a failed command's long output, plus its command line"
29+
run "$IMAGE" bash --login -c '
30+
export HELP50=$(mktemp)
31+
_helpless() { printf "%s" "$1" > /tmp/output; printf "%s" "$2" > /tmp/cmd; }
32+
. /etc/profile.d/help50.sh
33+
34+
# A command that prints 3000 lines and then fails, as script(1) records it
35+
{ printf "$ ./slow\r\n"; seq 3000 | sed "s/$/\r/"; printf "Error: boom\r\n"; } > "$HELP50"
36+
set -o history; history -s ./slow; set +o history
37+
false; _help50
38+
test "$(cat /tmp/cmd)" = ./slow &&
39+
test "$(head -n 1 /tmp/output)" = 1 &&
40+
grep -qx "\[... 1914 lines omitted ...\]" /tmp/output &&
41+
! grep -qx 1000 /tmp/output &&
42+
test "$(tail -n 1 /tmp/output)" = "Error: boom" || exit 1
43+
44+
# A command that fails without output
45+
: > "$HELP50"
46+
set -o history; history -s ./slow; set +o history
47+
false; _help50
48+
test "$(cat /tmp/cmd)" = ./slow && test ! -s /tmp/output || exit 1
49+
'
50+
2851
echo "OK"

0 commit comments

Comments
 (0)