diff options
| author | Silvan Mosberger <silvan.mosberger@tweag.io> | 2024-12-10 20:26:33 +0100 |
|---|---|---|
| committer | Silvan Mosberger <silvan.mosberger@tweag.io> | 2024-12-10 20:26:33 +0100 |
| commit | 4f0dadbf38ee4cf4cc38cbc232b7708fddf965bc (patch) | |
| tree | 1ff84f90d76da8505f195a3e063ae9afd94e270b /lib/path/tests | |
| parent | vimPlugins.avante-nvim: move out to separate directory (#364001) (diff) | |
| download | nixpkgs-4f0dadbf38ee4cf4cc38cbc232b7708fddf965bc.tar.gz | |
treewide: format all inactive Nix files
After final improvements to the official formatter implementation,
this commit now performs the first treewide reformat of Nix files using it.
This is part of the implementation of RFC 166.
Only "inactive" files are reformatted, meaning only files that
aren't being touched by any PR with activity in the past 2 months.
This is to avoid conflicts for PRs that might soon be merged.
Later we can do a full treewide reformat to get the rest,
which should not cause as many conflicts.
A CI check has already been running for some time to ensure that new and
already-formatted files are formatted, so the files being reformatted here
should also stay formatted.
This commit was automatically created and can be verified using
nix-build https://github.com/infinisil/treewide-nixpkgs-reformat-script/archive/a08b3a4d199c6124ac5b36a889d9099b4383463f.tar.gz \
--argstr baseRev b32a0943687d2a5094a6d92f25a4b6e16a76b5b7
result/bin/apply-formatting $NIXPKGS_PATH
Diffstat (limited to 'lib/path/tests')
| -rw-r--r-- | lib/path/tests/default.nix | 62 | ||||
| -rw-r--r-- | lib/path/tests/prop.nix | 50 | ||||
| -rw-r--r-- | lib/path/tests/unit.nix | 51 |
3 files changed, 99 insertions, 64 deletions
diff --git a/lib/path/tests/default.nix b/lib/path/tests/default.nix index 93aea798acca..2ea43e04c3b7 100644 --- a/lib/path/tests/default.nix +++ b/lib/path/tests/default.nix @@ -2,8 +2,8 @@ nixpkgs ? ../../.., system ? builtins.currentSystem, pkgs ? import nixpkgs { - config = {}; - overlays = []; + config = { }; + overlays = [ ]; inherit system; }, nixVersions ? import ../../tests/nix-for-tests.nix { inherit pkgs; }, @@ -12,34 +12,38 @@ seed ? null, }: -pkgs.runCommand "lib-path-tests" { - nativeBuildInputs = [ - nixVersions.stable - ] ++ (with pkgs; [ - jq - bc - ]); -} '' - # Needed to make Nix evaluation work - export TEST_ROOT=$(pwd)/test-tmp - export NIX_BUILD_HOOK= - export NIX_CONF_DIR=$TEST_ROOT/etc - export NIX_LOCALSTATE_DIR=$TEST_ROOT/var - export NIX_LOG_DIR=$TEST_ROOT/var/log/nix - export NIX_STATE_DIR=$TEST_ROOT/var/nix - export NIX_STORE_DIR=$TEST_ROOT/store - export PAGER=cat +pkgs.runCommand "lib-path-tests" + { + nativeBuildInputs = + [ + nixVersions.stable + ] + ++ (with pkgs; [ + jq + bc + ]); + } + '' + # Needed to make Nix evaluation work + export TEST_ROOT=$(pwd)/test-tmp + export NIX_BUILD_HOOK= + export NIX_CONF_DIR=$TEST_ROOT/etc + export NIX_LOCALSTATE_DIR=$TEST_ROOT/var + export NIX_LOG_DIR=$TEST_ROOT/var/log/nix + export NIX_STATE_DIR=$TEST_ROOT/var/nix + export NIX_STORE_DIR=$TEST_ROOT/store + export PAGER=cat - cp -r ${libpath} lib - export TEST_LIB=$PWD/lib + cp -r ${libpath} lib + export TEST_LIB=$PWD/lib - echo "Running unit tests lib/path/tests/unit.nix" - nix-instantiate --eval --show-trace \ - --argstr libpath "$TEST_LIB" \ - lib/path/tests/unit.nix + echo "Running unit tests lib/path/tests/unit.nix" + nix-instantiate --eval --show-trace \ + --argstr libpath "$TEST_LIB" \ + lib/path/tests/unit.nix - echo "Running property tests lib/path/tests/prop.sh" - bash lib/path/tests/prop.sh ${toString seed} + echo "Running property tests lib/path/tests/prop.sh" + bash lib/path/tests/prop.sh ${toString seed} - touch $out -'' + touch $out + '' diff --git a/lib/path/tests/prop.nix b/lib/path/tests/prop.nix index 67e5c1e9d61c..b4fa355e9525 100644 --- a/lib/path/tests/prop.nix +++ b/lib/path/tests/prop.nix @@ -16,14 +16,15 @@ let lib = import libpath; # read each file into a string - strings = map (name: - builtins.readFile (dir + "/${name}") - ) (builtins.attrNames (builtins.readDir dir)); + strings = map (name: builtins.readFile (dir + "/${name}")) ( + builtins.attrNames (builtins.readDir dir) + ); inherit (lib.path.subpath) normalise isValid; inherit (lib.asserts) assertMsg; - normaliseAndCheck = str: + normaliseAndCheck = + str: let originalValid = isValid str; @@ -33,28 +34,27 @@ let absConcatOrig = /. + ("/" + str); absConcatNormalised = /. + ("/" + tryOnce.value); in - # Check the lib.path.subpath.normalise property to only error on invalid subpaths - assert assertMsg - (originalValid -> tryOnce.success) - "Even though string \"${str}\" is valid as a subpath, the normalisation for it failed"; - assert assertMsg - (! originalValid -> ! tryOnce.success) - "Even though string \"${str}\" is invalid as a subpath, the normalisation for it succeeded"; + # Check the lib.path.subpath.normalise property to only error on invalid subpaths + assert assertMsg ( + originalValid -> tryOnce.success + ) "Even though string \"${str}\" is valid as a subpath, the normalisation for it failed"; + assert assertMsg ( + !originalValid -> !tryOnce.success + ) "Even though string \"${str}\" is invalid as a subpath, the normalisation for it succeeded"; - # Check normalisation idempotency - assert assertMsg - (originalValid -> tryTwice.success) - "For valid subpath \"${str}\", the normalisation \"${tryOnce.value}\" was not a valid subpath"; - assert assertMsg - (originalValid -> tryOnce.value == tryTwice.value) - "For valid subpath \"${str}\", normalising it once gives \"${tryOnce.value}\" but normalising it twice gives a different result: \"${tryTwice.value}\""; + # Check normalisation idempotency + assert assertMsg ( + originalValid -> tryTwice.success + ) "For valid subpath \"${str}\", the normalisation \"${tryOnce.value}\" was not a valid subpath"; + assert assertMsg (originalValid -> tryOnce.value == tryTwice.value) + "For valid subpath \"${str}\", normalising it once gives \"${tryOnce.value}\" but normalising it twice gives a different result: \"${tryTwice.value}\""; - # Check that normalisation doesn't change a string when appended to an absolute Nix path value - assert assertMsg - (originalValid -> absConcatOrig == absConcatNormalised) - "For valid subpath \"${str}\", appending to an absolute Nix path value gives \"${absConcatOrig}\", but appending the normalised result \"${tryOnce.value}\" gives a different value \"${absConcatNormalised}\""; + # Check that normalisation doesn't change a string when appended to an absolute Nix path value + assert assertMsg (originalValid -> absConcatOrig == absConcatNormalised) + "For valid subpath \"${str}\", appending to an absolute Nix path value gives \"${absConcatOrig}\", but appending the normalised result \"${tryOnce.value}\" gives a different value \"${absConcatNormalised}\""; - # Return an empty string when failed - if tryOnce.success then tryOnce.value else ""; + # Return an empty string when failed + if tryOnce.success then tryOnce.value else ""; -in lib.genAttrs strings normaliseAndCheck +in +lib.genAttrs strings normaliseAndCheck diff --git a/lib/path/tests/unit.nix b/lib/path/tests/unit.nix index 9b0a0b2714aa..903e8ff0acff 100644 --- a/lib/path/tests/unit.nix +++ b/lib/path/tests/unit.nix @@ -3,7 +3,14 @@ { libpath }: let lib = import libpath; - inherit (lib.path) hasPrefix removePrefix append splitRoot hasStorePathPrefix subpath; + inherit (lib.path) + hasPrefix + removePrefix + append + splitRoot + hasStorePathPrefix + subpath + ; # This is not allowed generally, but we're in the tests here, so we'll allow ourselves. storeDirPath = /. + builtins.storeDir; @@ -79,15 +86,24 @@ let testSplitRootExample1 = { expr = splitRoot /foo/bar; - expected = { root = /.; subpath = "./foo/bar"; }; + expected = { + root = /.; + subpath = "./foo/bar"; + }; }; testSplitRootExample2 = { expr = splitRoot /.; - expected = { root = /.; subpath = "./."; }; + expected = { + root = /.; + subpath = "./."; + }; }; testSplitRootExample3 = { expr = splitRoot /foo/../bar; - expected = { root = /.; subpath = "./bar"; }; + expected = { + root = /.; + subpath = "./bar"; + }; }; testSplitRootExample4 = { expr = (builtins.tryEval (splitRoot "/foo/bar")).success; @@ -111,7 +127,9 @@ let expected = false; }; testHasStorePathPrefixExample5 = { - expr = hasStorePathPrefix (storeDirPath + "/.links/10gg8k3rmbw8p7gszarbk7qyd9jwxhcfq9i6s5i0qikx8alkk4hq"); + expr = hasStorePathPrefix ( + storeDirPath + "/.links/10gg8k3rmbw8p7gszarbk7qyd9jwxhcfq9i6s5i0qikx8alkk4hq" + ); expected = false; }; testHasStorePathPrefixExample6 = { @@ -188,11 +206,18 @@ let # Test examples from the lib.path.subpath.join documentation testSubpathJoinExample1 = { - expr = subpath.join [ "foo" "bar/baz" ]; + expr = subpath.join [ + "foo" + "bar/baz" + ]; expected = "./foo/bar/baz"; }; testSubpathJoinExample2 = { - expr = subpath.join [ "./foo" "." "bar//./baz/" ]; + expr = subpath.join [ + "./foo" + "." + "bar//./baz/" + ]; expected = "./foo/bar/baz"; }; testSubpathJoinExample3 = { @@ -273,7 +298,11 @@ let }; testSubpathComponentsExample2 = { expr = subpath.components "./foo//bar/./baz/"; - expected = [ "foo" "bar" "baz" ]; + expected = [ + "foo" + "bar" + "baz" + ]; }; testSubpathComponentsExample3 = { expr = (builtins.tryEval (subpath.components "/foo")).success; @@ -281,5 +310,7 @@ let }; }; in - if cases == [] then "Unit tests successful" - else throw "Path unit tests failed: ${lib.generators.toPretty {} cases}" +if cases == [ ] then + "Unit tests successful" +else + throw "Path unit tests failed: ${lib.generators.toPretty { } cases}" |
