diff options
author | EuAndreh <eu@euandre.org> | 2019-01-05 09:05:36 -0200 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2019-01-05 09:05:36 -0200 |
commit | e6cf841ef23a80048c702362329b3428129520cf (patch) | |
tree | 0968d205fa703b3681f1b783286710528b6c5a30 /t/website.bats | |
parent | TODOs.org. (diff) | |
download | euandre.org-e6cf841ef23a80048c702362329b3428129520cf.tar.gz euandre.org-e6cf841ef23a80048c702362329b3428129520cf.tar.xz |
Add BATS tests to CLI usage and basic interactions.
Also, remove custom =nix-shell= shebang from Perl files. Instead, we should
inherit Perl from the =shell= derivation in default.nix.
Diffstat (limited to '')
-rwxr-xr-x | t/website.bats | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/t/website.bats b/t/website.bats new file mode 100755 index 0000000..d10b39d --- /dev/null +++ b/t/website.bats @@ -0,0 +1,60 @@ +#!/usr/bin/env bats + +# Go to the directory where ./website is. +cd "$BATS_TEST_DIRNAME/../" + +# exit code 1: error running command +# exit code 2: couldn't parse the command line argument + +@test "Help: show short usage when no subcommand is given, exit code is 2" { + run ./website + [[ "$status" -eq 2 ]] + [[ "${lines[0]}" = "Usage:" ]] + [[ "${lines[-1]}" = "Missing subcommand." ]] +} + +@test "Help: show short usage for unknown subcommand, exit code is 2" { + run ./website bad-subcommand + [[ "$status" -eq 2 ]] + [[ "${lines[0]}" = "Usage:" ]] + [[ "${lines[-1]}" = "Unknown subcommand: bad-subcommand." ]] +} + +@test "Help: show full toplevel help" { + run ./website --help + [[ "$status" -eq 0 ]] + [[ "${lines[0]}" = "NAME" ]] + run ./website -h + [[ "$status" -eq 0 ]] + [[ "${lines[0]}" = "NAME" ]] +} + +@test "Help: show short subcommand usage when subcommand isn't invoked properly, exit code is 2" { + run ./website pastebin + [[ "$status" -eq 2 ]] + [[ "${lines[0]}" = "Missing required --title argument." ]] + run ./website slides + [[ "$status" -eq 2 ]] + [[ "${lines[0]}" = "Missing required --name argument." ]] +} + +@test "Help: show subcommand manpage" { + run ./website pastebin -h + [[ "$status" -eq 0 ]] + [[ "${lines[0]}" = "NAME" ]] + run ./website pastebin --help + [[ "$status" -eq 0 ]] + [[ "${lines[0]}" = "NAME" ]] + run ./website slides -h + [[ "$status" -eq 0 ]] + [[ "${lines[0]}" = "NAME" ]] + run ./website slides --help + [[ "$status" -eq 0 ]] + [[ "${lines[0]}" = "NAME" ]] +} + +@test "Pastebin: required input for --title" { + run ./website pastebin --title + [[ "$status" = 2 ]] + [[ "${lines[0]}" = "Option title requires an argument" ]] +} |