2023-05-14 22:28:31 +02:00
|
|
|
# Run:
|
|
|
|
# [nixpkgs]$ nix-instantiate --eval --strict lib/tests/systems.nix
|
|
|
|
# Expected output: [], or the failed cases
|
2017-04-25 02:12:43 +02:00
|
|
|
let
|
|
|
|
lib = import ../default.nix;
|
|
|
|
mseteq = x: y: {
|
|
|
|
expr = lib.sort lib.lessThan x;
|
|
|
|
expected = lib.sort lib.lessThan y;
|
|
|
|
};
|
2020-11-04 15:13:06 +01:00
|
|
|
in
|
2023-05-14 22:28:31 +02:00
|
|
|
lib.runTests (
|
|
|
|
# We assert that the new algorithmic way of generating these lists matches the
|
|
|
|
# way they were hard-coded before.
|
|
|
|
#
|
|
|
|
# One might think "if we exhaustively test, what's the point of procedurally
|
|
|
|
# calculating the lists anyway?". The answer is one can mindlessly update these
|
|
|
|
# tests as new platforms become supported, and then just give the diff a quick
|
|
|
|
# sanity check before committing :).
|
|
|
|
|
|
|
|
(with lib.systems.doubles; {
|
2020-11-04 15:13:06 +01:00
|
|
|
testall = mseteq all (linux ++ darwin ++ freebsd ++ openbsd ++ netbsd ++ illumos ++ wasi ++ windows ++ embedded ++ mmix ++ js ++ genode ++ redox);
|
2017-02-09 22:09:47 +01:00
|
|
|
|
2021-04-19 00:53:35 +02:00
|
|
|
testarm = mseteq arm [ "armv5tel-linux" "armv6l-linux" "armv6l-netbsd" "armv6l-none" "armv7a-linux" "armv7a-netbsd" "armv7l-linux" "armv7l-netbsd" "arm-none" "armv7a-darwin" ];
|
2023-01-19 17:39:30 +01:00
|
|
|
testarmv7 = mseteq armv7 [ "armv7a-darwin" "armv7a-linux" "armv7l-linux" "armv7a-netbsd" "armv7l-netbsd" ];
|
2022-10-31 13:35:51 +01:00
|
|
|
testi686 = mseteq i686 [ "i686-linux" "i686-freebsd13" "i686-genode" "i686-netbsd" "i686-openbsd" "i686-cygwin" "i686-windows" "i686-none" "i686-darwin" ];
|
2023-05-19 21:52:57 +02:00
|
|
|
testmips = mseteq mips [ "mips-linux" "mips64-linux" "mips64el-linux" "mipsel-linux" "mipsel-netbsd" ];
|
2020-11-04 15:13:06 +01:00
|
|
|
testmmix = mseteq mmix [ "mmix-mmixware" ];
|
2023-01-19 17:39:50 +01:00
|
|
|
testpower = mseteq power [ "powerpc-netbsd" "powerpc-none" "powerpc64-linux" "powerpc64le-linux" "powerpcle-none" ];
|
2022-04-27 16:03:47 +02:00
|
|
|
testriscv = mseteq riscv [ "riscv32-linux" "riscv64-linux" "riscv32-netbsd" "riscv64-netbsd" "riscv32-none" "riscv64-none" ];
|
2022-04-27 16:04:08 +02:00
|
|
|
testriscv32 = mseteq riscv32 [ "riscv32-linux" "riscv32-netbsd" "riscv32-none" ];
|
|
|
|
testriscv64 = mseteq riscv64 [ "riscv64-linux" "riscv64-netbsd" "riscv64-none" ];
|
2023-01-19 17:40:01 +01:00
|
|
|
tests390x = mseteq s390x [ "s390x-linux" "s390x-none" ];
|
2022-10-31 13:35:51 +01:00
|
|
|
testx86_64 = mseteq x86_64 [ "x86_64-linux" "x86_64-darwin" "x86_64-freebsd13" "x86_64-genode" "x86_64-redox" "x86_64-openbsd" "x86_64-netbsd" "x86_64-cygwin" "x86_64-solaris" "x86_64-windows" "x86_64-none" ];
|
2017-02-09 22:09:47 +01:00
|
|
|
|
2018-10-18 21:12:49 +02:00
|
|
|
testcygwin = mseteq cygwin [ "i686-cygwin" "x86_64-cygwin" ];
|
2019-07-10 20:38:55 +02:00
|
|
|
testdarwin = mseteq darwin [ "x86_64-darwin" "i686-darwin" "aarch64-darwin" "armv7a-darwin" ];
|
2022-10-31 13:35:51 +01:00
|
|
|
testfreebsd = mseteq freebsd [ "i686-freebsd13" "x86_64-freebsd13" ];
|
2020-08-04 17:50:55 +02:00
|
|
|
testgenode = mseteq genode [ "aarch64-genode" "i686-genode" "x86_64-genode" ];
|
2020-07-21 22:11:36 +02:00
|
|
|
testredox = mseteq redox [ "x86_64-redox" ];
|
2018-10-18 21:12:49 +02:00
|
|
|
testgnu = mseteq gnu (linux /* ++ kfreebsd ++ ... */);
|
|
|
|
testillumos = mseteq illumos [ "x86_64-solaris" ];
|
2023-05-19 21:52:57 +02:00
|
|
|
testlinux = mseteq linux [ "aarch64-linux" "armv5tel-linux" "armv6l-linux" "armv7a-linux" "armv7l-linux" "i686-linux" "loongarch64-linux" "m68k-linux" "microblaze-linux" "microblazeel-linux" "mips-linux" "mips64-linux" "mips64el-linux" "mipsel-linux" "powerpc64-linux" "powerpc64le-linux" "riscv32-linux" "riscv64-linux" "s390-linux" "s390x-linux" "x86_64-linux" ];
|
2021-08-01 14:25:45 +02:00
|
|
|
testnetbsd = mseteq netbsd [ "aarch64-netbsd" "armv6l-netbsd" "armv7a-netbsd" "armv7l-netbsd" "i686-netbsd" "m68k-netbsd" "mipsel-netbsd" "powerpc-netbsd" "riscv32-netbsd" "riscv64-netbsd" "x86_64-netbsd" ];
|
2018-10-18 21:12:49 +02:00
|
|
|
testopenbsd = mseteq openbsd [ "i686-openbsd" "x86_64-openbsd" ];
|
|
|
|
testwindows = mseteq windows [ "i686-cygwin" "x86_64-cygwin" "i686-windows" "x86_64-windows" ];
|
2020-07-21 22:11:36 +02:00
|
|
|
testunix = mseteq unix (linux ++ darwin ++ freebsd ++ openbsd ++ netbsd ++ illumos ++ cygwin ++ redox);
|
2023-05-14 22:28:31 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
// {
|
|
|
|
test_equals_example_x86_64-linux = {
|
|
|
|
expr = lib.systems.equals (lib.systems.elaborate "x86_64-linux") (lib.systems.elaborate "x86_64-linux");
|
|
|
|
expected = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
test_toLosslessStringMaybe_example_x86_64-linux = {
|
|
|
|
expr = lib.systems.toLosslessStringMaybe (lib.systems.elaborate "x86_64-linux");
|
|
|
|
expected = "x86_64-linux";
|
|
|
|
};
|
|
|
|
test_toLosslessStringMaybe_fail = {
|
|
|
|
expr = lib.systems.toLosslessStringMaybe (lib.systems.elaborate "x86_64-linux" // { something = "extra"; });
|
|
|
|
expected = null;
|
|
|
|
};
|
2017-02-09 22:09:47 +01:00
|
|
|
}
|
2023-05-14 22:28:31 +02:00
|
|
|
|
|
|
|
# Generate test cases to assert that a change in any non-function attribute makes a platform unequal
|
|
|
|
// lib.concatMapAttrs (platformAttrName: origValue: {
|
|
|
|
|
|
|
|
${"test_equals_unequal_${platformAttrName}"} =
|
|
|
|
let modified =
|
|
|
|
assert origValue != arbitraryValue;
|
|
|
|
lib.systems.elaborate "x86_64-linux" // { ${platformAttrName} = arbitraryValue; };
|
2023-06-13 10:22:06 +02:00
|
|
|
arbitraryValue = x: "<<modified>>";
|
2023-05-14 22:28:31 +02:00
|
|
|
in {
|
|
|
|
expr = lib.systems.equals (lib.systems.elaborate "x86_64-linux") modified;
|
|
|
|
expected = {
|
|
|
|
# Changes in these attrs are not detectable because they're function.
|
|
|
|
# The functions should be derived from the data, so this is not a problem.
|
|
|
|
canExecute = null;
|
|
|
|
emulator = null;
|
|
|
|
emulatorAvailable = null;
|
|
|
|
isCompatible = null;
|
|
|
|
}?${platformAttrName};
|
|
|
|
};
|
|
|
|
|
|
|
|
}) (lib.systems.elaborate "x86_64-linux" /* arbitrary choice, just to get all the elaborated attrNames */)
|
|
|
|
|
|
|
|
)
|