Skip to content

Instantly share code, notes, and snippets.

@xpmatteo
Created October 16, 2020 08:22
Show Gist options
  • Save xpmatteo/2363b0c2dbb3aaf488e0e16fcf782d91 to your computer and use it in GitHub Desktop.
Save xpmatteo/2363b0c2dbb3aaf488e0e16fcf782d91 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
fail() {
echo "$0: $*"
exit 1
}
captured_output=/tmp/captured_output
temp_dir=/tmp/test-script-folder
rm -rf $temp_dir
mkdir -p $temp_dir
printf "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n" > $temp_dir/ten_lines
printf "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n0\n" > $temp_dir/eleven_lines
rm_long_files() {
ls $1
}
rm_long_files $temp_dir > $captured_output || fail "command returned error"
expected="rm $temp_dir/eleven_lines
"
actual=$(cat $captured_output)
[ "$expected" == "$actual" ] || fail "
Expected:
--
$expected
--
Actual:
--
$actual
--
"
echo OK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment