at 24.05-pre 92 lines 2.1 kB view raw
1{ fetchurl 2, formats 3, glibcLocales 4, jdk 5, lib 6, stdenv 7}: 8 9# This test primarily tests correct escaping. 10# See also testJavaProperties in 11# pkgs/pkgs-lib/tests/formats.nix, which tests 12# type coercions and is a bit easier to read. 13 14let 15 inherit (lib) concatStrings attrValues mapAttrs; 16 17 javaProperties = formats.javaProperties { }; 18 19 input = { 20 foo = "bar"; 21 "empty value" = ""; 22 "typical.dot.syntax" = "com.sun.awt"; 23 "" = "empty key's value"; 24 "1" = "2 3"; 25 "#" = "not a comment # still not"; 26 "!" = "not a comment!"; 27 "!a" = "still not! a comment"; 28 "!b" = "still not ! a comment"; 29 "dos paths" = "C:\\Program Files\\Nix For Windows\\nix.exe"; 30 "a \t\nb" = " c"; 31 "angry \t\nkey" = '' 32 multi 33 ${"\tline\r"} 34 space- 35 indented 36 trailing-space${" "} 37 trailing-space${" "} 38 value 39 ''; 40 "this=not" = "bad"; 41 "nor = this" = "bad"; 42 "all stuff" = "foo = bar"; 43 "unicode big brain" = "e = mc"; 44 "ütf-8" = "dûh"; 45 # NB: Some editors (vscode) show this _whole_ line in right-to-left order 46 "الجبر" = "أكثر من مجرد أرقام"; 47 }; 48 49in 50stdenv.mkDerivation { 51 name = "pkgs.formats.javaProperties-test-${jdk.name}"; 52 nativeBuildInputs = [ 53 jdk 54 glibcLocales 55 ]; 56 57 # technically should go through the type.merge first, but that's tested 58 # in tests/formats.nix. 59 properties = javaProperties.generate "example.properties" input; 60 61 # Expected output as printed by Main.java 62 passAsFile = [ "expected" ]; 63 expected = concatStrings (attrValues ( 64 mapAttrs 65 (key: value: 66 '' 67 KEY 68 ${key} 69 VALUE 70 ${value} 71 72 '' 73 ) 74 input 75 )); 76 77 src = lib.sourceByRegex ./. [ 78 ".*\.java" 79 ]; 80 # On Linux, this can be C.UTF-8, but darwin + zulu requires en_US.UTF-8 81 LANG = "en_US.UTF-8"; 82 buildPhase = '' 83 javac Main.java 84 ''; 85 doCheck = true; 86 checkPhase = '' 87 cat -v $properties 88 java Main $properties >actual 89 diff -U3 $expectedPath actual 90 ''; 91 installPhase = "touch $out"; 92}