summary refs log tree commit diff
path: root/lib/tests
diff options
context:
space:
mode:
authorSilvan Mosberger <github@infinisil.com>2020-12-18 16:42:42 +0100
committerSilvan Mosberger <github@infinisil.com>2020-12-18 16:44:37 +0100
commit9e6737710c4fb2613850e699178b23d54f1a3261 (patch)
tree9ba4d7163707bbc92e8a5917680426b0a01836f4 /lib/tests
parentfd1cc29974de2255d407a706f23aacdfb76f543b (diff)
downloadnixpkgs-9e6737710c4fb2613850e699178b23d54f1a3261.tar
nixpkgs-9e6737710c4fb2613850e699178b23d54f1a3261.tar.gz
nixpkgs-9e6737710c4fb2613850e699178b23d54f1a3261.tar.bz2
nixpkgs-9e6737710c4fb2613850e699178b23d54f1a3261.tar.lz
nixpkgs-9e6737710c4fb2613850e699178b23d54f1a3261.tar.xz
nixpkgs-9e6737710c4fb2613850e699178b23d54f1a3261.tar.zst
nixpkgs-9e6737710c4fb2613850e699178b23d54f1a3261.zip
Revert "Module-builtin assertions, disabling assertions and submodule assertions"
Diffstat (limited to 'lib/tests')
-rw-r--r--lib/tests/misc.nix2
-rwxr-xr-xlib/tests/modules.sh78
-rw-r--r--lib/tests/modules/assertions/condition-true.nix8
-rw-r--r--lib/tests/modules/assertions/enable-false.nix9
-rw-r--r--lib/tests/modules/assertions/multi.nix23
-rw-r--r--lib/tests/modules/assertions/simple.nix6
-rw-r--r--lib/tests/modules/assertions/submodule-attrsOf-attrsOf.nix13
-rw-r--r--lib/tests/modules/assertions/submodule-attrsOf.nix13
-rw-r--r--lib/tests/modules/assertions/submodule.nix13
-rw-r--r--lib/tests/modules/assertions/underscore-attributes.nix8
-rw-r--r--lib/tests/modules/assertions/warning.nix9
11 files changed, 22 insertions, 160 deletions
diff --git a/lib/tests/misc.nix b/lib/tests/misc.nix
index 2d53ed81176..35a5801c724 100644
--- a/lib/tests/misc.nix
+++ b/lib/tests/misc.nix
@@ -655,7 +655,7 @@ runTests {
           modules = [ module ];
         }).options;
 
-        locs = filter (o: ! o.internal) (optionAttrSetToDocList (removeAttrs options [ "_module" ]));
+        locs = filter (o: ! o.internal) (optionAttrSetToDocList options);
       in map (o: o.loc) locs;
     expected = [ [ "foo" ] [ "foo" "<name>" "bar" ] [ "foo" "bar" ] ];
   };
diff --git a/lib/tests/modules.sh b/lib/tests/modules.sh
index 775be9f7209..309c5311361 100755
--- a/lib/tests/modules.sh
+++ b/lib/tests/modules.sh
@@ -27,50 +27,37 @@ reportFailure() {
     fail=$((fail + 1))
 }
 
-checkConfigCodeOutErr() {
-    local expectedExit=$1
-    shift;
+checkConfigOutput() {
     local outputContains=$1
     shift;
-    local errorContains=$1
-    shift;
-    out=$(mktemp)
-    err=$(mktemp)
-    evalConfig "$@" 1>"$out" 2>"$err"
-    if [[ "$?" -ne "$expectedExit" ]]; then
-        echo 2>&1 "error: Expected exit code $expectedExit while evaluating"
-        reportFailure "$@"
-        return 1
-    fi
-
-    if [[ -n "$outputContains" ]] && ! grep -zP --silent "$outputContains" "$out"; then
-        echo 2>&1 "error: Expected output matching '$outputContains', while evaluating"
+    if evalConfig "$@" 2>/dev/null | grep --silent "$outputContains" ; then
+        pass=$((pass + 1))
+        return 0;
+    else
+        echo 2>&1 "error: Expected result matching '$outputContains', while evaluating"
         reportFailure "$@"
         return 1
     fi
-
-    if [[ -n "$errorContains" ]] && ! grep -zP --silent "$errorContains" "$err"; then
-        echo 2>&1 "error: Expected error matching '$errorContains', while evaluating"
-        reportFailure "$@"
-        return 1
-    fi
-
-    pass=$((pass + 1))
-
-    # Clean up temp files
-    rm "$out" "$err"
-}
-
-checkConfigOutput() {
-    local outputContains=$1
-    shift;
-    checkConfigCodeOutErr 0 "$outputContains" "" "$@"
 }
 
 checkConfigError() {
     local errorContains=$1
+    local err=""
     shift;
-    checkConfigCodeOutErr 1 "" "$errorContains" "$@"
+    if err==$(evalConfig "$@" 2>&1 >/dev/null); then
+        echo 2>&1 "error: Expected error code, got exit code 0, while evaluating"
+        reportFailure "$@"
+        return 1
+    else
+        if echo "$err" | grep -zP --silent "$errorContains" ; then
+            pass=$((pass + 1))
+            return 0;
+        else
+            echo 2>&1 "error: Expected error matching '$errorContains', while evaluating"
+            reportFailure "$@"
+            return 1
+        fi
+    fi
 }
 
 # Check boolean option.
@@ -275,29 +262,6 @@ checkConfigOutput true config.value.mkbefore ./types-anything/mk-mods.nix
 checkConfigOutput 1 config.value.nested.foo ./types-anything/mk-mods.nix
 checkConfigOutput baz config.value.nested.bar.baz ./types-anything/mk-mods.nix
 
-## Module assertions
-# Check that assertions are triggered by default for just evaluating config
-checkConfigError 'Failed checks:\n- \[test\] Assertion failed' config ./assertions/simple.nix
-
-# Assertion is not triggered when enable is false or condition is true
-checkConfigOutput '{ }' config ./assertions/condition-true.nix
-checkConfigOutput '{ }' config ./assertions/enable-false.nix
-
-# Warnings should be displayed on standard error
-checkConfigCodeOutErr 0 '{ }' 'warning: \[test\] Warning message' config ./assertions/warning.nix
-
-# Check that multiple assertions and warnings can be triggered at once
-checkConfigError 'Failed checks:\n- \[test1\] Assertion 1 failed\n- \[test2\] Assertion 2 failed' config ./assertions/multi.nix
-checkConfigError 'trace: warning: \[test3\] Warning 3 failed\ntrace: warning: \[test4\] Warning 4 failed' config ./assertions/multi.nix
-
-# Submodules should be able to trigger assertions and display the submodule prefix in their error
-checkConfigError 'Failed checks:\n- \[foo/test\] Assertion failed' config.foo ./assertions/submodule.nix
-checkConfigError 'Failed checks:\n- \[foo.bar/test\] Assertion failed' config.foo.bar ./assertions/submodule-attrsOf.nix
-checkConfigError 'Failed checks:\n- \[foo.bar.baz/test\] Assertion failed' config.foo.bar.baz ./assertions/submodule-attrsOf-attrsOf.nix
-
-# Assertions with an attribute starting with _ shouldn't have their name displayed
-checkConfigError 'Failed checks:\n- Assertion failed' config ./assertions/underscore-attributes.nix
-
 cat <<EOF
 ====== module tests ======
 $pass Pass
diff --git a/lib/tests/modules/assertions/condition-true.nix b/lib/tests/modules/assertions/condition-true.nix
deleted file mode 100644
index 7ca0817a239..00000000000
--- a/lib/tests/modules/assertions/condition-true.nix
+++ /dev/null
@@ -1,8 +0,0 @@
-{
-
-  _module.checks.test = {
-    check = true;
-    message = "Assertion failed";
-  };
-
-}
diff --git a/lib/tests/modules/assertions/enable-false.nix b/lib/tests/modules/assertions/enable-false.nix
deleted file mode 100644
index 11f753bb32e..00000000000
--- a/lib/tests/modules/assertions/enable-false.nix
+++ /dev/null
@@ -1,9 +0,0 @@
-{
-
-  _module.checks.test = {
-    enable = false;
-    check = false;
-    message = "Assertion failed";
-  };
-
-}
diff --git a/lib/tests/modules/assertions/multi.nix b/lib/tests/modules/assertions/multi.nix
deleted file mode 100644
index 1e2e14b8643..00000000000
--- a/lib/tests/modules/assertions/multi.nix
+++ /dev/null
@@ -1,23 +0,0 @@
-{
-
-  _module.checks = {
-    test1 = {
-      check = false;
-      message = "Assertion 1 failed";
-    };
-    test2 = {
-      check = false;
-      message = "Assertion 2 failed";
-    };
-    test3 = {
-      check = false;
-      message = "Warning 3 failed";
-      type = "warning";
-    };
-    test4 = {
-      check = false;
-      message = "Warning 4 failed";
-      type = "warning";
-    };
-  };
-}
diff --git a/lib/tests/modules/assertions/simple.nix b/lib/tests/modules/assertions/simple.nix
deleted file mode 100644
index 115d89a3036..00000000000
--- a/lib/tests/modules/assertions/simple.nix
+++ /dev/null
@@ -1,6 +0,0 @@
-{
-  _module.checks.test = {
-    check = false;
-    message = "Assertion failed";
-  };
-}
diff --git a/lib/tests/modules/assertions/submodule-attrsOf-attrsOf.nix b/lib/tests/modules/assertions/submodule-attrsOf-attrsOf.nix
deleted file mode 100644
index 27a63d1e432..00000000000
--- a/lib/tests/modules/assertions/submodule-attrsOf-attrsOf.nix
+++ /dev/null
@@ -1,13 +0,0 @@
-{ lib, ... }: {
-
-  options.foo = lib.mkOption {
-    default = { bar.baz = {}; };
-    type = lib.types.attrsOf (lib.types.attrsOf (lib.types.submodule {
-      _module.checks.test = {
-        check = false;
-        message = "Assertion failed";
-      };
-    }));
-  };
-
-}
diff --git a/lib/tests/modules/assertions/submodule-attrsOf.nix b/lib/tests/modules/assertions/submodule-attrsOf.nix
deleted file mode 100644
index aac5937cf7e..00000000000
--- a/lib/tests/modules/assertions/submodule-attrsOf.nix
+++ /dev/null
@@ -1,13 +0,0 @@
-{ lib, ... }: {
-
-  options.foo = lib.mkOption {
-    default = { bar = {}; };
-    type = lib.types.attrsOf (lib.types.submodule {
-      _module.checks.test = {
-        check = false;
-        message = "Assertion failed";
-      };
-    });
-  };
-
-}
diff --git a/lib/tests/modules/assertions/submodule.nix b/lib/tests/modules/assertions/submodule.nix
deleted file mode 100644
index 4e7e0b1bd61..00000000000
--- a/lib/tests/modules/assertions/submodule.nix
+++ /dev/null
@@ -1,13 +0,0 @@
-{ lib, ... }: {
-
-  options.foo = lib.mkOption {
-    default = {};
-    type = lib.types.submodule {
-      _module.checks.test = {
-        check = false;
-        message = "Assertion failed";
-      };
-    };
-  };
-
-}
diff --git a/lib/tests/modules/assertions/underscore-attributes.nix b/lib/tests/modules/assertions/underscore-attributes.nix
deleted file mode 100644
index f9ee5c5787b..00000000000
--- a/lib/tests/modules/assertions/underscore-attributes.nix
+++ /dev/null
@@ -1,8 +0,0 @@
-{
-
-  _module.checks._test = {
-    check = false;
-    message = "Assertion failed";
-  };
-
-}
diff --git a/lib/tests/modules/assertions/warning.nix b/lib/tests/modules/assertions/warning.nix
deleted file mode 100644
index 72598ba3fdd..00000000000
--- a/lib/tests/modules/assertions/warning.nix
+++ /dev/null
@@ -1,9 +0,0 @@
-{
-
-  _module.checks.test = {
-    check = false;
-    type = "warning";
-    message = "Warning message";
-  };
-
-}