Unverified Commit 871cda0b authored by Connor Baker's avatar Connor Baker Committed by GitHub
Browse files

testers.shellcheck: refactor, update docs, and simplify tests (#385940)

parents dd5a41a9 cd7df192
Loading
Loading
Loading
Loading
+10 −5
Original line number Diff line number Diff line
@@ -118,7 +118,7 @@ It has two modes:

## `shellcheck` {#tester-shellcheck}

Runs files through `shellcheck`, a static analysis tool for shell scripts.
Run files through `shellcheck`, a static analysis tool for shell scripts, failing if there are any issues.

:::{.example #ex-shellcheck}
# Run `testers.shellcheck`
@@ -127,7 +127,7 @@ A single script

```nix
testers.shellcheck {
  name = "shellcheck";
  name = "script";
  src = ./script.sh;
}
```
@@ -139,7 +139,7 @@ let
  inherit (lib) fileset;
in
testers.shellcheck {
  name = "shellcheck";
  name = "nixbsd-activate";
  src = fileset.toSource {
    root = ./.;
    fileset = fileset.unions [
@@ -154,15 +154,20 @@ testers.shellcheck {

### Inputs {#tester-shellcheck-inputs}

[`src` (path or string)]{#tester-shellcheck-param-src}
`name` (string, optional)
: The name of the test.
  `name` will be required at a future point because it massively improves traceability of test failures, but is kept optional for now to avoid breaking existing usages.
  Defaults to `run-shellcheck`.
  The name of the derivation produced by the tester is `shellcheck-${name}` when `name` is supplied.

`src` (path-like)
: The path to the shell script(s) to check.
  This can be a single file or a directory containing shell files.
  All files in `src` will be checked, so you may want to provide `fileset`-based source instead of a whole directory.

### Return value {#tester-shellcheck-return}

A derivation that runs `shellcheck` on the given script(s).
A derivation that runs `shellcheck` on the given script(s), producing an empty output if no issues are found.
The build will fail if `shellcheck` finds any issues.

## `shfmt` {#tester-shfmt}
+0 −3
Original line number Diff line number Diff line
@@ -1557,9 +1557,6 @@
  "tester-shellcheck-inputs": [
    "index.html#tester-shellcheck-inputs"
  ],
  "tester-shellcheck-param-src": [
    "index.html#tester-shellcheck-param-src"
  ],
  "tester-shellcheck-return": [
    "index.html#tester-shellcheck-return"
  ],
+3 −0
Original line number Diff line number Diff line
@@ -18,6 +18,9 @@
- The hand written `perlPackages.SearchXapian` bindings have been dropped in favor of the (mostly compatible)
  `perlPackages.Xapian`.

- [testers.shellcheck](https://nixos.org/manual/nixpkgs/unstable/#tester-shellcheck) now warns when `name` is not provided.
  The `name` argument will become mandatory in a future release.

- The `nixLog*` family of functions made available through the standard environment have been rewritten to prefix messages with both the debug level and the function name of the caller.
  The `nixLog` function, which logs unconditionally, was also re-introduced and modified to prefix messages with the function name of the caller.
  For more information, [see this PR](https://github.com/NixOS/nixpkgs/pull/370742).
+1 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ let
  inherit (lib) fileset;

  runShellcheck = testers.shellcheck {
    name = "activation-check";
    src = fileset.toSource {
      root = ./.;
      fileset = fileset.unions [
+1 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ let
  };

  runShellcheck = testers.shellcheck {
    name = "activation-lib";
    src = runTests.src;
  };

Loading