blob: d7c347a559ef4c70aa2f3d9304d4dbde372647d7 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
{ stdenv, lib, runCommand, haskellPackages, nodePackages, perlPackages, python2Packages, python3Packages, writers, writeText }:
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'
'';
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
class Test(Enum):
a = "success"
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
'';
c = writeC "test_c" { libraries = [ ]; } ''
#include <stdio.h>
int main() {
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
class Test(Enum):
a = "success"
print Test.a
'';
python3 = writePython3 "test_python3" { libraries = [ python3Packages.pyyaml ]; } ''
import yaml
y = yaml.load("""
- test: success
""")
print(y[0]['test'])
'';
};
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"
'');
};
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; };
meta.platforms = stdenv.lib.platforms.all;
} ''
${lib.concatMapStringsSep "\n" (test: writeTest "success" "${test}/bin/test_writers") (lib.attrValues bin)}
${lib.concatMapStringsSep "\n" (test: writeTest "success" test) (lib.attrValues simple)}
${lib.concatMapStringsSep "\n" (test: writeTest "success" test) (lib.attrValues path)}
echo 'nix-writers successfully tested' >&2
touch $out
''
|