diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 76ddc851..c0377b68 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -184,6 +184,7 @@ of the wrapper (if any) and ensure that the tests are only run on the required p let inherit (tlib) fileContains + fileNotContains isDirectory isFile notIsFile @@ -202,7 +203,7 @@ test { wrapper = "direnv"; } { # <-- Specify the name of the wrapper here (*) in [ "[[ -d ${wrapper} ]]" # <-- a simple condition to be asserted - { + { cond = "[[ -d ${wrapper} ]]"; msg = "No directory found for wrapper."; # <-- you can also specify a custom error message } @@ -214,7 +215,7 @@ test { wrapper = "direnv"; } { # <-- Specify the name of the wrapper here (*) wrapper = self.wrappers.direnv.wrap { inherit pkgs; }; - in + in '' # <-- no need to provide a list if there is only one assertion "${wrapper}/bin/direnv" --version | grep -q "${wrapper.version}" @@ -253,6 +254,7 @@ except you don't provide a wrapper but a name: let inherit (tlib) fileContains + fileNotContains isDirectory isFile notIsFile diff --git a/ci/test-lib.nix b/ci/test-lib.nix index 92731b17..277d051f 100644 --- a/ci/test-lib.nix +++ b/ci/test-lib.nix @@ -319,6 +319,28 @@ in msg = "Pattern '${pattern}' not found in ${file}"; }; + /** + Returns an `Assertion` that checks whether `file` does not contain a line matching `pattern`. + + The check is performed with `! grep -Eq`, so `pattern` is treated as an extended regular expression. + + # Type + ``` + fileNotContains :: String -> String -> Assertion + ``` + + # Arguments + file + : Path to the file to search. + + pattern + : Extended regular expression to search for. + */ + fileNotContains = file: pattern: { + cond = ''! grep -Eq -- '${pattern}' "${file}"''; + msg = "Pattern '${pattern}' found in ${file}"; + }; + /** Returns an `Assertion` that checks whether `expected` and `actual` are equal.