2021-03-04 17:37:30 +00:00
|
|
|
{ glib
|
|
|
|
, haskellPackages
|
|
|
|
, lib
|
|
|
|
, nodePackages
|
|
|
|
, perlPackages
|
|
|
|
, python2Packages
|
|
|
|
, python3Packages
|
|
|
|
, runCommand
|
|
|
|
, writers
|
|
|
|
, writeText
|
2019-10-21 22:20:46 +01:00
|
|
|
}:
|
2018-11-27 02:58:17 +00:00
|
|
|
with writers;
|
|
|
|
let
|
|
|
|
|
|
|
|
bin = {
|
|
|
|
bash = writeBashBin "test_writers" ''
|
|
|
|
if [[ "test" == "test" ]]; then echo "success"; fi
|
|
|
|
'';
|
|
|
|
|
|
|
|
c = writeCBin "test_writers" { libraries = [ ]; } ''
|
|
|
|
#include <stdio.h>
|
|
|
|
int main() {
|
|
|
|
printf("success\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
|
|
|
|
dash = writeDashBin "test_writers" ''
|
|
|
|
test '~' = '~' && echo 'success'
|
|
|
|
'';
|
|
|
|
|
2021-01-12 10:03:08 +00:00
|
|
|
rust = writeRustBin "test_writers" {} ''
|
|
|
|
fn main(){
|
|
|
|
println!("success")
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
|
2018-11-27 02:58:17 +00:00
|
|
|
haskell = writeHaskellBin "test_writers" { libraries = [ haskellPackages.acme-default ]; } ''
|
|
|
|
import Data.Default
|
|
|
|
|
|
|
|
int :: Int
|
|
|
|
int = def
|
|
|
|
|
|
|
|
main :: IO ()
|
|
|
|
main = case int of
|
|
|
|
18871 -> putStrLn $ id "success"
|
|
|
|
_ -> print "fail"
|
|
|
|
'';
|
|
|
|
|
|
|
|
js = writeJSBin "test_writers" { libraries = [ nodePackages.semver ]; } ''
|
|
|
|
var semver = require('semver');
|
|
|
|
|
|
|
|
if (semver.valid('1.2.3')) {
|
|
|
|
console.log('success')
|
|
|
|
} else {
|
|
|
|
console.log('fail')
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
|
|
|
|
perl = writePerlBin "test_writers" { libraries = [ perlPackages.boolean ]; } ''
|
|
|
|
use boolean;
|
|
|
|
print "success\n" if true;
|
|
|
|
'';
|
|
|
|
|
|
|
|
python2 = writePython2Bin "test_writers" { libraries = [ python2Packages.enum ]; } ''
|
|
|
|
from enum import Enum
|
|
|
|
|
2019-10-21 22:20:25 +01:00
|
|
|
|
2018-11-27 02:58:17 +00:00
|
|
|
class Test(Enum):
|
|
|
|
a = "success"
|
|
|
|
|
2019-10-21 22:20:25 +01:00
|
|
|
|
2018-11-27 02:58:17 +00:00
|
|
|
print Test.a
|
|
|
|
'';
|
|
|
|
|
|
|
|
python3 = writePython3Bin "test_writers" { libraries = [ python3Packages.pyyaml ]; } ''
|
|
|
|
import yaml
|
|
|
|
|
|
|
|
y = yaml.load("""
|
|
|
|
- test: success
|
|
|
|
""")
|
|
|
|
print(y[0]['test'])
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
simple = {
|
|
|
|
bash = writeBash "test_bash" ''
|
|
|
|
if [[ "test" == "test" ]]; then echo "success"; fi
|
|
|
|
'';
|
|
|
|
|
2019-10-21 22:20:46 +01:00
|
|
|
c = writeC "test_c" { libraries = [ glib.dev ]; } ''
|
|
|
|
#include <gio/gio.h>
|
2018-11-27 02:58:17 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
int main() {
|
2019-10-21 22:20:46 +01:00
|
|
|
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 02:58:17 +00:00
|
|
|
printf("success\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
|
|
|
|
dash = writeDash "test_dash" ''
|
|
|
|
test '~' = '~' && echo 'success'
|
|
|
|
'';
|
|
|
|
|
|
|
|
haskell = writeHaskell "test_haskell" { libraries = [ haskellPackages.acme-default ]; } ''
|
|
|
|
import Data.Default
|
|
|
|
|
|
|
|
int :: Int
|
|
|
|
int = def
|
|
|
|
|
|
|
|
main :: IO ()
|
|
|
|
main = case int of
|
|
|
|
18871 -> putStrLn $ id "success"
|
|
|
|
_ -> print "fail"
|
|
|
|
'';
|
|
|
|
|
|
|
|
js = writeJS "test_js" { libraries = [ nodePackages.semver ]; } ''
|
|
|
|
var semver = require('semver');
|
|
|
|
|
|
|
|
if (semver.valid('1.2.3')) {
|
|
|
|
console.log('success')
|
|
|
|
} else {
|
|
|
|
console.log('fail')
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
|
|
|
|
perl = writePerl "test_perl" { libraries = [ perlPackages.boolean ]; } ''
|
|
|
|
use boolean;
|
|
|
|
print "success\n" if true;
|
|
|
|
'';
|
|
|
|
|
|
|
|
python2 = writePython2 "test_python2" { libraries = [ python2Packages.enum ]; } ''
|
|
|
|
from enum import Enum
|
|
|
|
|
2019-10-21 22:20:25 +01:00
|
|
|
|
2018-11-27 02:58:17 +00:00
|
|
|
class Test(Enum):
|
|
|
|
a = "success"
|
|
|
|
|
2019-10-21 22:20:25 +01:00
|
|
|
|
2018-11-27 02:58:17 +00:00
|
|
|
print Test.a
|
|
|
|
'';
|
|
|
|
|
|
|
|
python3 = writePython3 "test_python3" { libraries = [ python3Packages.pyyaml ]; } ''
|
|
|
|
import yaml
|
|
|
|
|
|
|
|
y = yaml.load("""
|
|
|
|
- test: success
|
|
|
|
""")
|
|
|
|
print(y[0]['test'])
|
|
|
|
'';
|
2020-07-24 11:31:01 +01:00
|
|
|
|
|
|
|
python2NoLibs = writePython2 "test_python2_no_libs" {} ''
|
|
|
|
print("success")
|
|
|
|
'';
|
|
|
|
|
|
|
|
python3NoLibs = writePython3 "test_python3_no_libs" {} ''
|
|
|
|
print("success")
|
|
|
|
'';
|
2018-11-27 02:58:17 +00:00
|
|
|
};
|
|
|
|
|
2018-12-01 23:56:16 +00:00
|
|
|
|
|
|
|
path = {
|
|
|
|
bash = writeBash "test_bash" (writeText "test" ''
|
|
|
|
if [[ "test" == "test" ]]; then echo "success"; fi
|
|
|
|
'');
|
|
|
|
haskell = writeHaskell "test_haskell" { 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"
|
|
|
|
'');
|
|
|
|
};
|
|
|
|
|
2018-11-27 02:58:17 +00:00
|
|
|
writeTest = expectedValue: test:
|
|
|
|
writeDash "test-writers" ''
|
|
|
|
if test "$(${test})" != "${expectedValue}"; then
|
|
|
|
echo 'test ${test} failed'
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
|
|
|
in runCommand "test-writers" {
|
|
|
|
passthru = { inherit writeTest bin simple; };
|
2021-01-24 00:40:18 +00:00
|
|
|
meta.platforms = lib.platforms.all;
|
2018-11-27 02:58:17 +00:00
|
|
|
} ''
|
|
|
|
${lib.concatMapStringsSep "\n" (test: writeTest "success" "${test}/bin/test_writers") (lib.attrValues bin)}
|
2019-09-09 00:38:31 +01:00
|
|
|
${lib.concatMapStringsSep "\n" (test: writeTest "success" test) (lib.attrValues simple)}
|
|
|
|
${lib.concatMapStringsSep "\n" (test: writeTest "success" test) (lib.attrValues path)}
|
2018-11-27 02:58:17 +00:00
|
|
|
|
|
|
|
echo 'nix-writers successfully tested' >&2
|
|
|
|
touch $out
|
|
|
|
''
|
|
|
|
|