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 | |
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 '')
-rw-r--r-- | TODOs.org | 1 | ||||
-rw-r--r-- | default.nix | 4 | ||||
-rwxr-xr-x | pastebin/website-pastebin | 3 | ||||
-rwxr-xr-x | slides/website-slides | 3 | ||||
-rwxr-xr-x | t/website.bats | 60 | ||||
-rwxr-xr-x | website | 5 | ||||
-rwxr-xr-x | website.bats | 11 |
7 files changed, 68 insertions, 19 deletions
@@ -8,6 +8,7 @@ https://jaspervdj.be/hakyll/tutorials/using-teasers-in-hakyll.html * CLI ** Add completion ** Add =help= subcommand +Nested help ** DONE Print usage when no subcommand is provided CLOSED: [2019-01-01 Tue 19:35] * CI diff --git a/default.nix b/default.nix index 6c8a56c..14398f9 100644 --- a/default.nix +++ b/default.nix @@ -41,10 +41,12 @@ in with pkgs; with pkgs.stdenv; rec { name = "website-test"; src = ./.; phases = "unpackPhase buildPhase"; - buildInputs = [perl]; + buildInputs = [perl bats]; buildPhase = '' mkdir txt podchecker website pastebin/website-pastebin slides/website-slides 2>&1 | tee txt/podchecker.txt + patchShebangs . + ./t/website.bats mv txt/ $out/ ''; }; diff --git a/pastebin/website-pastebin b/pastebin/website-pastebin index 185672d..b9f7841 100755 --- a/pastebin/website-pastebin +++ b/pastebin/website-pastebin @@ -1,5 +1,4 @@ -#!/usr/bin/env nix-shell -#!nix-shell -i perl -p less moreutils nvi perl --pure -I nixpkgs=https://github.com/NixOS/nixpkgs-channels/archive/nixos-18.09.tar.gz +#!/usr/bin/env perl =head1 NAME diff --git a/slides/website-slides b/slides/website-slides index e1ae31b..cf795c4 100755 --- a/slides/website-slides +++ b/slides/website-slides @@ -1,5 +1,4 @@ -#!/usr/bin/env nix-shell -#!nix-shell -i perl -p less git perl --pure -I nixpkgs=https://github.com/NixOS/nixpkgs-channels/archive/nixos-18.09.tar.gz +#!/usr/bin/env perl =head1 NAME 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" ]] +} @@ -1,5 +1,4 @@ -#!/usr/bin/env nix-shell -#!nix-shell -i perl -p perl less nix --pure -I nixpkgs=https://github.com/NixOS/nixpkgs-channels/archive/nixos-18.09.tar.gz +#!/usr/bin/env perl =head1 NAME @@ -69,7 +68,7 @@ sub dispatch { -exitval => 0 ); } elsif (!defined $action) { - print "Missing subcomand.\n"; + print "Missing subcommand.\n"; pod2usage( -verbose => 1, -exitval => 2 diff --git a/website.bats b/website.bats deleted file mode 100755 index c9319ed..0000000 --- a/website.bats +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bats - -# @test "Help: show short usage when no subcommand is given." { -# run ./cli.pl -# [[ "$status" -eq 1 ]] -# } - -# print short usage -# show manpage -# create pastebin -# create a slide |