1212} :
1313with writers ;
1414let
15+ expectSuccess = test :
16+ runCommand "run-${ test . name } " { } ''
17+ if test "$(${ test } )" != "success"; then
18+ echo 'test ${ test . name } failed'
19+ exit 1
20+ fi
1521
16- bin = {
17- bash = writeBashBin "test-writers-bash-bin" ''
18- if [[ "test" == "test" ]]; then echo "success"; fi
22+ touch $out
1923 '' ;
2024
21- dash = writeDashBin "test-writers-dash-bin" ''
22- test '~' = '~' && echo 'success'
25+ expectSuccessBin = test :
26+ runCommand "run-${ test . name } " { } ''
27+ if test "$(${ lib . getExe test } )" != "success"; then
28+ echo 'test ${ test . name } failed'
29+ exit 1
30+ fi
31+
32+ touch $out
2333 '' ;
34+ in
35+ lib . recurseIntoAttrs {
36+ bin = lib . recurseIntoAttrs {
37+ bash = expectSuccessBin ( writeBashBin "test-writers-bash-bin" ''
38+ if [[ "test" == "test" ]]; then echo "success"; fi
39+ '' ) ;
2440
25- fish = writeFishBin "test-writers-fish-bin" ''
41+ dash = expectSuccessBin ( writeDashBin "test-writers-dash-bin" ''
42+ test '~' = '~' && echo 'success'
43+ '' ) ;
44+
45+ fish = expectSuccessBin ( writeFishBin "test-writers-fish-bin" ''
2646 if test "test" = "test"
2747 echo "success"
2848 end
29- '' ;
49+ '' ) ;
3050
31- rust = writeRustBin "test-writers-rust-bin" { } ''
51+ rust = expectSuccessBin ( writeRustBin "test-writers-rust-bin" { } ''
3252 fn main(){
3353 println!("success")
3454 }
35- '' ;
55+ '' ) ;
3656
37- haskell = writeHaskellBin "test-writers-haskell-bin" { libraries = [ haskellPackages . acme-default ] ; } ''
57+ haskell = expectSuccessBin ( writeHaskellBin "test-writers-haskell-bin" { libraries = [ haskellPackages . acme-default ] ; } ''
3858 import Data.Default
3959
4060 int :: Int
4464 main = case int of
4565 18871 -> putStrLn $ id "success"
4666 _ -> print "fail"
47- '' ;
67+ '' ) ;
4868
49- js = writeJSBin "test-writers-js-bin" { libraries = [ nodePackages . semver ] ; } ''
69+ js = expectSuccessBin ( writeJSBin "test-writers-js-bin" { libraries = [ nodePackages . semver ] ; } ''
5070 var semver = require('semver');
5171
5272 if (semver.valid('1.2.3')) {
5373 console.log('success')
5474 } else {
5575 console.log('fail')
5676 }
57- '' ;
77+ '' ) ;
5878
59- perl = writePerlBin "test-writers-perl-bin" { libraries = [ perlPackages . boolean ] ; } ''
79+ perl = expectSuccessBin ( writePerlBin "test-writers-perl-bin" { libraries = [ perlPackages . boolean ] ; } ''
6080 use boolean;
6181 print "success\n" if true;
62- '' ;
82+ '' ) ;
6383
64- pypy2 = writePyPy2Bin "test-writers-pypy2-bin" { libraries = [ pypy2Packages . enum ] ; } ''
84+ pypy2 = expectSuccessBin ( writePyPy2Bin "test-writers-pypy2-bin" { libraries = [ pypy2Packages . enum ] ; } ''
6585 from enum import Enum
6686
67-
6887 class Test(Enum):
6988 a = "success"
7089
71-
7290 print Test.a
73- '' ;
91+ '' ) ;
7492
75- python3 = writePython3Bin "test-writers-python3-bin" { libraries = [ python3Packages . pyyaml ] ; } ''
93+ python3 = expectSuccessBin ( writePython3Bin "test-writers-python3-bin" { libraries = [ python3Packages . pyyaml ] ; } ''
7694 import yaml
7795
78- y = yaml.load ("""
96+ y = yaml.safe_load ("""
7997 - test: success
8098 """)
8199 print(y[0]['test'])
82- '' ;
100+ '' ) ;
83101
84- pypy3 = writePyPy3Bin "test-writers-pypy3-bin" { libraries = [ pypy3Packages . pyyaml ] ; } ''
102+ pypy3 = expectSuccessBin ( writePyPy3Bin "test-writers-pypy3-bin" { libraries = [ pypy3Packages . pyyaml ] ; } ''
85103 import yaml
86104
87- y = yaml.load ("""
105+ y = yaml.safe_load ("""
88106 - test: success
89107 """)
90108 print(y[0]['test'])
91- '' ;
109+ '' ) ;
92110 } ;
93111
94- simple = {
95- bash = writeBash "test-writers-bash" ''
112+ simple = lib . recurseIntoAttrs {
113+ bash = expectSuccess ( writeBash "test-writers-bash" ''
96114 if [[ "test" == "test" ]]; then echo "success"; fi
97- '' ;
115+ '' ) ;
98116
99- dash = writeDash "test-writers-dash" ''
117+ dash = expectSuccess ( writeDash "test-writers-dash" ''
100118 test '~' = '~' && echo 'success'
101- '' ;
119+ '' ) ;
102120
103- fish = writeFish "test-writers-fish" ''
121+ fish = expectSuccess ( writeFish "test-writers-fish" ''
104122 if test "test" = "test"
105123 echo "success"
106124 end
107- '' ;
125+ '' ) ;
108126
109- haskell = writeHaskell "test-writers-haskell" { libraries = [ haskellPackages . acme-default ] ; } ''
127+ haskell = expectSuccess ( writeHaskell "test-writers-haskell" { libraries = [ haskellPackages . acme-default ] ; } ''
110128 import Data.Default
111129
112130 int :: Int
@@ -116,53 +134,51 @@ let
116134 main = case int of
117135 18871 -> putStrLn $ id "success"
118136 _ -> print "fail"
119- '' ;
137+ '' ) ;
120138
121- js = writeJS "test-writers-js" { libraries = [ nodePackages . semver ] ; } ''
139+ js = expectSuccess ( writeJS "test-writers-js" { libraries = [ nodePackages . semver ] ; } ''
122140 var semver = require('semver');
123141
124142 if (semver.valid('1.2.3')) {
125143 console.log('success')
126144 } else {
127145 console.log('fail')
128146 }
129- '' ;
147+ '' ) ;
130148
131- perl = writePerl "test-writers-perl" { libraries = [ perlPackages . boolean ] ; } ''
149+ perl = expectSuccess ( writePerl "test-writers-perl" { libraries = [ perlPackages . boolean ] ; } ''
132150 use boolean;
133151 print "success\n" if true;
134- '' ;
152+ '' ) ;
135153
136- pypy2 = writePyPy2 "test-writers-pypy2" { libraries = [ pypy2Packages . enum ] ; } ''
154+ pypy2 = expectSuccess ( writePyPy2 "test-writers-pypy2" { libraries = [ pypy2Packages . enum ] ; } ''
137155 from enum import Enum
138156
139-
140157 class Test(Enum):
141158 a = "success"
142159
143-
144160 print Test.a
145- '' ;
161+ '' ) ;
146162
147- python3 = writePython3 "test-writers-python3" { libraries = [ python3Packages . pyyaml ] ; } ''
163+ python3 = expectSuccess ( writePython3 "test-writers-python3" { libraries = [ python3Packages . pyyaml ] ; } ''
148164 import yaml
149165
150- y = yaml.load ("""
166+ y = yaml.safe_load ("""
151167 - test: success
152168 """)
153169 print(y[0]['test'])
154- '' ;
170+ '' ) ;
155171
156- pypy3 = writePyPy3 "test-writers-pypy3" { libraries = [ pypy3Packages . pyyaml ] ; } ''
172+ pypy3 = expectSuccess ( writePyPy3 "test-writers-pypy3" { libraries = [ pypy3Packages . pyyaml ] ; } ''
157173 import yaml
158174
159- y = yaml.load ("""
175+ y = yaml.safe_load ("""
160176 - test: success
161177 """)
162178 print(y[0]['test'])
163- '' ;
179+ '' ) ;
164180
165- fsharp = makeFSharpWriter {
181+ fsharp = expectSuccess ( makeFSharpWriter {
166182 libraries = { fetchNuGet } : [
167183 ( fetchNuGet { pname = "FSharp.SystemTextJson" ; version = "0.17.4" ; sha256 = "1bplzc9ybdqspii4q28l8gmfvzpkmgq5l1hlsiyg2h46w881lwg2" ; } )
168184 ] ;
@@ -183,31 +199,31 @@ let
183199 then "success"
184200 else "failed"
185201 |> printfn "%s"
186- '' ;
202+ '' ) ;
187203
188- pypy2NoLibs = writePyPy2 "test-writers-pypy2-no-libs" { } ''
204+ pypy2NoLibs = expectSuccess ( writePyPy2 "test-writers-pypy2-no-libs" { } ''
189205 print("success")
190- '' ;
206+ '' ) ;
191207
192- python3NoLibs = writePython3 "test-writers-python3-no-libs" { } ''
208+ python3NoLibs = expectSuccess ( writePython3 "test-writers-python3-no-libs" { } ''
193209 print("success")
194- '' ;
210+ '' ) ;
195211
196- pypy3NoLibs = writePyPy3 "test-writers-pypy3-no-libs" { } ''
212+ pypy3NoLibs = expectSuccess ( writePyPy3 "test-writers-pypy3-no-libs" { } ''
197213 print("success")
198- '' ;
214+ '' ) ;
199215
200- fsharpNoNugetDeps = writeFSharp "test-writers-fsharp-no-nuget-deps" ''
216+ fsharpNoNugetDeps = expectSuccess ( writeFSharp "test-writers-fsharp-no-nuget-deps" ''
201217 printfn "success"
202- '' ;
218+ '' ) ;
203219 } ;
204220
205-
206- path = {
207- bash = writeBash "test-writers-bash-path" ( writeText "test" ''
221+ path = lib . recurseIntoAttrs {
222+ bash = expectSuccess ( writeBash "test-writers-bash-path" ( writeText "test" ''
208223 if [[ "test" == "test" ]]; then echo "success"; fi
209- '' ) ;
210- haskell = writeHaskell "test-writers-haskell-path" { libraries = [ haskellPackages . acme-default ] ; } ( writeText "test" ''
224+ '' ) ) ;
225+
226+ haskell = expectSuccess ( writeHaskell "test-writers-haskell-path" { libraries = [ haskellPackages . acme-default ] ; } ( writeText "test" ''
211227 import Data.Default
212228
213229 int :: Int
217233 main = case int of
218234 18871 -> putStrLn $ id "success"
219235 _ -> print "fail"
220- '' ) ;
236+ '' ) ) ;
221237 } ;
222-
223- writeTest = expectedValue : name : test :
224- writeDash "run-${ name } " ''
225- if test "$(${ test } )" != "${ expectedValue } "; then
226- echo 'test ${ test } failed'
227- exit 1
228- fi
229- '' ;
230-
231- in runCommand "test-writers" {
232- passthru = { inherit writeTest bin simple path ; } ;
233- meta . platforms = lib . platforms . all ;
234- } ''
235- ${ lib . concatMapStringsSep "\n " ( test : writeTest "success" test . name "${ test } /bin/${ test . name } " ) ( lib . attrValues bin ) }
236- ${ lib . concatMapStringsSep "\n " ( test : writeTest "success" test . name test ) ( lib . attrValues simple ) }
237- ${ lib . concatMapStringsSep "\n " ( test : writeTest "success" test . name test ) ( lib . attrValues path ) }
238-
239- echo 'nix-writers successfully tested' >&2
240- touch $out
241- ''
242-
238+ }
0 commit comments