From e6cf841ef23a80048c702362329b3428129520cf Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Sat, 5 Jan 2019 09:05:36 -0200 Subject: 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. --- t/website.bats | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100755 t/website.bats (limited to 't/website.bats') 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" ]] +} -- cgit v1.2.3