2 # [nixpkgs]$ nix-instantiate --eval --strict lib/tests/systems.nix
3 # Expected output: [], or the failed cases
5 # OfBorg runs (approximately) nix-build lib/tests/release.nix
7 lib = import ../default.nix;
9 expr = lib.sort lib.lessThan x;
10 expected = lib.sort lib.lessThan y;
14 Try to convert an elaborated system back to a simple string. If not possible,
15 return null. So we have the property:
18 sys == elaborate (toLosslessStringMaybe sys)
20 NOTE: This property is not guaranteed when `sys` was elaborated by a different
23 toLosslessStringMaybe = sys:
24 if lib.isString sys then sys
25 else if lib.systems.equals sys (lib.systems.elaborate sys.system) then sys.system
30 # We assert that the new algorithmic way of generating these lists matches the
31 # way they were hard-coded before.
33 # One might think "if we exhaustively test, what's the point of procedurally
34 # calculating the lists anyway?". The answer is one can mindlessly update these
35 # tests as new platforms become supported, and then just give the diff a quick
36 # sanity check before committing :).
38 (with lib.systems.doubles; {
39 testall = mseteq all (linux ++ darwin ++ freebsd ++ openbsd ++ netbsd ++ illumos ++ wasi ++ windows ++ embedded ++ mmix ++ js ++ genode ++ redox);
41 testarm = mseteq arm [ "armv5tel-linux" "armv6l-linux" "armv6l-netbsd" "armv6l-none" "armv7a-linux" "armv7a-netbsd" "armv7l-linux" "armv7l-netbsd" "arm-none" "armv7a-darwin" ];
42 testarmv7 = mseteq armv7 [ "armv7a-darwin" "armv7a-linux" "armv7l-linux" "armv7a-netbsd" "armv7l-netbsd" ];
43 testi686 = mseteq i686 [ "i686-linux" "i686-freebsd" "i686-genode" "i686-netbsd" "i686-openbsd" "i686-cygwin" "i686-windows" "i686-none" "i686-darwin" ];
44 testmips = mseteq mips [ "mips-none" "mips64-none" "mips-linux" "mips64-linux" "mips64el-linux" "mipsel-linux" "mipsel-netbsd" ];
45 testmmix = mseteq mmix [ "mmix-mmixware" ];
46 testpower = mseteq power [ "powerpc-netbsd" "powerpc-none" "powerpc64-linux" "powerpc64le-linux" "powerpcle-none" ];
47 testriscv = mseteq riscv [ "riscv32-linux" "riscv64-linux" "riscv32-netbsd" "riscv64-netbsd" "riscv32-none" "riscv64-none" ];
48 testriscv32 = mseteq riscv32 [ "riscv32-linux" "riscv32-netbsd" "riscv32-none" ];
49 testriscv64 = mseteq riscv64 [ "riscv64-linux" "riscv64-netbsd" "riscv64-none" ];
50 tests390x = mseteq s390x [ "s390x-linux" "s390x-none" ];
51 testx86_64 = mseteq x86_64 [ "x86_64-linux" "x86_64-darwin" "x86_64-freebsd" "x86_64-genode" "x86_64-redox" "x86_64-openbsd" "x86_64-netbsd" "x86_64-cygwin" "x86_64-solaris" "x86_64-windows" "x86_64-none" ];
53 testcygwin = mseteq cygwin [ "i686-cygwin" "x86_64-cygwin" ];
54 testdarwin = mseteq darwin [ "x86_64-darwin" "i686-darwin" "aarch64-darwin" "armv7a-darwin" ];
55 testfreebsd = mseteq freebsd [ "i686-freebsd" "x86_64-freebsd" ];
56 testgenode = mseteq genode [ "aarch64-genode" "i686-genode" "x86_64-genode" ];
57 testredox = mseteq redox [ "x86_64-redox" ];
58 testgnu = mseteq gnu (linux /* ++ kfreebsd ++ ... */);
59 testillumos = mseteq illumos [ "x86_64-solaris" ];
60 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" ];
61 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" ];
62 testopenbsd = mseteq openbsd [ "i686-openbsd" "x86_64-openbsd" ];
63 testwindows = mseteq windows [ "i686-cygwin" "x86_64-cygwin" "aarch64-windows" "i686-windows" "x86_64-windows" ];
64 testunix = mseteq unix (linux ++ darwin ++ freebsd ++ openbsd ++ netbsd ++ illumos ++ cygwin ++ redox);
68 test_equals_example_x86_64-linux = {
69 expr = lib.systems.equals (lib.systems.elaborate "x86_64-linux") (lib.systems.elaborate "x86_64-linux");
73 test_toLosslessStringMaybe_example_x86_64-linux = {
74 expr = toLosslessStringMaybe (lib.systems.elaborate "x86_64-linux");
75 expected = "x86_64-linux";
77 test_toLosslessStringMaybe_fail = {
78 expr = toLosslessStringMaybe (lib.systems.elaborate "x86_64-linux" // { something = "extra"; });
83 # Generate test cases to assert that a change in any non-function attribute makes a platform unequal
84 // lib.concatMapAttrs (platformAttrName: origValue: {
86 ${"test_equals_unequal_${platformAttrName}"} =
88 assert origValue != arbitraryValue;
89 lib.systems.elaborate "x86_64-linux" // { ${platformAttrName} = arbitraryValue; };
90 arbitraryValue = x: "<<modified>>";
92 expr = lib.systems.equals (lib.systems.elaborate "x86_64-linux") modified;
94 # Changes in these attrs are not detectable because they're function.
95 # The functions should be derived from the data, so this is not a problem.
98 emulatorAvailable = null;
99 staticEmulatorAvailable = null;
101 }?${platformAttrName};
104 }) (lib.systems.elaborate "x86_64-linux" /* arbitrary choice, just to get all the elaborated attrNames */)