lib/tests: add tests for lib.licenses

This commit is contained in:
jopejoe1
2026-01-22 20:36:13 +01:00
parent bb8e1c54e9
commit dbdb37908f
2 changed files with 102 additions and 3 deletions

View File

@@ -76,7 +76,7 @@
- [exception] Exception to apply
*/
WITH = license: exception: {
licenseType = "compound";
licenseType = "exception";
operator = "WITH";
inherit license exception;
};
@@ -88,8 +88,8 @@
# Example
```nix
PLUS lib.licenses.lgpl21Only
=> { licenseType = "plus"; operator = "+"; license = lib.licenses.lgpl21Only; };
PLUS lib.licenses.eupl11
=> { licenseType = "plus"; operator = "+"; license = lib.licenses.eupl11; };
```
# Type

View File

@@ -5012,4 +5012,103 @@ runTests {
testReplaceElemAtOutOfRange = testingThrow (lib.replaceElemAt [ 1 2 3 ] 5 "a");
testReplaceElemAtNegative = testingThrow (lib.replaceElemAt [ 1 2 3 ] (-1) "a");
testIsFree = {
expr = lib.licenses.isFree (
lib.licenses.AND [
(lib.licenses.mit)
(lib.licenses.OR [
lib.licenses.free
lib.licenses.unfree
])
(lib.licenses.WITH lib.licenses.asl20 lib.licenses.llvm-exception)
(lib.licenses.PLUS lib.licenses.eupl11)
]
);
expected = true;
};
testIsUnfree = {
expr = lib.licenses.isFree (
lib.licenses.AND [
(lib.licenses.mit)
(lib.licenses.OR [ lib.licenses.unfree ])
(lib.licenses.WITH lib.licenses.asl20 lib.licenses.llvm-exception)
(lib.licenses.PLUS lib.licenses.eupl11)
]
);
expected = false;
};
testIsRedistributable = {
expr = lib.licenses.isRedistributable (
lib.licenses.AND [
(lib.licenses.mit)
(lib.licenses.OR [
lib.licenses.free
lib.licenses.unfree
])
(lib.licenses.WITH lib.licenses.asl20 lib.licenses.llvm-exception)
(lib.licenses.PLUS lib.licenses.eupl11)
]
);
expected = true;
};
testIsUnredistributable = {
expr = lib.licenses.isRedistributable (
lib.licenses.AND [
(lib.licenses.mit)
(lib.licenses.OR [ lib.licenses.unfree ])
(lib.licenses.WITH lib.licenses.asl20 lib.licenses.llvm-exception)
(lib.licenses.PLUS lib.licenses.eupl11)
]
);
expected = false;
};
testContainsLicenses = {
expr = lib.licenses.containsLicenses [ lib.licenses.mit ] (
lib.licenses.AND [
(lib.licenses.mit)
(lib.licenses.OR [
lib.licenses.free
lib.licenses.unfree
])
(lib.licenses.WITH lib.licenses.asl20 lib.licenses.llvm-exception)
(lib.licenses.PLUS lib.licenses.eupl11)
]
);
expected = true;
};
testToSPDX = {
expr = lib.licenses.toSPDX (
lib.licenses.AND [
(lib.licenses.mit)
(lib.licenses.OR [
lib.licenses.free
lib.licenses.unfree
])
(lib.licenses.WITH lib.licenses.asl20 lib.licenses.llvm-exception)
(lib.licenses.PLUS lib.licenses.eupl11)
]
);
expected = "MIT AND (LicenseRef-nixos-free OR LicenseRef-nixos-unfree) AND (Apache-2.0 WITH LLVM-exception) AND EUPL-1.1+";
};
testEvaluateProperty = {
expr = lib.licenses.evaluateProperty (x: x.deprecated) true (
lib.licenses.AND [
(lib.licenses.mit)
(lib.licenses.OR [
lib.licenses.free
lib.licenses.unfree
])
(lib.licenses.WITH lib.licenses.asl20 lib.licenses.llvm-exception)
(lib.licenses.PLUS lib.licenses.eupl11)
]
);
expected = false;
};
}