diff options
author | Alyssa Ross <hi@alyssa.is> | 2024-03-01 11:40:12 +0100 |
---|---|---|
committer | Alyssa Ross <hi@alyssa.is> | 2024-03-01 11:40:12 +0100 |
commit | bf6d657e5dbcb5e39fda280ef7e86b2a7794ca86 (patch) | |
tree | 8eb035cbab19794f6415cc460fac7226f7a58afc /nixpkgs/pkgs/test | |
parent | 66f707d69f1e423db5a35c2fe43b32781125a9af (diff) | |
parent | 09c1497ce5d4ed4a0edfdd44450d3048074cb300 (diff) | |
download | nixlib-bf6d657e5dbcb5e39fda280ef7e86b2a7794ca86.tar nixlib-bf6d657e5dbcb5e39fda280ef7e86b2a7794ca86.tar.gz nixlib-bf6d657e5dbcb5e39fda280ef7e86b2a7794ca86.tar.bz2 nixlib-bf6d657e5dbcb5e39fda280ef7e86b2a7794ca86.tar.lz nixlib-bf6d657e5dbcb5e39fda280ef7e86b2a7794ca86.tar.xz nixlib-bf6d657e5dbcb5e39fda280ef7e86b2a7794ca86.tar.zst nixlib-bf6d657e5dbcb5e39fda280ef7e86b2a7794ca86.zip |
Merge branch 'nixos-unstable-small' of https://github.com/NixOS/nixpkgs
Diffstat (limited to 'nixpkgs/pkgs/test')
-rw-r--r-- | nixpkgs/pkgs/test/default.nix | 4 | ||||
-rw-r--r-- | nixpkgs/pkgs/test/substitute/default.nix | 96 | ||||
-rw-r--r-- | nixpkgs/pkgs/test/systemd/default.nix | 5 | ||||
-rw-r--r-- | nixpkgs/pkgs/test/systemd/nixos/default.nix | 37 |
4 files changed, 142 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/test/default.nix b/nixpkgs/pkgs/test/default.nix index 5382cae6159f..9868bbc6033b 100644 --- a/nixpkgs/pkgs/test/default.nix +++ b/nixpkgs/pkgs/test/default.nix @@ -175,4 +175,8 @@ with pkgs; nixpkgs-check-by-name = callPackage ./nixpkgs-check-by-name { }; auto-patchelf-hook = callPackage ./auto-patchelf-hook { }; + + systemd = callPackage ./systemd { }; + + substitute = recurseIntoAttrs (callPackage ./substitute { }); } diff --git a/nixpkgs/pkgs/test/substitute/default.nix b/nixpkgs/pkgs/test/substitute/default.nix new file mode 100644 index 000000000000..3ff346b14658 --- /dev/null +++ b/nixpkgs/pkgs/test/substitute/default.nix @@ -0,0 +1,96 @@ +{ substitute, testers, runCommand }: +let + # Ofborg doesn't allow any traces on stderr, + # so mock `lib` to not trace warnings, + # because substitute gives a deprecation warning + substituteSilent = substitute.override (prevArgs: { + lib = prevArgs.lib.extend (finalLib: prevLib: { + trivial = prevLib.trivial // { + warn = msg: value: value; + }; + }); + }); +in { + + substitutions = testers.testEqualContents { + assertion = "substitutions-spaces"; + actual = substitute { + src = builtins.toFile "source" '' + Hello world! + ''; + substitutions = [ + "--replace-fail" + "Hello world!" + "Yo peter!" + ]; + }; + expected = builtins.toFile "expected" '' + Yo peter! + ''; + }; + + legacySingleReplace = testers.testEqualContents { + assertion = "substitute-single-replace"; + actual = substituteSilent { + src = builtins.toFile "source" '' + Hello world! + ''; + replacements = [ + "--replace-fail" "world" "paul" + ]; + }; + expected = builtins.toFile "expected" '' + Hello paul! + ''; + }; + + legacyString = testers.testEqualContents { + assertion = "substitute-string"; + actual = substituteSilent { + src = builtins.toFile "source" '' + Hello world! + ''; + # Not great that this works at all, but is supported + replacements = "--replace-fail world string"; + }; + expected = builtins.toFile "expected" '' + Hello string! + ''; + }; + + legacySingleArg = testers.testEqualContents { + assertion = "substitute-single-arg"; + actual = substituteSilent { + src = builtins.toFile "source" '' + Hello world! + ''; + # Not great that this works at all, but is supported + replacements = [ + "--replace-fail world list" + ]; + }; + expected = builtins.toFile "expected" '' + Hello list! + ''; + }; + + legacyVar = testers.testEqualContents { + assertion = "substitute-var"; + actual = substituteSilent { + src = builtins.toFile "source" '' + @greeting@ @name@! + ''; + # Not great that this works at all, but is supported + replacements = [ + "--subst-var name" + "--subst-var-by greeting Yo" + ]; + name = "peter"; + }; + expected = builtins.toFile "expected" '' + Yo peter! + ''; + }; + + +} diff --git a/nixpkgs/pkgs/test/systemd/default.nix b/nixpkgs/pkgs/test/systemd/default.nix new file mode 100644 index 000000000000..2208bf794481 --- /dev/null +++ b/nixpkgs/pkgs/test/systemd/default.nix @@ -0,0 +1,5 @@ +{ lib, callPackage }: + +lib.recurseIntoAttrs { + nixos = callPackage ./nixos { }; +} diff --git a/nixpkgs/pkgs/test/systemd/nixos/default.nix b/nixpkgs/pkgs/test/systemd/nixos/default.nix new file mode 100644 index 000000000000..e45399b63516 --- /dev/null +++ b/nixpkgs/pkgs/test/systemd/nixos/default.nix @@ -0,0 +1,37 @@ +{ pkgs, lib, stdenv, ... }: + +lib.runTests { + # Merging two non-list definitions must still result in an error + # about a conflicting definition. + test-unitOption-merging-non-lists-conflict = + let nixos = pkgs.nixos { + system.stateVersion = lib.trivial.release; + systemd.services.systemd-test-nixos = { + serviceConfig = lib.mkMerge [ + { StateDirectory = "foo"; } + { StateDirectory = "bar"; } + ]; + }; + }; + in { + expr = (builtins.tryEval (nixos.config.systemd.services.systemd-test-nixos.serviceConfig.StateDirectory)).success; + expected = false; + }; + + # Merging must lift non-list definitions to a list + # if at least one of them is a list. + test-unitOption-merging-list-non-list-append = + let nixos = pkgs.nixos { + system.stateVersion = lib.trivial.release; + systemd.services.systemd-test-nixos = { + serviceConfig = lib.mkMerge [ + { StateDirectory = "foo"; } + { StateDirectory = ["bar"]; } + ]; + }; + }; + in { + expr = nixos.config.systemd.services.systemd-test-nixos.serviceConfig.StateDirectory; + expected = [ "foo" "bar" ]; + }; +} |