aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/functional/flakes/flake-metadata.sh36
-rw-r--r--tests/functional/flakes/flake-metadata/flake.lock245
-rw-r--r--tests/functional/flakes/flake-metadata/metadata.out.expected36
-rw-r--r--tests/functional/lang/eval-okay-derivation-legacy.err.exp6
-rw-r--r--tests/functional/lang/eval-okay-derivation-legacy.exp1
-rw-r--r--tests/functional/lang/eval-okay-derivation-legacy.nix12
-rw-r--r--tests/functional/meson.build3
-rw-r--r--tests/functional/search.sh2
-rw-r--r--tests/unit/libexpr-support/tests/libexpr.hh4
-rw-r--r--tests/unit/libexpr/trivial.cc17
-rw-r--r--tests/unit/libutil-support/tests/cli-literate-parser.cc9
11 files changed, 361 insertions, 10 deletions
diff --git a/tests/functional/flakes/flake-metadata.sh b/tests/functional/flakes/flake-metadata.sh
new file mode 100644
index 000000000..ab5a69b3a
--- /dev/null
+++ b/tests/functional/flakes/flake-metadata.sh
@@ -0,0 +1,36 @@
+source ./common.sh
+
+flakeDir=$TEST_ROOT/flake
+mkdir -p "$flakeDir"
+
+cat > "$flakeDir/flake.nix" <<-'EOF'
+{
+ inputs = {
+ nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable-small";
+ flake-utils.url = "github:numtide/flake-utils";
+ flake-compat = {
+ url = "github:edolstra/flake-compat";
+ flake = false;
+ };
+ lanzaboote = {
+ url = "github:nix-community/lanzaboote";
+ inputs.nixpkgs.follows = "nixpkgs";
+ inputs.flake-utils.follows = "flake-utils";
+ inputs.flake-compat.follows = "flake-compat";
+ };
+ };
+
+ outputs = { ... }: {};
+}
+EOF
+
+cp flake-metadata/flake.lock "$flakeDir"
+touch -d @1000 "$flakeDir/flake.nix" "$flakeDir/flake.lock" "$flakeDir"
+
+# For some reason we use NIX_STORE_DIR which causes unstable paths. This is
+# goofy. We can just use --store, which sets rootDir and does not have this
+# problem.
+actualStore=$NIX_STORE_DIR
+unset NIX_STORE_DIR
+NOCOLOR=1 TZ=UTC LC_ALL=C.UTF-8 nix flake metadata --store "$actualStore" "$flakeDir" | grep -v -e 'Locked URL:' -e 'Resolved URL:' > "$TEST_ROOT/metadata.out.actual"
+diff -u flake-metadata/metadata.out.expected "$TEST_ROOT/metadata.out.actual"
diff --git a/tests/functional/flakes/flake-metadata/flake.lock b/tests/functional/flakes/flake-metadata/flake.lock
new file mode 100644
index 000000000..62b7dc3e8
--- /dev/null
+++ b/tests/functional/flakes/flake-metadata/flake.lock
@@ -0,0 +1,245 @@
+{
+ "nodes": {
+ "crane": {
+ "inputs": {
+ "nixpkgs": [
+ "lanzaboote",
+ "nixpkgs"
+ ]
+ },
+ "locked": {
+ "lastModified": 1711299236,
+ "narHash": "sha256-6/JsyozOMKN8LUGqWMopKTSiK8N79T8Q+hcxu2KkTXg=",
+ "owner": "ipetkov",
+ "repo": "crane",
+ "rev": "880573f80d09e18a11713f402b9e6172a085449f",
+ "type": "github"
+ },
+ "original": {
+ "owner": "ipetkov",
+ "repo": "crane",
+ "type": "github"
+ }
+ },
+ "flake-compat": {
+ "flake": false,
+ "locked": {
+ "lastModified": 1696426674,
+ "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=",
+ "owner": "edolstra",
+ "repo": "flake-compat",
+ "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
+ "type": "github"
+ },
+ "original": {
+ "owner": "edolstra",
+ "repo": "flake-compat",
+ "type": "github"
+ }
+ },
+ "flake-parts": {
+ "inputs": {
+ "nixpkgs-lib": [
+ "lanzaboote",
+ "nixpkgs"
+ ]
+ },
+ "locked": {
+ "lastModified": 1709336216,
+ "narHash": "sha256-Dt/wOWeW6Sqm11Yh+2+t0dfEWxoMxGBvv3JpIocFl9E=",
+ "owner": "hercules-ci",
+ "repo": "flake-parts",
+ "rev": "f7b3c975cf067e56e7cda6cb098ebe3fb4d74ca2",
+ "type": "github"
+ },
+ "original": {
+ "owner": "hercules-ci",
+ "repo": "flake-parts",
+ "type": "github"
+ }
+ },
+ "flake-utils": {
+ "inputs": {
+ "systems": "systems"
+ },
+ "locked": {
+ "lastModified": 1710146030,
+ "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
+ "owner": "numtide",
+ "repo": "flake-utils",
+ "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
+ "type": "github"
+ },
+ "original": {
+ "owner": "numtide",
+ "repo": "flake-utils",
+ "type": "github"
+ }
+ },
+ "gitignore": {
+ "inputs": {
+ "nixpkgs": [
+ "lanzaboote",
+ "pre-commit-hooks-nix",
+ "nixpkgs"
+ ]
+ },
+ "locked": {
+ "lastModified": 1709087332,
+ "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=",
+ "owner": "hercules-ci",
+ "repo": "gitignore.nix",
+ "rev": "637db329424fd7e46cf4185293b9cc8c88c95394",
+ "type": "github"
+ },
+ "original": {
+ "owner": "hercules-ci",
+ "repo": "gitignore.nix",
+ "type": "github"
+ }
+ },
+ "lanzaboote": {
+ "inputs": {
+ "crane": "crane",
+ "flake-compat": [
+ "flake-compat"
+ ],
+ "flake-parts": "flake-parts",
+ "flake-utils": [
+ "flake-utils"
+ ],
+ "nixpkgs": [
+ "nixpkgs"
+ ],
+ "pre-commit-hooks-nix": "pre-commit-hooks-nix",
+ "rust-overlay": "rust-overlay"
+ },
+ "locked": {
+ "lastModified": 1713369831,
+ "narHash": "sha256-G4OGxvlIIjphpkxcRAkf1QInYsAeqbfNh6Yl1JLy2uM=",
+ "owner": "nix-community",
+ "repo": "lanzaboote",
+ "rev": "850f27322239f8cfa56b122cc9a278ab99a49015",
+ "type": "github"
+ },
+ "original": {
+ "owner": "nix-community",
+ "repo": "lanzaboote",
+ "type": "github"
+ }
+ },
+ "nixpkgs": {
+ "locked": {
+ "lastModified": 1719824438,
+ "narHash": "sha256-pY0wosAgcr9W4vmGML0T3BVhQiGuKoozCbs2t+Je1zc=",
+ "owner": "nixos",
+ "repo": "nixpkgs",
+ "rev": "7f993cdf26ccef564eabf31fdb40d140821e12bc",
+ "type": "github"
+ },
+ "original": {
+ "owner": "nixos",
+ "ref": "nixos-unstable-small",
+ "repo": "nixpkgs",
+ "type": "github"
+ }
+ },
+ "nixpkgs-stable": {
+ "locked": {
+ "lastModified": 1710695816,
+ "narHash": "sha256-3Eh7fhEID17pv9ZxrPwCLfqXnYP006RKzSs0JptsN84=",
+ "owner": "NixOS",
+ "repo": "nixpkgs",
+ "rev": "614b4613980a522ba49f0d194531beddbb7220d3",
+ "type": "github"
+ },
+ "original": {
+ "owner": "NixOS",
+ "ref": "nixos-23.11",
+ "repo": "nixpkgs",
+ "type": "github"
+ }
+ },
+ "pre-commit-hooks-nix": {
+ "inputs": {
+ "flake-compat": [
+ "lanzaboote",
+ "flake-compat"
+ ],
+ "flake-utils": [
+ "lanzaboote",
+ "flake-utils"
+ ],
+ "gitignore": "gitignore",
+ "nixpkgs": [
+ "lanzaboote",
+ "nixpkgs"
+ ],
+ "nixpkgs-stable": "nixpkgs-stable"
+ },
+ "locked": {
+ "lastModified": 1710923068,
+ "narHash": "sha256-6hOpUiuxuwpXXc/xfJsBUJeqqgGI+JMJuLo45aG3cKc=",
+ "owner": "cachix",
+ "repo": "pre-commit-hooks.nix",
+ "rev": "e611897ddfdde3ed3eaac4758635d7177ff78673",
+ "type": "github"
+ },
+ "original": {
+ "owner": "cachix",
+ "repo": "pre-commit-hooks.nix",
+ "type": "github"
+ }
+ },
+ "root": {
+ "inputs": {
+ "flake-compat": "flake-compat",
+ "flake-utils": "flake-utils",
+ "lanzaboote": "lanzaboote",
+ "nixpkgs": "nixpkgs"
+ }
+ },
+ "rust-overlay": {
+ "inputs": {
+ "flake-utils": [
+ "lanzaboote",
+ "flake-utils"
+ ],
+ "nixpkgs": [
+ "lanzaboote",
+ "nixpkgs"
+ ]
+ },
+ "locked": {
+ "lastModified": 1711246447,
+ "narHash": "sha256-g9TOluObcOEKewFo2fR4cn51Y/jSKhRRo4QZckHLop0=",
+ "owner": "oxalica",
+ "repo": "rust-overlay",
+ "rev": "dcc802a6ec4e9cc6a1c8c393327f0c42666f22e4",
+ "type": "github"
+ },
+ "original": {
+ "owner": "oxalica",
+ "repo": "rust-overlay",
+ "type": "github"
+ }
+ },
+ "systems": {
+ "locked": {
+ "lastModified": 1681028828,
+ "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
+ "owner": "nix-systems",
+ "repo": "default",
+ "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
+ "type": "github"
+ },
+ "original": {
+ "owner": "nix-systems",
+ "repo": "default",
+ "type": "github"
+ }
+ }
+ },
+ "root": "root",
+ "version": 7
+}
diff --git a/tests/functional/flakes/flake-metadata/metadata.out.expected b/tests/functional/flakes/flake-metadata/metadata.out.expected
new file mode 100644
index 000000000..72e57eca7
--- /dev/null
+++ b/tests/functional/flakes/flake-metadata/metadata.out.expected
@@ -0,0 +1,36 @@
+Path: /nix/store/gaxb42z68bcr8lch467shvmnhjjzgd8b-source
+Last modified: 1970-01-01 00:16:40
+Inputs:
+├───flake-compat: github:edolstra/flake-compat/0f9255e01c2351cc7d116c072cb317785dd33b33
+│ Last modified: 2023-10-04 13:37:54
+├───flake-utils: github:numtide/flake-utils/b1d9ab70662946ef0850d488da1c9019f3a9752a
+│ Last modified: 2024-03-11 08:33:50
+│ └───systems: github:nix-systems/default/da67096a3b9bf56a91d16901293e51ba5b49a27e
+│ Last modified: 2023-04-09 08:27:08
+├───lanzaboote: github:nix-community/lanzaboote/850f27322239f8cfa56b122cc9a278ab99a49015
+│ Last modified: 2024-04-17 16:03:51
+│ ├───crane: github:ipetkov/crane/880573f80d09e18a11713f402b9e6172a085449f
+│ │ Last modified: 2024-03-24 16:53:56
+│ │ └───nixpkgs follows input 'lanzaboote/nixpkgs'
+│ ├───flake-compat follows input 'flake-compat'
+│ ├───flake-parts: github:hercules-ci/flake-parts/f7b3c975cf067e56e7cda6cb098ebe3fb4d74ca2
+│ │ Last modified: 2024-03-01 23:36:56
+│ │ └───nixpkgs-lib follows input 'lanzaboote/nixpkgs'
+│ ├───flake-utils follows input 'flake-utils'
+│ ├───nixpkgs follows input 'nixpkgs'
+│ ├───pre-commit-hooks-nix: github:cachix/pre-commit-hooks.nix/e611897ddfdde3ed3eaac4758635d7177ff78673
+│ │ Last modified: 2024-03-20 08:24:28
+│ │ ├───flake-compat follows input 'lanzaboote/flake-compat'
+│ │ ├───flake-utils follows input 'lanzaboote/flake-utils'
+│ │ ├───gitignore: github:hercules-ci/gitignore.nix/637db329424fd7e46cf4185293b9cc8c88c95394
+│ │ │ Last modified: 2024-02-28 02:28:52
+│ │ │ └───nixpkgs follows input 'lanzaboote/pre-commit-hooks-nix/nixpkgs'
+│ │ ├───nixpkgs follows input 'lanzaboote/nixpkgs'
+│ │ └───nixpkgs-stable: github:NixOS/nixpkgs/614b4613980a522ba49f0d194531beddbb7220d3
+│ │ Last modified: 2024-03-17 17:16:56
+│ └───rust-overlay: github:oxalica/rust-overlay/dcc802a6ec4e9cc6a1c8c393327f0c42666f22e4
+│ Last modified: 2024-03-24 02:14:07
+│ ├───flake-utils follows input 'lanzaboote/flake-utils'
+│ └───nixpkgs follows input 'lanzaboote/nixpkgs'
+└───nixpkgs: github:nixos/nixpkgs/7f993cdf26ccef564eabf31fdb40d140821e12bc
+ Last modified: 2024-07-01 09:00:38
diff --git a/tests/functional/lang/eval-okay-derivation-legacy.err.exp b/tests/functional/lang/eval-okay-derivation-legacy.err.exp
new file mode 100644
index 000000000..94f0854dd
--- /dev/null
+++ b/tests/functional/lang/eval-okay-derivation-legacy.err.exp
@@ -0,0 +1,6 @@
+warning: In a derivation named 'eval-okay-derivation-legacy', 'structuredAttrs' disables the effect of the derivation attribute 'allowedReferences'; use 'outputChecks.<output>.allowedReferences' instead
+warning: In a derivation named 'eval-okay-derivation-legacy', 'structuredAttrs' disables the effect of the derivation attribute 'allowedRequisites'; use 'outputChecks.<output>.allowedRequisites' instead
+warning: In a derivation named 'eval-okay-derivation-legacy', 'structuredAttrs' disables the effect of the derivation attribute 'disallowedReferences'; use 'outputChecks.<output>.disallowedReferences' instead
+warning: In a derivation named 'eval-okay-derivation-legacy', 'structuredAttrs' disables the effect of the derivation attribute 'disallowedRequisites'; use 'outputChecks.<output>.disallowedRequisites' instead
+warning: In a derivation named 'eval-okay-derivation-legacy', 'structuredAttrs' disables the effect of the derivation attribute 'maxClosureSize'; use 'outputChecks.<output>.maxClosureSize' instead
+warning: In a derivation named 'eval-okay-derivation-legacy', 'structuredAttrs' disables the effect of the derivation attribute 'maxSize'; use 'outputChecks.<output>.maxSize' instead
diff --git a/tests/functional/lang/eval-okay-derivation-legacy.exp b/tests/functional/lang/eval-okay-derivation-legacy.exp
new file mode 100644
index 000000000..4f374a1aa
--- /dev/null
+++ b/tests/functional/lang/eval-okay-derivation-legacy.exp
@@ -0,0 +1 @@
+"/nix/store/mzgwvrjjir216ra58mwwizi8wj6y9ddr-eval-okay-derivation-legacy"
diff --git a/tests/functional/lang/eval-okay-derivation-legacy.nix b/tests/functional/lang/eval-okay-derivation-legacy.nix
new file mode 100644
index 000000000..b529cdf90
--- /dev/null
+++ b/tests/functional/lang/eval-okay-derivation-legacy.nix
@@ -0,0 +1,12 @@
+(builtins.derivationStrict {
+ name = "eval-okay-derivation-legacy";
+ system = "x86_64-linux";
+ builder = "/dontcare";
+ __structuredAttrs = true;
+ allowedReferences = [ ];
+ disallowedReferences = [ ];
+ allowedRequisites = [ ];
+ disallowedRequisites = [ ];
+ maxSize = 1234;
+ maxClosureSize = 12345;
+}).out
diff --git a/tests/functional/meson.build b/tests/functional/meson.build
index 7a9c7182f..2b5dfe422 100644
--- a/tests/functional/meson.build
+++ b/tests/functional/meson.build
@@ -69,8 +69,9 @@ functional_tests_scripts = [
'flakes/unlocked-override.sh',
'flakes/absolute-paths.sh',
'flakes/build-paths.sh',
- 'flakes/flake-registry.sh',
'flakes/flake-in-submodule.sh',
+ 'flakes/flake-metadata.sh',
+ 'flakes/flake-registry.sh',
'flakes/subdir-flake.sh',
'gc.sh',
'nix-collect-garbage-d.sh',
diff --git a/tests/functional/search.sh b/tests/functional/search.sh
index d9c7a75da..1a2a20089 100644
--- a/tests/functional/search.sh
+++ b/tests/functional/search.sh
@@ -29,6 +29,8 @@ nix search -f search.nix '' ^ | grepQuiet hello
## Tests for multiple regex/match highlighting
+# FIXME: possibly not test this with colour in the future
+export CLICOLOR_FORCE=1
e=$'\x1b' # grep doesn't support \e, \033 or even \x1b
# Multiple overlapping regexes
(( $(nix search -f search.nix '' 'oo' 'foo' 'oo' | grep -c "$e\[32;1mfoo$e\\[0;1m") == 1 ))
diff --git a/tests/unit/libexpr-support/tests/libexpr.hh b/tests/unit/libexpr-support/tests/libexpr.hh
index 01dcbb34c..745aa168d 100644
--- a/tests/unit/libexpr-support/tests/libexpr.hh
+++ b/tests/unit/libexpr-support/tests/libexpr.hh
@@ -26,9 +26,9 @@ namespace nix {
, state({}, store)
{
}
- Value eval(std::string input, bool forceValue = true) {
+ Value eval(std::string input, bool forceValue = true, const ExperimentalFeatureSettings & xpSettings = experimentalFeatureSettings) {
Value v;
- Expr & e = state.parseExprFromString(input, state.rootPath(CanonPath::root));
+ Expr & e = state.parseExprFromString(input, state.rootPath(CanonPath::root), xpSettings);
state.eval(e, v);
if (forceValue)
state.forceValue(v, noPos);
diff --git a/tests/unit/libexpr/trivial.cc b/tests/unit/libexpr/trivial.cc
index 171727ac7..19b62aff8 100644
--- a/tests/unit/libexpr/trivial.cc
+++ b/tests/unit/libexpr/trivial.cc
@@ -59,6 +59,11 @@ namespace nix {
ASSERT_THAT(v, IsFloatEq(1.234));
}
+ TEST_F(TrivialExpressionTest, pointfloat) {
+ auto v = eval(".234");
+ ASSERT_THAT(v, IsFloatEq(0.234));
+ }
+
TEST_F(TrivialExpressionTest, updateAttrs) {
auto v = eval("{ a = 1; } // { b = 2; a = 3; }");
ASSERT_THAT(v, IsAttrsOfSize(2));
@@ -81,6 +86,18 @@ namespace nix {
ASSERT_THAT(v, IsTrue());
}
+ TEST_F(TrivialExpressionTest, urlLiteral) {
+ auto v = eval("https://nixos.org");
+ ASSERT_THAT(v, IsStringEq("https://nixos.org"));
+ }
+
+ TEST_F(TrivialExpressionTest, noUrlLiteral) {
+ ExperimentalFeatureSettings mockXpSettings;
+ mockXpSettings.set("experimental-features", "no-url-literals");
+
+ ASSERT_THROW(eval("https://nixos.org", true, mockXpSettings), Error);
+ }
+
TEST_F(TrivialExpressionTest, withFound) {
auto v = eval("with { a = 23; }; a");
ASSERT_THAT(v, IsIntEq(23));
diff --git a/tests/unit/libutil-support/tests/cli-literate-parser.cc b/tests/unit/libutil-support/tests/cli-literate-parser.cc
index f74fe85eb..3aa55859c 100644
--- a/tests/unit/libutil-support/tests/cli-literate-parser.cc
+++ b/tests/unit/libutil-support/tests/cli-literate-parser.cc
@@ -1,20 +1,16 @@
#include "cli-literate-parser.hh"
#include "escape-string.hh"
-#include "escape-char.hh"
-#include "libexpr/print.hh"
#include "types.hh"
#include <ranges>
#include <boost/algorithm/string/replace.hpp>
#include <boost/algorithm/string/trim.hpp>
#include <iostream>
-#include <memory>
#include <sstream>
#include <variant>
#include "cli-literate-parser.hh"
#include "escape-string.hh"
#include "fmt.hh"
-#include "libexpr/print.hh"
#include "shlex.hh"
#include "types.hh"
#include "strings.hh"
@@ -361,9 +357,8 @@ const char * ParseError::what() const noexcept
return what_->c_str();
} else {
auto escaped = escapeString(rest, {.maxLength = 256, .escapeNonPrinting = true});
- auto hint =
- new HintFmt("Parse error: Expected %1%, got:\n%2%", expected, Uncolored(escaped));
- what_ = hint->str();
+ auto hint = HintFmt("Parse error: Expected %1%, got:\n%2%", expected, Uncolored(escaped));
+ what_ = hint.str();
return what_->c_str();
}
}