#!/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]}" =~ "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]}" =~ "Unknown subcommand: bad-subcommand." ]] [[ "${lines[1]}" = "Usage:" ]] } @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." ]] [[ "${lines[1]}" = "Usage:" ]] run ./website slides [[ "$status" -eq 2 ]] [[ "${lines[0]}" =~ "Missing required --name argument." ]] [[ "${lines[1]}" = "Usage:" ]] } @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" ]] [[ "${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:" ]] }