Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{ glib 2, haskellPackages 3, lib 4, nodePackages 5, perlPackages 6, pypy2Packages 7, python3Packages 8, pypy3Packages 9, runCommand 10, writers 11, writeText 12}: 13with writers; 14let 15 16 bin = { 17 bash = writeBashBin "test-writers-bash-bin" '' 18 if [[ "test" == "test" ]]; then echo "success"; fi 19 ''; 20 21 dash = writeDashBin "test-writers-dash-bin" '' 22 test '~' = '~' && echo 'success' 23 ''; 24 25 fish = writeFishBin "test-writers-fish-bin" '' 26 if test "test" = "test" 27 echo "success" 28 end 29 ''; 30 31 rust = writeRustBin "test-writers-rust-bin" {} '' 32 fn main(){ 33 println!("success") 34 } 35 ''; 36 37 haskell = writeHaskellBin "test-writers-haskell-bin" { libraries = [ haskellPackages.acme-default ]; } '' 38 import Data.Default 39 40 int :: Int 41 int = def 42 43 main :: IO () 44 main = case int of 45 18871 -> putStrLn $ id "success" 46 _ -> print "fail" 47 ''; 48 49 js = writeJSBin "test-writers-js-bin" { libraries = [ nodePackages.semver ]; } '' 50 var semver = require('semver'); 51 52 if (semver.valid('1.2.3')) { 53 console.log('success') 54 } else { 55 console.log('fail') 56 } 57 ''; 58 59 perl = writePerlBin "test-writers-perl-bin" { libraries = [ perlPackages.boolean ]; } '' 60 use boolean; 61 print "success\n" if true; 62 ''; 63 64 pypy2 = writePyPy2Bin "test-writers-pypy2-bin" { libraries = [ pypy2Packages.enum ]; } '' 65 from enum import Enum 66 67 68 class Test(Enum): 69 a = "success" 70 71 72 print Test.a 73 ''; 74 75 python3 = writePython3Bin "test-writers-python3-bin" { libraries = [ python3Packages.pyyaml ]; } '' 76 import yaml 77 78 y = yaml.load(""" 79 - test: success 80 """) 81 print(y[0]['test']) 82 ''; 83 84 pypy3 = writePyPy3Bin "test-writers-pypy3-bin" { libraries = [ pypy3Packages.pyyaml ]; } '' 85 import yaml 86 87 y = yaml.load(""" 88 - test: success 89 """) 90 print(y[0]['test']) 91 ''; 92 }; 93 94 simple = { 95 bash = writeBash "test-writers-bash" '' 96 if [[ "test" == "test" ]]; then echo "success"; fi 97 ''; 98 99 dash = writeDash "test-writers-dash" '' 100 test '~' = '~' && echo 'success' 101 ''; 102 103 fish = writeFish "test-writers-fish" '' 104 if test "test" = "test" 105 echo "success" 106 end 107 ''; 108 109 haskell = writeHaskell "test-writers-haskell" { libraries = [ haskellPackages.acme-default ]; } '' 110 import Data.Default 111 112 int :: Int 113 int = def 114 115 main :: IO () 116 main = case int of 117 18871 -> putStrLn $ id "success" 118 _ -> print "fail" 119 ''; 120 121 js = writeJS "test-writers-js" { libraries = [ nodePackages.semver ]; } '' 122 var semver = require('semver'); 123 124 if (semver.valid('1.2.3')) { 125 console.log('success') 126 } else { 127 console.log('fail') 128 } 129 ''; 130 131 perl = writePerl "test-writers-perl" { libraries = [ perlPackages.boolean ]; } '' 132 use boolean; 133 print "success\n" if true; 134 ''; 135 136 pypy2 = writePyPy2 "test-writers-pypy2" { libraries = [ pypy2Packages.enum ]; } '' 137 from enum import Enum 138 139 140 class Test(Enum): 141 a = "success" 142 143 144 print Test.a 145 ''; 146 147 python3 = writePython3 "test-writers-python3" { libraries = [ python3Packages.pyyaml ]; } '' 148 import yaml 149 150 y = yaml.load(""" 151 - test: success 152 """) 153 print(y[0]['test']) 154 ''; 155 156 pypy3 = writePyPy3 "test-writers-pypy3" { libraries = [ pypy3Packages.pyyaml ]; } '' 157 import yaml 158 159 y = yaml.load(""" 160 - test: success 161 """) 162 print(y[0]['test']) 163 ''; 164 165 fsharp = makeFSharpWriter { 166 libraries = { fetchNuGet }: [ 167 (fetchNuGet { pname = "FSharp.SystemTextJson"; version = "0.17.4"; sha256 = "1bplzc9ybdqspii4q28l8gmfvzpkmgq5l1hlsiyg2h46w881lwg2"; }) 168 ]; 169 } "test-writers-fsharp" '' 170 #r "nuget: FSharp.SystemTextJson, 0.17.4" 171 172 module Json = 173 open System.Text.Json 174 open System.Text.Json.Serialization 175 let options = JsonSerializerOptions() 176 options.Converters.Add(JsonFSharpConverter()) 177 let serialize<'a> (o: 'a) = JsonSerializer.Serialize<'a>(o, options) 178 let deserialize<'a> (str: string) = JsonSerializer.Deserialize<'a>(str, options) 179 180 type Letter = A | B 181 let a = {| Hello = Some "World"; Letter = A |} 182 if a |> Json.serialize |> Json.deserialize |> (=) a 183 then "success" 184 else "failed" 185 |> printfn "%s" 186 ''; 187 188 pypy2NoLibs = writePyPy2 "test-writers-pypy2-no-libs" {} '' 189 print("success") 190 ''; 191 192 python3NoLibs = writePython3 "test-writers-python3-no-libs" {} '' 193 print("success") 194 ''; 195 196 pypy3NoLibs = writePyPy3 "test-writers-pypy3-no-libs" {} '' 197 print("success") 198 ''; 199 200 fsharpNoNugetDeps = writeFSharp "test-writers-fsharp-no-nuget-deps" '' 201 printfn "success" 202 ''; 203 }; 204 205 206 path = { 207 bash = writeBash "test-writers-bash-path" (writeText "test" '' 208 if [[ "test" == "test" ]]; then echo "success"; fi 209 ''); 210 haskell = writeHaskell "test-writers-haskell-path" { libraries = [ haskellPackages.acme-default ]; } (writeText "test" '' 211 import Data.Default 212 213 int :: Int 214 int = def 215 216 main :: IO () 217 main = case int of 218 18871 -> putStrLn $ id "success" 219 _ -> print "fail" 220 ''); 221 }; 222 223 writeTest = expectedValue: name: test: 224 writeDash "run-${name}" '' 225 if test "$(${test})" != "${expectedValue}"; then 226 echo 'test ${test} failed' 227 exit 1 228 fi 229 ''; 230 231in runCommand "test-writers" { 232 passthru = { inherit writeTest bin simple path; }; 233 meta.platforms = lib.platforms.all; 234} '' 235 ${lib.concatMapStringsSep "\n" (test: writeTest "success" test.name "${test}/bin/${test.name}") (lib.attrValues bin)} 236 ${lib.concatMapStringsSep "\n" (test: writeTest "success" test.name test) (lib.attrValues simple)} 237 ${lib.concatMapStringsSep "\n" (test: writeTest "success" test.name test) (lib.attrValues path)} 238 239 echo 'nix-writers successfully tested' >&2 240 touch $out 241'' 242