2021-03-04 18:37:30 +01:00
|
|
|
{ glib
|
|
|
|
, haskellPackages
|
|
|
|
, lib
|
|
|
|
, nodePackages
|
|
|
|
, perlPackages
|
2021-12-11 14:02:38 +01:00
|
|
|
, pypy2Packages
|
2021-03-04 18:37:30 +01:00
|
|
|
, python3Packages
|
2021-12-11 14:02:38 +01:00
|
|
|
, pypy3Packages
|
2021-03-04 18:37:30 +01:00
|
|
|
, runCommand
|
|
|
|
, writers
|
|
|
|
, writeText
|
2019-10-21 23:20:46 +02:00
|
|
|
}:
|
2018-11-27 03:58:17 +01:00
|
|
|
with writers;
|
|
|
|
let
|
|
|
|
|
|
|
|
bin = {
|
2021-06-08 12:38:25 +02:00
|
|
|
bash = writeBashBin "test-writers-bash-bin" ''
|
2018-11-27 03:58:17 +01:00
|
|
|
if [[ "test" == "test" ]]; then echo "success"; fi
|
|
|
|
'';
|
|
|
|
|
2021-06-08 12:38:25 +02:00
|
|
|
dash = writeDashBin "test-writers-dash-bin" ''
|
2018-11-27 03:58:17 +01:00
|
|
|
test '~' = '~' && echo 'success'
|
|
|
|
'';
|
|
|
|
|
2022-10-10 15:58:42 +02:00
|
|
|
fish = writeFishBin "test-writers-fish-bin" ''
|
|
|
|
if test "test" = "test"
|
|
|
|
echo "success"
|
|
|
|
end
|
|
|
|
'';
|
|
|
|
|
2021-06-08 12:38:25 +02:00
|
|
|
rust = writeRustBin "test-writers-rust-bin" {} ''
|
2021-01-12 11:03:08 +01:00
|
|
|
fn main(){
|
|
|
|
println!("success")
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
|
2021-06-08 12:38:25 +02:00
|
|
|
haskell = writeHaskellBin "test-writers-haskell-bin" { libraries = [ haskellPackages.acme-default ]; } ''
|
2018-11-27 03:58:17 +01:00
|
|
|
import Data.Default
|
|
|
|
|
|
|
|
int :: Int
|
|
|
|
int = def
|
|
|
|
|
|
|
|
main :: IO ()
|
|
|
|
main = case int of
|
|
|
|
18871 -> putStrLn $ id "success"
|
|
|
|
_ -> print "fail"
|
|
|
|
'';
|
|
|
|
|
2021-06-08 12:38:25 +02:00
|
|
|
js = writeJSBin "test-writers-js-bin" { libraries = [ nodePackages.semver ]; } ''
|
2018-11-27 03:58:17 +01:00
|
|
|
var semver = require('semver');
|
|
|
|
|
|
|
|
if (semver.valid('1.2.3')) {
|
|
|
|
console.log('success')
|
|
|
|
} else {
|
|
|
|
console.log('fail')
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
|
2021-06-08 12:38:25 +02:00
|
|
|
perl = writePerlBin "test-writers-perl-bin" { libraries = [ perlPackages.boolean ]; } ''
|
2018-11-27 03:58:17 +01:00
|
|
|
use boolean;
|
|
|
|
print "success\n" if true;
|
|
|
|
'';
|
|
|
|
|
2021-12-11 14:02:38 +01:00
|
|
|
pypy2 = writePyPy2Bin "test-writers-pypy2-bin" { libraries = [ pypy2Packages.enum ]; } ''
|
|
|
|
from enum import Enum
|
|
|
|
|
|
|
|
|
|
|
|
class Test(Enum):
|
|
|
|
a = "success"
|
|
|
|
|
|
|
|
|
|
|
|
print Test.a
|
|
|
|
'';
|
|
|
|
|
2021-06-08 12:38:25 +02:00
|
|
|
python3 = writePython3Bin "test-writers-python3-bin" { libraries = [ python3Packages.pyyaml ]; } ''
|
2018-11-27 03:58:17 +01:00
|
|
|
import yaml
|
|
|
|
|
|
|
|
y = yaml.load("""
|
|
|
|
- test: success
|
|
|
|
""")
|
|
|
|
print(y[0]['test'])
|
|
|
|
'';
|
2021-12-11 14:02:38 +01:00
|
|
|
|
|
|
|
pypy3 = writePyPy3Bin "test-writers-pypy3-bin" { libraries = [ pypy3Packages.pyyaml ]; } ''
|
|
|
|
import yaml
|
|
|
|
|
|
|
|
y = yaml.load("""
|
|
|
|
- test: success
|
|
|
|
""")
|
|
|
|
print(y[0]['test'])
|
|
|
|
'';
|
2018-11-27 03:58:17 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
simple = {
|
2021-06-08 12:38:25 +02:00
|
|
|
bash = writeBash "test-writers-bash" ''
|
2018-11-27 03:58:17 +01:00
|
|
|
if [[ "test" == "test" ]]; then echo "success"; fi
|
|
|
|
'';
|
|
|
|
|
2021-06-08 12:38:25 +02:00
|
|
|
dash = writeDash "test-writers-dash" ''
|
2018-11-27 03:58:17 +01:00
|
|
|
test '~' = '~' && echo 'success'
|
|
|
|
'';
|
|
|
|
|
2022-10-10 15:58:42 +02:00
|
|
|
fish = writeFish "test-writers-fish" ''
|
|
|
|
if test "test" = "test"
|
|
|
|
echo "success"
|
|
|
|
end
|
|
|
|
'';
|
|
|
|
|
2021-06-08 12:38:25 +02:00
|
|
|
haskell = writeHaskell "test-writers-haskell" { libraries = [ haskellPackages.acme-default ]; } ''
|
2018-11-27 03:58:17 +01:00
|
|
|
import Data.Default
|
|
|
|
|
|
|
|
int :: Int
|
|
|
|
int = def
|
|
|
|
|
|
|
|
main :: IO ()
|
|
|
|
main = case int of
|
|
|
|
18871 -> putStrLn $ id "success"
|
|
|
|
_ -> print "fail"
|
|
|
|
'';
|
|
|
|
|
2021-06-08 12:38:25 +02:00
|
|
|
js = writeJS "test-writers-js" { libraries = [ nodePackages.semver ]; } ''
|
2018-11-27 03:58:17 +01:00
|
|
|
var semver = require('semver');
|
|
|
|
|
|
|
|
if (semver.valid('1.2.3')) {
|
|
|
|
console.log('success')
|
|
|
|
} else {
|
|
|
|
console.log('fail')
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
|
2021-06-08 12:38:25 +02:00
|
|
|
perl = writePerl "test-writers-perl" { libraries = [ perlPackages.boolean ]; } ''
|
2018-11-27 03:58:17 +01:00
|
|
|
use boolean;
|
|
|
|
print "success\n" if true;
|
|
|
|
'';
|
|
|
|
|
2021-12-11 14:02:38 +01:00
|
|
|
pypy2 = writePyPy2 "test-writers-pypy2" { libraries = [ pypy2Packages.enum ]; } ''
|
|
|
|
from enum import Enum
|
|
|
|
|
|
|
|
|
|
|
|
class Test(Enum):
|
|
|
|
a = "success"
|
|
|
|
|
|
|
|
|
|
|
|
print Test.a
|
|
|
|
'';
|
|
|
|
|
2021-06-08 12:38:25 +02:00
|
|
|
python3 = writePython3 "test-writers-python3" { libraries = [ python3Packages.pyyaml ]; } ''
|
2018-11-27 03:58:17 +01:00
|
|
|
import yaml
|
|
|
|
|
|
|
|
y = yaml.load("""
|
|
|
|
- test: success
|
|
|
|
""")
|
|
|
|
print(y[0]['test'])
|
|
|
|
'';
|
2020-07-24 12:31:01 +02:00
|
|
|
|
2021-12-11 14:02:38 +01:00
|
|
|
pypy3 = writePyPy3 "test-writers-pypy3" { libraries = [ pypy3Packages.pyyaml ]; } ''
|
|
|
|
import yaml
|
|
|
|
|
|
|
|
y = yaml.load("""
|
|
|
|
- test: success
|
|
|
|
""")
|
|
|
|
print(y[0]['test'])
|
|
|
|
'';
|
|
|
|
|
2022-02-28 23:40:43 +01:00
|
|
|
fsharp = makeFSharpWriter {
|
|
|
|
libraries = { fetchNuGet }: [
|
|
|
|
(fetchNuGet { pname = "FSharp.SystemTextJson"; version = "0.17.4"; sha256 = "1bplzc9ybdqspii4q28l8gmfvzpkmgq5l1hlsiyg2h46w881lwg2"; })
|
|
|
|
];
|
|
|
|
} "test-writers-fsharp" ''
|
|
|
|
#r "nuget: FSharp.SystemTextJson, 0.17.4"
|
|
|
|
|
|
|
|
module Json =
|
|
|
|
open System.Text.Json
|
|
|
|
open System.Text.Json.Serialization
|
|
|
|
let options = JsonSerializerOptions()
|
|
|
|
options.Converters.Add(JsonFSharpConverter())
|
|
|
|
let serialize<'a> (o: 'a) = JsonSerializer.Serialize<'a>(o, options)
|
|
|
|
let deserialize<'a> (str: string) = JsonSerializer.Deserialize<'a>(str, options)
|
|
|
|
|
|
|
|
type Letter = A | B
|
|
|
|
let a = {| Hello = Some "World"; Letter = A |}
|
|
|
|
if a |> Json.serialize |> Json.deserialize |> (=) a
|
|
|
|
then "success"
|
|
|
|
else "failed"
|
|
|
|
|> printfn "%s"
|
|
|
|
'';
|
|
|
|
|
2021-12-11 14:02:38 +01:00
|
|
|
pypy2NoLibs = writePyPy2 "test-writers-pypy2-no-libs" {} ''
|
|
|
|
print("success")
|
|
|
|
'';
|
|
|
|
|
2021-06-08 12:38:25 +02:00
|
|
|
python3NoLibs = writePython3 "test-writers-python3-no-libs" {} ''
|
2020-07-24 12:31:01 +02:00
|
|
|
print("success")
|
|
|
|
'';
|
2021-12-11 14:02:38 +01:00
|
|
|
|
|
|
|
pypy3NoLibs = writePyPy3 "test-writers-pypy3-no-libs" {} ''
|
|
|
|
print("success")
|
|
|
|
'';
|
2022-02-28 23:40:43 +01:00
|
|
|
|
|
|
|
fsharpNoNugetDeps = writeFSharp "test-writers-fsharp-no-nuget-deps" ''
|
|
|
|
printfn "success"
|
|
|
|
'';
|
2018-11-27 03:58:17 +01:00
|
|
|
};
|
|
|
|
|
2018-12-02 00:56:16 +01:00
|
|
|
|
|
|
|
path = {
|
2021-06-08 12:38:25 +02:00
|
|
|
bash = writeBash "test-writers-bash-path" (writeText "test" ''
|
2018-12-02 00:56:16 +01:00
|
|
|
if [[ "test" == "test" ]]; then echo "success"; fi
|
|
|
|
'');
|
2021-06-08 12:38:25 +02:00
|
|
|
haskell = writeHaskell "test-writers-haskell-path" { libraries = [ haskellPackages.acme-default ]; } (writeText "test" ''
|
2018-12-02 00:56:16 +01:00
|
|
|
import Data.Default
|
|
|
|
|
|
|
|
int :: Int
|
|
|
|
int = def
|
|
|
|
|
|
|
|
main :: IO ()
|
|
|
|
main = case int of
|
|
|
|
18871 -> putStrLn $ id "success"
|
|
|
|
_ -> print "fail"
|
|
|
|
'');
|
|
|
|
};
|
|
|
|
|
2021-06-08 11:36:09 +02:00
|
|
|
writeTest = expectedValue: name: test:
|
|
|
|
writeDash "run-${name}" ''
|
2018-11-27 03:58:17 +01:00
|
|
|
if test "$(${test})" != "${expectedValue}"; then
|
|
|
|
echo 'test ${test} failed'
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
|
|
|
in runCommand "test-writers" {
|
2021-07-13 15:22:34 +02:00
|
|
|
passthru = { inherit writeTest bin simple path; };
|
2021-01-24 01:40:18 +01:00
|
|
|
meta.platforms = lib.platforms.all;
|
2018-11-27 03:58:17 +01:00
|
|
|
} ''
|
2021-06-08 11:36:09 +02:00
|
|
|
${lib.concatMapStringsSep "\n" (test: writeTest "success" test.name "${test}/bin/${test.name}") (lib.attrValues bin)}
|
|
|
|
${lib.concatMapStringsSep "\n" (test: writeTest "success" test.name test) (lib.attrValues simple)}
|
|
|
|
${lib.concatMapStringsSep "\n" (test: writeTest "success" test.name test) (lib.attrValues path)}
|
2018-11-27 03:58:17 +01:00
|
|
|
|
|
|
|
echo 'nix-writers successfully tested' >&2
|
|
|
|
touch $out
|
|
|
|
''
|
|
|
|
|