nixpkgs-suyu/pkgs/build-support/writers/test.nix

207 lines
5.1 KiB
Nix
Raw Normal View History

2021-03-04 18:37:30 +01:00
{ glib
, haskellPackages
, lib
, nodePackages
, perlPackages
, python2Packages
, python3Packages
, runCommand
, writers
, writeText
}:
2018-11-27 03:58:17 +01:00
with writers;
let
bin = {
bash = writeBashBin "test-writers-bash-bin" ''
2018-11-27 03:58:17 +01:00
if [[ "test" == "test" ]]; then echo "success"; fi
'';
c = writeCBin "test-writers-c" { libraries = [ ]; } ''
2018-11-27 03:58:17 +01:00
#include <stdio.h>
int main() {
printf("success\n");
return 0;
}
'';
dash = writeDashBin "test-writers-dash-bin" ''
2018-11-27 03:58:17 +01:00
test '~' = '~' && echo 'success'
'';
rust = writeRustBin "test-writers-rust-bin" {} ''
2021-01-12 11:03:08 +01:00
fn main(){
println!("success")
}
'';
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"
'';
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')
}
'';
perl = writePerlBin "test-writers-perl-bin" { libraries = [ perlPackages.boolean ]; } ''
2018-11-27 03:58:17 +01:00
use boolean;
print "success\n" if true;
'';
python2 = writePython2Bin "test-writers-python2-bin" { libraries = [ python2Packages.enum ]; } ''
2018-11-27 03:58:17 +01:00
from enum import Enum
2018-11-27 03:58:17 +01:00
class Test(Enum):
a = "success"
2018-11-27 03:58:17 +01:00
print Test.a
'';
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'])
'';
};
simple = {
bash = writeBash "test-writers-bash" ''
2018-11-27 03:58:17 +01:00
if [[ "test" == "test" ]]; then echo "success"; fi
'';
c = writeC "test-writers-c" { libraries = [ glib.dev ]; } ''
#include <gio/gio.h>
2018-11-27 03:58:17 +01:00
#include <stdio.h>
int main() {
GApplication *application = g_application_new ("hello.world", G_APPLICATION_FLAGS_NONE);
g_application_register (application, NULL, NULL);
GNotification *notification = g_notification_new ("Hello world!");
g_notification_set_body (notification, "This is an example notification.");
GIcon *icon = g_themed_icon_new ("dialog-information");
g_notification_set_icon (notification, icon);
g_object_unref (icon);
g_object_unref (notification);
g_object_unref (application);
2018-11-27 03:58:17 +01:00
printf("success\n");
return 0;
}
'';
dash = writeDash "test-writers-dash" ''
2018-11-27 03:58:17 +01:00
test '~' = '~' && echo 'success'
'';
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"
'';
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')
}
'';
perl = writePerl "test-writers-perl" { libraries = [ perlPackages.boolean ]; } ''
2018-11-27 03:58:17 +01:00
use boolean;
print "success\n" if true;
'';
python2 = writePython2 "test-writers-python2" { libraries = [ python2Packages.enum ]; } ''
2018-11-27 03:58:17 +01:00
from enum import Enum
2018-11-27 03:58:17 +01:00
class Test(Enum):
a = "success"
2018-11-27 03:58:17 +01:00
print Test.a
'';
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'])
'';
python2NoLibs = writePython2 "test-writers-python2-no-libs" {} ''
print("success")
'';
python3NoLibs = writePython3 "test-writers-python3-no-libs" {} ''
print("success")
'';
2018-11-27 03:58:17 +01:00
};
path = {
bash = writeBash "test-writers-bash-path" (writeText "test" ''
if [[ "test" == "test" ]]; then echo "success"; fi
'');
haskell = writeHaskell "test-writers-haskell-path" { libraries = [ haskellPackages.acme-default ]; } (writeText "test" ''
import Data.Default
int :: Int
int = def
main :: IO ()
main = case int of
18871 -> putStrLn $ id "success"
_ -> print "fail"
'');
};
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" {
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
} ''
${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
''