tiny-pilot / tiny-pilot/tinypilot

Use shellcheck for bats tests without workaround

Open
#1,718 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Python
Stars
3.5k
Forks
291
PR merge metrics
No merged PRs in 30d

Description

Unfortunately, the shellcheck+bats situation is a bit messy right now. Once they get things in order again, we can refactor our bats bash tests:

  • Remove the workaround for the warnings about the $output/$status/$lines variables (see below)
  • Use the @test prefix notation instead of the #@test comment notation.
    • I.e., @test test_some_command() { instead of test_some_command() { #@test

Backstory / Workaround

shellcheck has built-in support for .bats files, even if these files use the (otherwise non-standard) @test prefix. However, there was a regression in shellcheck, where shellcheck now produces false positive info statements about potential modifications of the $output/$status/$lines variables, which is confusing and annoying.

Our current workaround is to put the following block at the beginning of every .bats file:

{
  # Silence shellcheck for global bats variables.
  # https://github.com/tiny-pilot/tinypilot/issues/1718
  # shellcheck disable=SC2154
  echo "${output}" "${status}" "${lines}" >/dev/null
}

This silences the SC2154 warnings that would otherwise appear.

Note that this workaround has to be wrapped in a custom “scope” (subshell), because of the shellcheck gotcha that directives immediately after the shebang apply to the entire file. The {...} ensures that the directive only ever applies to the echo statement, regardless of what else is between it and the shebang.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Find the repository's .bats files and inspect their current shellcheck workaround and test declaration syntax. Check the linked shellcheck and Bats guidance before changing anything, since the issue depends on the shellcheck regression being resolved. Done means the workaround is removed, tests use @test notation, and shellcheck runs without the described false positives.

Written by the indexing model from the issue text.

Assessment

Tech stack
bash
Domain
testing-qa, tooling
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.