#!/usr/bin/env bats load test_helper # # Literal matching # # Correctness @test "refute_output() : returns 0 if does not equal \`\$output'" { run echo 'b' run refute_output 'a' assert_test_pass } @test "refute_output() : returns 1 and displays details if equals \`\$output'" { run echo 'a' run refute_output 'a' assert_test_fail <<'ERR_MSG' -- output equals, but it was expected to differ -- output : a -- ERR_MSG } @test 'refute_output(): succeeds if output is empty' { run echo '' run refute_output assert_test_pass } @test 'refute_output(): fails if output is non-empty' { run echo 'a' run refute_output assert_test_fail <<'ERR_MSG' -- output non-empty, but expected no output -- output : a -- ERR_MSG } @test 'refute_output() - : reads from STDIN' { run echo '-' run refute_output - < from STDIN' { run echo '--stdin' run refute_output --stdin <: displays details in multi-line format if necessary' { run printf 'a 0\na 1' run refute_output $'a 0\na 1' assert_test_fail <<'ERR_MSG' -- output equals, but it was expected to differ -- output (2 lines): a 0 a 1 -- ERR_MSG } # Options @test 'refute_output() : performs literal matching by default' { run echo 'a' run refute_output '*' assert_test_pass } # # Partial matching: `-p' and `--partial' # # Options @test 'refute_output() -p : enables partial matching' { run echo 'abc' run refute_output -p 'd' assert_test_pass } @test 'refute_output() --partial : enables partial matching' { run echo 'abc' run refute_output --partial 'd' assert_test_pass } # Correctness @test "refute_output() --partial : returns 0 if is not a substring in \`\$output'" { run printf 'a\nb\nc' run refute_output --partial 'd' assert_test_pass } @test "refute_output() --partial : returns 1 and displays details if is a substring in \`\$output'" { run echo 'a' run refute_output --partial 'a' assert_test_fail <<'ERR_MSG' -- output should not contain substring -- substring : a output : a -- ERR_MSG } # Output formatting @test 'refute_output() --partial : displays details in multi-line format if necessary' { run printf 'a 0\na 1' run refute_output --partial 'a' assert_test_fail <<'ERR_MSG' -- output should not contain substring -- substring (1 lines): a output (2 lines): a 0 a 1 -- ERR_MSG } # # Regular expression matching: `-e' and `--regexp' # # Options @test 'refute_output() -e : enables regular expression matching' { run echo 'abc' run refute_output -e '^d' assert_test_pass } @test 'refute_output() --regexp : enables regular expression matching' { run echo 'abc' run refute_output --regexp '^d' assert_test_pass } # Correctness @test "refute_output() --regexp : returns 0 if does not match \`\$output'" { run printf 'a\nb\nc' run refute_output --regexp '.*d.*' assert_test_pass } @test "refute_output() --regexp : returns 1 and displays details if matches \`\$output'" { run echo 'a' run refute_output --regexp '.*a.*' assert_test_fail <<'ERR_MSG' -- regular expression should not match output -- regexp : .*a.* output : a -- ERR_MSG } # Output formatting @test 'refute_output() --regexp : displays details in multi-line format if necessary' { run printf 'a 0\na 1' run refute_output --regexp '.*a.*' assert_test_fail <<'ERR_MSG' -- regular expression should not match output -- regexp (1 lines): .*a.* output (2 lines): a 0 a 1 -- ERR_MSG } # Error handling @test 'refute_output() --regexp : returns 1 and displays an error message if is not a valid extended regular expression' { run refute_output --regexp '[.*' assert_test_fail <<'ERR_MSG' -- ERROR: refute_output -- Invalid extended regular expression: `[.*' -- ERR_MSG } # # Common # @test "refute_output(): \`--partial' and \`--regexp' are mutually exclusive" { run refute_output --partial --regexp assert_test_fail <<'ERR_MSG' -- ERROR: refute_output -- `--partial' and `--regexp' are mutually exclusive -- ERR_MSG } @test "refute_output(): \`--' stops parsing options" { run echo '--' run refute_output -- '-p' assert_test_pass }