#!/usr/bin/env bats load test_helper setup() { common_setup make_working_copy stub make # Fails on any file that contains BAD, as if it had a warning stub shellcheck 'for f in "$@"; do [ -f "$f" ] && grep -q BAD "$f" && exit 1; done; exit 0' stub bats 'echo 7' } @test "check runs make lint and make test, and shellcheck on untracked scripts" { printf '%s\n' '#!/bin/bash' 'echo fine' > "$WC/new-script" printf '%s\n' 'echo fine' > "$WC/new-hook.sh" echo "not a script" > "$WC/notes.txt" run cdd check [ "$status" -eq 0 ] called make --no-print-directory lint called make --no-print-directory test grep -q "^shellcheck --severity=warning .*new-script" "$STUB_LOG" grep -q "^shellcheck --severity=warning .*new-hook.sh" "$STUB_LOG" [[ "$output" == *"shellcheck: ok ("*" files, 2 untracked) bats: ok (7 tests)"* ]] run grep -q "^shellcheck .*notes.txt" "$STUB_LOG" [ "$status" -eq 1 ] } @test "check fails on a warning in an untracked script" { printf '%s\n' '#!/bin/bash' 'BAD' > "$WC/new-script" run cdd check [ "$status" -eq 1 ] [[ "$output" == *"shellcheck: FAILED"* ]] } @test "check skips ignored files" { echo "ignored-script" > "$WC/.gitignore" printf '%s\n' '#!/bin/bash' 'BAD' > "$WC/ignored-script" run cdd check [ "$status" -eq 0 ] } @test "check --fast runs only the shellcheck steps" { run cdd check --fast [ "$status" -eq 0 ] called make --no-print-directory lint uncalled make --no-print-directory test [[ "$output" == *"bats: skipped (--fast)"* ]] } @test "check fails when make test fails" { stub make '[ "$2" != test ]' run cdd check [ "$status" -eq 1 ] [[ "$output" == *"bats: FAILED"* ]] }