diff options
author | EuAndreh <eu@euandre.org> | 2019-01-05 10:38:38 -0200 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2019-01-05 10:39:06 -0200 |
commit | 55e947d7901c17dbb1365a5cfb9f40acd50e903b (patch) | |
tree | 4e2a7db1001ccf64073824d907afaabf2e69ae91 | |
parent | Add BATS tests to CLI usage and basic interactions. (diff) | |
download | euandre.org-55e947d7901c17dbb1365a5cfb9f40acd50e903b.tar.gz euandre.org-55e947d7901c17dbb1365a5cfb9f40acd50e903b.tar.xz |
Print CLI errors using Term::ANSIColor.
Diffstat (limited to '')
-rw-r--r-- | TODOs.org | 1 | ||||
-rw-r--r-- | default.nix | 1 | ||||
-rwxr-xr-x | pastebin/website-pastebin | 3 | ||||
-rwxr-xr-x | slides/website-slides | 3 | ||||
-rwxr-xr-x | t/website.bats | 22 | ||||
-rwxr-xr-x | website | 11 |
6 files changed, 28 insertions, 13 deletions
@@ -11,6 +11,7 @@ https://jaspervdj.be/hakyll/tutorials/using-teasers-in-hakyll.html Nested help ** DONE Print usage when no subcommand is provided CLOSED: [2019-01-01 Tue 19:35] +** Add tests when actually running subcommands * CI ** Improvements *** Use NixOS instead of Debian? diff --git a/default.nix b/default.nix index 14398f9..00572eb 100644 --- a/default.nix +++ b/default.nix @@ -47,6 +47,7 @@ in with pkgs; with pkgs.stdenv; rec { podchecker website pastebin/website-pastebin slides/website-slides 2>&1 | tee txt/podchecker.txt patchShebangs . ./t/website.bats + ./website test mv txt/ $out/ ''; }; diff --git a/pastebin/website-pastebin b/pastebin/website-pastebin index b9f7841..6061c74 100755 --- a/pastebin/website-pastebin +++ b/pastebin/website-pastebin @@ -38,6 +38,7 @@ use Getopt::Long qw(:config no_ignore_case bundling); use Pod::Usage qw(pod2usage); use Unicode::Normalize qw(NFKD); use File::Basename qw(dirname); +use Term::ANSIColor; my $help = 0; my $title = ''; @@ -52,7 +53,7 @@ pod2usage( pod2usage( -verbose => 1, -exitval => 2, - -message => "Missing required --title argument." + -message => colored("Missing required --title argument.", "red") ) if !$title; # Taken from: diff --git a/slides/website-slides b/slides/website-slides index cf795c4..a1f1466 100755 --- a/slides/website-slides +++ b/slides/website-slides @@ -39,6 +39,7 @@ use Pod::Usage qw(pod2usage); use File::Basename qw(dirname); use File::Path qw(make_path); use File::Copy qw(copy); +use Term::ANSIColor; my $help = 0; my $name = ''; @@ -50,7 +51,7 @@ pod2usage(-verbose => 2, -exitval => 0) if $help; pod2usage( -verbose => 1, -exitval => 2, - -message => "Missing required --name argument." + -message => colored("Missing required --name argument.", "red") ) if !$name; my $dirname = dirname(__FILE__); diff --git a/t/website.bats b/t/website.bats index d10b39d..5bbfb59 100755 --- a/t/website.bats +++ b/t/website.bats @@ -9,15 +9,15 @@ cd "$BATS_TEST_DIRNAME/../" @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." ]] + [[ "${lines[0]}" =~ "Missing subcommand." ]] + [[ "${lines[1]}" = "Usage:" ]] } @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." ]] + [[ "${lines[0]}" =~ "Unknown subcommand: bad-subcommand." ]] + [[ "${lines[1]}" = "Usage:" ]] } @test "Help: show full toplevel help" { @@ -32,10 +32,12 @@ cd "$BATS_TEST_DIRNAME/../" @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." ]] + [[ "${lines[0]}" =~ "Missing required --title argument." ]] + [[ "${lines[1]}" = "Usage:" ]] run ./website slides [[ "$status" -eq 2 ]] - [[ "${lines[0]}" = "Missing required --name argument." ]] + [[ "${lines[0]}" =~ "Missing required --name argument." ]] + [[ "${lines[1]}" = "Usage:" ]] } @test "Help: show subcommand manpage" { @@ -57,4 +59,12 @@ cd "$BATS_TEST_DIRNAME/../" run ./website pastebin --title [[ "$status" = 2 ]] [[ "${lines[0]}" = "Option title requires an argument" ]] + [[ "${lines[1]}" = "Usage:" ]] +} + +@test "Slides: required input for --name" { + run ./website slides --name + [[ "$status" = 2 ]] + [[ "${lines[0]}" = "Option name requires an argument" ]] + [[ "${lines[1]}" = "Usage:" ]] } @@ -37,6 +37,7 @@ use warnings; use Getopt::Long qw(:config no_ignore_case bundling pass_through); use Pod::Usage qw(pod2usage); use File::Basename qw(dirname); +use Term::ANSIColor; my $help = 0; my $title = ''; @@ -47,7 +48,7 @@ sub getopts { } sub test { - die "FIXME"; + print colored("FIXME", "red"), "\n"; } sub escaped_cmd { @@ -68,10 +69,10 @@ sub dispatch { -exitval => 0 ); } elsif (!defined $action) { - print "Missing subcommand.\n"; pod2usage( -verbose => 1, - -exitval => 2 + -exitval => 2, + -message => colored("Missing subcommand.", "red") ); } elsif ($action eq 'pastebin') { my @sub_args = grep { $_ ne $action } @args; @@ -82,10 +83,10 @@ sub dispatch { } elsif ($action eq 'test') { test(); } else { - print "Unknown subcommand: $action.\n"; pod2usage( -verbose => 1, - -exitval => 2 + -exitval => 2, + -message => colored("Unknown subcommand: $action.", "red") ); } } |