15 # If you are reading this, you can test these writers by running: nix-build . -A tests.writers
18 inherit (lib) getExe recurseIntoAttrs;
57 runCommand "run-${test.name}" { } ''
58 if [[ "$(${test})" != success ]]; then
59 echo 'test ${test.name} failed'
68 runCommand "run-${test.name}" { } ''
69 if [[ "$(${getExe test})" != success ]]; then
70 echo 'test ${test.name} failed'
80 expectedFile = writeText "${file.name}-expected" expected;
82 testers.testEqualContents {
83 expected = expectedFile;
85 assertion = "${file.name} matches";
89 bin = recurseIntoAttrs {
90 bash = expectSuccessBin (
91 writeBashBin "test-writers-bash-bin" ''
92 if [[ "test" == "test" ]]; then echo "success"; fi
96 dash = expectSuccessBin (
97 writeDashBin "test-writers-dash-bin" ''
98 test '~' = '~' && echo 'success'
102 fish = expectSuccessBin (
103 writeFishBin "test-writers-fish-bin" ''
104 if test "test" = "test"
110 babashka = expectSuccessBin (
111 writeBabashkaBin "test-writers-babashka-bin" { } ''
116 guile = expectSuccessBin (
117 writeGuileBin "test-writers-guile-bin" { } ''
118 (display "success\n")
122 rust = expectSuccessBin (
123 writeRustBin "test-writers-rust-bin" { } ''
130 haskell = expectSuccessBin (
131 writeHaskellBin "test-writers-haskell-bin" { libraries = [ haskellPackages.acme-default ]; } ''
139 18871 -> putStrLn $ id "success"
144 nim = expectSuccessBin (
145 writeNimBin "test-writers-nim-bin" { } ''
150 js = expectSuccessBin (
151 writeJSBin "test-writers-js-bin" { libraries = [ nodePackages.semver ]; } ''
152 var semver = require('semver');
154 if (semver.valid('1.2.3')) {
155 console.log('success')
162 perl = expectSuccessBin (
163 writePerlBin "test-writers-perl-bin" { libraries = [ perlPackages.boolean ]; } ''
165 print "success\n" if true;
169 python3 = expectSuccessBin (
170 writePython3Bin "test-writers-python3-bin" { libraries = [ python3Packages.pyyaml ]; } ''
173 y = yaml.safe_load("""
180 # Commented out because of this issue: https://github.com/NixOS/nixpkgs/issues/39356
182 #pypy2 = expectSuccessBin (writePyPy2Bin "test-writers-pypy2-bin" { libraries = [ pypy2Packages.enum ]; } ''
183 # from enum import Enum
191 #pypy3 = expectSuccessBin (writePyPy3Bin "test-writers-pypy3-bin" { libraries = [ pypy3Packages.pyyaml ]; } ''
194 # y = yaml.safe_load("""
197 # print(y[0]['test'])
200 # Could not test this because of external package issues :(
201 #lua = writeLuaBin "test-writers-lua-bin" { libraries = [ pkgs.luaPackages.say ]; } ''
203 # s:set_namespace("en")
205 # s:set('money', 'I have %s dollars')
206 # s:set('wow', 'So much money!')
208 # print(s('money', {1000})) -- I have 1000 dollars
210 # s:set_namespace("fr") -- switch to french!
211 # s:set('wow', "Tant d'argent!")
213 # print(s('wow')) -- Tant d'argent!
214 # s:set_namespace("en") -- switch back to english!
215 # print(s('wow')) -- So much money!
218 #ruby = expectSuccessBin (writeRubyBin "test-writers-ruby-bin" { libraries = [ rubyPackages.rubocop ]; } ''
219 #puts "This should work!"
223 simple = recurseIntoAttrs {
224 bash = expectSuccess (
225 writeBash "test-writers-bash" ''
226 if [[ "test" == "test" ]]; then echo "success"; fi
230 dash = expectSuccess (
231 writeDash "test-writers-dash" ''
232 test '~' = '~' && echo 'success'
236 fish = expectSuccess (
237 writeFish "test-writers-fish" ''
238 if test "test" = "test"
244 nim = expectSuccess (
245 writeNim "test-writers-nim" { } ''
251 writeNu "test-writers-nushell" ''
256 babashka = expectSuccess (
257 writeBabashka "test-writers-babashka" { } ''
262 guile = expectSuccess (
263 writeGuile "test-writers-guile"
265 libraries = [ guile-lib ];
269 (use-modules (unit-test))
270 (assert-true (= (second '(1 2 3))
272 (display "success\n")
276 guileR6RS = expectSuccess (
277 writeGuile "test-writers-guile-r6rs"
280 libraries = with akkuPackages; [ r6rs-slice ];
283 (import (rnrs base (6))
286 (assert (equal? (slice '(1 2 3) 0 2)
288 (display "success\n")
292 guileR7RS = expectSuccess (
293 writeGuile "test-writers-guile-r7rs"
298 (import (scheme write)
300 (unless (= (second '(1 2 3))
302 (error "The value should be 2."))
303 (display "success\n")
307 haskell = expectSuccess (
308 writeHaskell "test-writers-haskell" { libraries = [ haskellPackages.acme-default ]; } ''
316 18871 -> putStrLn $ id "success"
322 writeJS "test-writers-js" { libraries = [ nodePackages.semver ]; } ''
323 var semver = require('semver');
325 if (semver.valid('1.2.3')) {
326 console.log('success')
333 perl = expectSuccess (
334 writePerl "test-writers-perl" { libraries = [ perlPackages.boolean ]; } ''
336 print "success\n" if true;
340 python3 = expectSuccess (
341 writePython3 "test-writers-python3" { libraries = [ python3Packages.pyyaml ]; } ''
344 y = yaml.safe_load("""
351 # Commented out because of this issue: https://github.com/NixOS/nixpkgs/issues/39356
353 #pypy2 = expectSuccessBin (writePyPy2Bin "test-writers-pypy2-bin" { libraries = [ pypy2Packages.enum ]; } ''
354 # from enum import Enum
362 #pypy3 = expectSuccessBin (writePyPy3Bin "test-writers-pypy3-bin" { libraries = [ pypy3Packages.pyyaml ]; } ''
365 # y = yaml.safe_load("""
368 # print(y[0]['test'])
371 # Commented out because fails with 'error FS0039: The value or constructor 'JsonFSharpConverter' is not defined.'
373 # fsharp = expectSuccess (makeFSharpWriter {
374 # libraries = { fetchNuGet }: [
375 # (fetchNuGet { pname = "FSharp.SystemTextJson"; version = "0.17.4"; sha256 = "1bplzc9ybdqspii4q28l8gmfvzpkmgq5l1hlsiyg2h46w881lwg2"; })
376 # (fetchNuGet { pname = "System.Text.Json"; version = "4.6.0"; sha256 = "0ism236hwi0k6axssfq58s1d8lihplwiz058pdvl8al71hagri39"; })
378 # } "test-writers-fsharp" ''
380 # #r "nuget: FSharp.SystemTextJson, 0.17.4"
383 # open System.Text.Json
384 # open System.Text.Json.Serialization
385 # let options = JsonSerializerOptions()
386 # options.Converters.Add(JsonFSharpConverter())
387 # let serialize<'a> (o: 'a) = JsonSerializer.Serialize<'a>(o, options)
388 # let deserialize<'a> (str: string) = JsonSerializer.Deserialize<'a>(str, options)
390 # type Letter = A | B
391 # let a = {| Hello = Some "World"; Letter = A |}
392 # if a |> Json.serialize |> Json.deserialize |> (=) a
398 #pypy2NoLibs = expectSuccess (writePyPy2 "test-writers-pypy2-no-libs" {} ''
402 python3NoLibs = expectSuccess (
403 writePython3 "test-writers-python3-no-libs" { } ''
408 pypy3NoLibs = expectSuccess (
409 writePyPy3 "test-writers-pypy3-no-libs" { } ''
414 fsharpNoNugetDeps = expectSuccess (
415 writeFSharp "test-writers-fsharp-no-nuget-deps" ''
420 luaNoLibs = expectSuccess (
421 writeLua "test-writers-lua-no-libs" { } ''
426 rubyNoLibs = expectSuccess (
427 writeRuby "test-writers-ruby-no-libs" { } ''
433 path = recurseIntoAttrs {
434 bash = expectSuccess (
435 writeBash "test-writers-bash-path" (
437 if [[ "test" == "test" ]]; then echo "success"; fi
442 haskell = expectSuccess (
443 writeHaskell "test-writers-haskell-path" { libraries = [ haskellPackages.acme-default ]; } (
452 18871 -> putStrLn $ id "success"
460 json = expectDataEqual {
461 file = writeJSON "data.json" { hello = "world"; };
469 toml = expectDataEqual {
470 file = writeTOML "data.toml" { hello = "world"; };
476 yaml = expectDataEqual {
477 file = writeYAML "data.yaml" { hello = "world"; };
478 expected = "hello: world\n";
482 wrapping = recurseIntoAttrs {
483 bash-bin = expectSuccessBin (
484 writeBashBin "test-writers-wrapping-bash-bin"
493 if [[ "$ThaigerSprint" == "Thailand" ]]; then
499 bash = expectSuccess (
500 writeBash "test-writers-wrapping-bash"
509 if [[ "$ThaigerSprint" == "Thailand" ]]; then
515 babashka-bin = expectSuccessBin (
516 writeBabashkaBin "test-writers-wrapping-babashka-bin"
525 (when (= (System/getenv "ThaigerSprint") "Thailand")
530 babashka = expectSuccess (
531 writeBabashka "test-writers-wrapping-babashka"
540 (when (= (System/getenv "ThaigerSprint") "Thailand")
545 nim = expectSuccess (
546 writeNim "test-writers-wrapping-nim"
557 if getEnv("ThaigerSprint") == "Thailand":
562 python = expectSuccess (
563 writePython3 "test-writers-wrapping-python"
574 if os.environ.get("ThaigerSprint") == "Thailand":
579 rust = expectSuccess (
580 writeRust "test-writers-wrapping-rust"
590 if std::env::var("ThaigerSprint").unwrap() == "Thailand" {
599 bin = writeBashBin "bin" { makeWrapperArgs = [ ]; } ''true'';
601 runCommand "run-test-writers-wrapping-no-empty-wrapper" { } ''
603 if [ $(ls -A ${bin}/bin | wc -l) -eq 1 ]; then
606 echo "Error: Empty wrapper was created" >&2