2021-03-04 17:37:30 +00:00
|
|
|
{ glib
|
|
|
|
, haskellPackages
|
|
|
|
, lib
|
|
|
|
, nodePackages
|
|
|
|
, perlPackages
|
2021-12-11 13:02:38 +00:00
|
|
|
, pypy2Packages
|
2021-03-04 17:37:30 +00:00
|
|
|
, python3Packages
|
2021-12-11 13:02:38 +00:00
|
|
|
, pypy3Packages
|
2021-03-04 17:37:30 +00:00
|
|
|
, runCommand
|
|
|
|
, writers
|
|
|
|
, writeText
|
2019-10-21 21:20:46 +00:00
|
|
|
}:
|
2018-11-27 02:58:17 +00:00
|
|
|
with writers;
|
|
|
|
let
|
2023-07-22 11:38:31 +00:00
|
|
|
expectSuccess = test:
|
|
|
|
runCommand "run-${test.name}" {} ''
|
2023-07-22 09:14:51 +00:00
|
|
|
if [[ "$(${test})" != success ]]; then
|
2023-07-22 11:38:31 +00:00
|
|
|
echo 'test ${test.name} failed'
|
|
|
|
exit 1
|
|
|
|
fi
|
2018-11-27 02:58:17 +00:00
|
|
|
|
2023-07-22 11:38:31 +00:00
|
|
|
touch $out
|
2018-11-27 02:58:17 +00:00
|
|
|
'';
|
|
|
|
|
2023-07-22 11:38:31 +00:00
|
|
|
expectSuccessBin = test:
|
|
|
|
runCommand "run-${test.name}" {} ''
|
2023-07-22 09:14:51 +00:00
|
|
|
if [[ "$(${lib.getExe test})" != success ]]; then
|
2023-07-22 11:38:31 +00:00
|
|
|
echo 'test ${test.name} failed'
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-07-22 09:14:51 +00:00
|
|
|
touch $out
|
|
|
|
'';
|
|
|
|
|
|
|
|
expectDataEqual = { file, expected }:
|
|
|
|
let
|
|
|
|
expectedFile = writeText "${file.name}-expected" expected;
|
|
|
|
in
|
|
|
|
runCommand "run-${file.name}" {} ''
|
|
|
|
if ! diff -u ${file} ${expectedFile}; then
|
|
|
|
echo 'test ${file.name} failed'
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-07-22 11:38:31 +00:00
|
|
|
touch $out
|
2018-11-27 02:58:17 +00:00
|
|
|
'';
|
2023-07-22 11:38:31 +00:00
|
|
|
in
|
|
|
|
lib.recurseIntoAttrs {
|
|
|
|
bin = lib.recurseIntoAttrs {
|
|
|
|
bash = expectSuccessBin (writeBashBin "test-writers-bash-bin" ''
|
|
|
|
if [[ "test" == "test" ]]; then echo "success"; fi
|
|
|
|
'');
|
2018-11-27 02:58:17 +00:00
|
|
|
|
2023-07-22 11:38:31 +00:00
|
|
|
dash = expectSuccessBin (writeDashBin "test-writers-dash-bin" ''
|
|
|
|
test '~' = '~' && echo 'success'
|
|
|
|
'');
|
|
|
|
|
|
|
|
fish = expectSuccessBin (writeFishBin "test-writers-fish-bin" ''
|
2022-10-10 13:58:42 +00:00
|
|
|
if test "test" = "test"
|
|
|
|
echo "success"
|
|
|
|
end
|
2023-07-22 11:38:31 +00:00
|
|
|
'');
|
2022-10-10 13:58:42 +00:00
|
|
|
|
2023-07-22 11:38:31 +00:00
|
|
|
rust = expectSuccessBin (writeRustBin "test-writers-rust-bin" {} ''
|
2021-01-12 10:03:08 +00:00
|
|
|
fn main(){
|
|
|
|
println!("success")
|
|
|
|
}
|
2023-07-22 11:38:31 +00:00
|
|
|
'');
|
2021-01-12 10:03:08 +00:00
|
|
|
|
2023-07-22 11:38:31 +00:00
|
|
|
haskell = expectSuccessBin (writeHaskellBin "test-writers-haskell-bin" { libraries = [ haskellPackages.acme-default ]; } ''
|
2018-11-27 02:58:17 +00:00
|
|
|
import Data.Default
|
|
|
|
|
|
|
|
int :: Int
|
|
|
|
int = def
|
|
|
|
|
|
|
|
main :: IO ()
|
|
|
|
main = case int of
|
|
|
|
18871 -> putStrLn $ id "success"
|
|
|
|
_ -> print "fail"
|
2023-07-22 11:38:31 +00:00
|
|
|
'');
|
2018-11-27 02:58:17 +00:00
|
|
|
|
2023-07-22 11:38:31 +00:00
|
|
|
js = expectSuccessBin (writeJSBin "test-writers-js-bin" { libraries = [ nodePackages.semver ]; } ''
|
2018-11-27 02:58:17 +00:00
|
|
|
var semver = require('semver');
|
|
|
|
|
|
|
|
if (semver.valid('1.2.3')) {
|
|
|
|
console.log('success')
|
|
|
|
} else {
|
|
|
|
console.log('fail')
|
|
|
|
}
|
2023-07-22 11:38:31 +00:00
|
|
|
'');
|
2018-11-27 02:58:17 +00:00
|
|
|
|
2023-07-22 11:38:31 +00:00
|
|
|
perl = expectSuccessBin (writePerlBin "test-writers-perl-bin" { libraries = [ perlPackages.boolean ]; } ''
|
2018-11-27 02:58:17 +00:00
|
|
|
use boolean;
|
|
|
|
print "success\n" if true;
|
2023-07-22 11:38:31 +00:00
|
|
|
'');
|
2018-11-27 02:58:17 +00:00
|
|
|
|
2023-07-22 11:38:31 +00:00
|
|
|
pypy2 = expectSuccessBin (writePyPy2Bin "test-writers-pypy2-bin" { libraries = [ pypy2Packages.enum ]; } ''
|
2021-12-11 13:02:38 +00:00
|
|
|
from enum import Enum
|
|
|
|
|
|
|
|
class Test(Enum):
|
|
|
|
a = "success"
|
|
|
|
|
|
|
|
print Test.a
|
2023-07-22 11:38:31 +00:00
|
|
|
'');
|
2021-12-11 13:02:38 +00:00
|
|
|
|
2023-07-22 11:38:31 +00:00
|
|
|
python3 = expectSuccessBin (writePython3Bin "test-writers-python3-bin" { libraries = [ python3Packages.pyyaml ]; } ''
|
2018-11-27 02:58:17 +00:00
|
|
|
import yaml
|
|
|
|
|
2023-07-22 11:38:31 +00:00
|
|
|
y = yaml.safe_load("""
|
2018-11-27 02:58:17 +00:00
|
|
|
- test: success
|
|
|
|
""")
|
|
|
|
print(y[0]['test'])
|
2023-07-22 11:38:31 +00:00
|
|
|
'');
|
2021-12-11 13:02:38 +00:00
|
|
|
|
2023-07-22 11:38:31 +00:00
|
|
|
pypy3 = expectSuccessBin (writePyPy3Bin "test-writers-pypy3-bin" { libraries = [ pypy3Packages.pyyaml ]; } ''
|
2021-12-11 13:02:38 +00:00
|
|
|
import yaml
|
|
|
|
|
2023-07-22 11:38:31 +00:00
|
|
|
y = yaml.safe_load("""
|
2021-12-11 13:02:38 +00:00
|
|
|
- test: success
|
|
|
|
""")
|
|
|
|
print(y[0]['test'])
|
2023-07-22 11:38:31 +00:00
|
|
|
'');
|
2018-11-27 02:58:17 +00:00
|
|
|
};
|
|
|
|
|
2023-07-22 11:38:31 +00:00
|
|
|
simple = lib.recurseIntoAttrs {
|
|
|
|
bash = expectSuccess (writeBash "test-writers-bash" ''
|
2018-11-27 02:58:17 +00:00
|
|
|
if [[ "test" == "test" ]]; then echo "success"; fi
|
2023-07-22 11:38:31 +00:00
|
|
|
'');
|
2018-11-27 02:58:17 +00:00
|
|
|
|
2023-07-22 11:38:31 +00:00
|
|
|
dash = expectSuccess (writeDash "test-writers-dash" ''
|
2018-11-27 02:58:17 +00:00
|
|
|
test '~' = '~' && echo 'success'
|
2023-07-22 11:38:31 +00:00
|
|
|
'');
|
2018-11-27 02:58:17 +00:00
|
|
|
|
2023-07-22 11:38:31 +00:00
|
|
|
fish = expectSuccess (writeFish "test-writers-fish" ''
|
2022-10-10 13:58:42 +00:00
|
|
|
if test "test" = "test"
|
|
|
|
echo "success"
|
|
|
|
end
|
2023-07-22 11:38:31 +00:00
|
|
|
'');
|
2022-10-10 13:58:42 +00:00
|
|
|
|
2023-07-22 11:38:31 +00:00
|
|
|
haskell = expectSuccess (writeHaskell "test-writers-haskell" { libraries = [ haskellPackages.acme-default ]; } ''
|
2018-11-27 02:58:17 +00:00
|
|
|
import Data.Default
|
|
|
|
|
|
|
|
int :: Int
|
|
|
|
int = def
|
|
|
|
|
|
|
|
main :: IO ()
|
|
|
|
main = case int of
|
|
|
|
18871 -> putStrLn $ id "success"
|
|
|
|
_ -> print "fail"
|
2023-07-22 11:38:31 +00:00
|
|
|
'');
|
2018-11-27 02:58:17 +00:00
|
|
|
|
2023-07-22 11:38:31 +00:00
|
|
|
js = expectSuccess (writeJS "test-writers-js" { libraries = [ nodePackages.semver ]; } ''
|
2018-11-27 02:58:17 +00:00
|
|
|
var semver = require('semver');
|
|
|
|
|
|
|
|
if (semver.valid('1.2.3')) {
|
|
|
|
console.log('success')
|
|
|
|
} else {
|
|
|
|
console.log('fail')
|
|
|
|
}
|
2023-07-22 11:38:31 +00:00
|
|
|
'');
|
2018-11-27 02:58:17 +00:00
|
|
|
|
2023-07-22 11:38:31 +00:00
|
|
|
perl = expectSuccess (writePerl "test-writers-perl" { libraries = [ perlPackages.boolean ]; } ''
|
2018-11-27 02:58:17 +00:00
|
|
|
use boolean;
|
|
|
|
print "success\n" if true;
|
2023-07-22 11:38:31 +00:00
|
|
|
'');
|
2018-11-27 02:58:17 +00:00
|
|
|
|
2023-07-22 11:38:31 +00:00
|
|
|
pypy2 = expectSuccess (writePyPy2 "test-writers-pypy2" { libraries = [ pypy2Packages.enum ]; } ''
|
2021-12-11 13:02:38 +00:00
|
|
|
from enum import Enum
|
|
|
|
|
|
|
|
class Test(Enum):
|
|
|
|
a = "success"
|
|
|
|
|
|
|
|
print Test.a
|
2023-07-22 11:38:31 +00:00
|
|
|
'');
|
2021-12-11 13:02:38 +00:00
|
|
|
|
2023-07-22 11:38:31 +00:00
|
|
|
python3 = expectSuccess (writePython3 "test-writers-python3" { libraries = [ python3Packages.pyyaml ]; } ''
|
2018-11-27 02:58:17 +00:00
|
|
|
import yaml
|
|
|
|
|
2023-07-22 11:38:31 +00:00
|
|
|
y = yaml.safe_load("""
|
2018-11-27 02:58:17 +00:00
|
|
|
- test: success
|
|
|
|
""")
|
|
|
|
print(y[0]['test'])
|
2023-07-22 11:38:31 +00:00
|
|
|
'');
|
2020-07-24 10:31:01 +00:00
|
|
|
|
2023-07-22 11:38:31 +00:00
|
|
|
pypy3 = expectSuccess (writePyPy3 "test-writers-pypy3" { libraries = [ pypy3Packages.pyyaml ]; } ''
|
2021-12-11 13:02:38 +00:00
|
|
|
import yaml
|
|
|
|
|
2023-07-22 11:38:31 +00:00
|
|
|
y = yaml.safe_load("""
|
2021-12-11 13:02:38 +00:00
|
|
|
- test: success
|
|
|
|
""")
|
|
|
|
print(y[0]['test'])
|
2023-07-22 11:38:31 +00:00
|
|
|
'');
|
2021-12-11 13:02:38 +00:00
|
|
|
|
2023-07-22 11:38:31 +00:00
|
|
|
fsharp = expectSuccess (makeFSharpWriter {
|
2022-02-28 22:40:43 +00:00
|
|
|
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"
|
2023-07-22 11:38:31 +00:00
|
|
|
'');
|
2022-02-28 22:40:43 +00:00
|
|
|
|
2023-07-22 11:38:31 +00:00
|
|
|
pypy2NoLibs = expectSuccess (writePyPy2 "test-writers-pypy2-no-libs" {} ''
|
2021-12-11 13:02:38 +00:00
|
|
|
print("success")
|
2023-07-22 11:38:31 +00:00
|
|
|
'');
|
2021-12-11 13:02:38 +00:00
|
|
|
|
2023-07-22 11:38:31 +00:00
|
|
|
python3NoLibs = expectSuccess (writePython3 "test-writers-python3-no-libs" {} ''
|
2020-07-24 10:31:01 +00:00
|
|
|
print("success")
|
2023-07-22 11:38:31 +00:00
|
|
|
'');
|
2021-12-11 13:02:38 +00:00
|
|
|
|
2023-07-22 11:38:31 +00:00
|
|
|
pypy3NoLibs = expectSuccess (writePyPy3 "test-writers-pypy3-no-libs" {} ''
|
2021-12-11 13:02:38 +00:00
|
|
|
print("success")
|
2023-07-22 11:38:31 +00:00
|
|
|
'');
|
2022-02-28 22:40:43 +00:00
|
|
|
|
2023-07-22 11:38:31 +00:00
|
|
|
fsharpNoNugetDeps = expectSuccess (writeFSharp "test-writers-fsharp-no-nuget-deps" ''
|
2022-02-28 22:40:43 +00:00
|
|
|
printfn "success"
|
2023-07-22 11:38:31 +00:00
|
|
|
'');
|
2018-11-27 02:58:17 +00:00
|
|
|
};
|
|
|
|
|
2023-07-22 11:38:31 +00:00
|
|
|
path = lib.recurseIntoAttrs {
|
|
|
|
bash = expectSuccess (writeBash "test-writers-bash-path" (writeText "test" ''
|
2018-12-01 23:56:16 +00:00
|
|
|
if [[ "test" == "test" ]]; then echo "success"; fi
|
2023-07-22 11:38:31 +00:00
|
|
|
''));
|
|
|
|
|
|
|
|
haskell = expectSuccess (writeHaskell "test-writers-haskell-path" { libraries = [ haskellPackages.acme-default ]; } (writeText "test" ''
|
2018-12-01 23:56:16 +00:00
|
|
|
import Data.Default
|
|
|
|
|
|
|
|
int :: Int
|
|
|
|
int = def
|
|
|
|
|
|
|
|
main :: IO ()
|
|
|
|
main = case int of
|
|
|
|
18871 -> putStrLn $ id "success"
|
|
|
|
_ -> print "fail"
|
2023-07-22 11:38:31 +00:00
|
|
|
''));
|
2018-12-01 23:56:16 +00:00
|
|
|
};
|
2023-07-22 09:14:51 +00:00
|
|
|
|
|
|
|
data = {
|
|
|
|
json = expectDataEqual {
|
|
|
|
file = writeJSON "data.json" { hello = "world"; };
|
|
|
|
expected = ''
|
|
|
|
{
|
|
|
|
"hello": "world"
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
toml = expectDataEqual {
|
|
|
|
file = writeTOML "data.toml" { hello = "world"; };
|
|
|
|
expected = "hello = 'world'\n";
|
|
|
|
};
|
|
|
|
|
|
|
|
yaml = expectDataEqual {
|
|
|
|
file = writeYAML "data.yaml" { hello = "world"; };
|
|
|
|
expected = "hello: world\n";
|
|
|
|
};
|
|
|
|
};
|
2023-07-22 11:38:31 +00:00
|
|
|
}
|