forked from purescript/spago
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpagoSpec.hs
724 lines (543 loc) · 30.5 KB
/
SpagoSpec.hs
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
module SpagoSpec (spec) where
import Control.Concurrent (threadDelay)
import qualified Data.Text as Text
import Prelude hiding (FilePath)
import qualified System.IO.Temp as Temp
import Test.Hspec (Spec, around_, describe, it, shouldBe, shouldNotSatisfy,
shouldReturn, shouldSatisfy)
import Turtle (ExitCode (..), cd, cp, decodeString, empty, encodeString,
mkdir, mktree, mv, pwd, readTextFile, rm, shell,
shellStrictWithErr, testdir, writeTextFile, (</>))
import Utils (checkFileHasInfix, checkFixture, outputShouldEqual,
readFixture, runFor, shouldBeFailure, shouldBeFailureOutput,
shouldBeFailureStderr, shouldBeSuccess, shouldBeSuccessOutput,
shouldBeSuccessOutputWithErr, shouldBeSuccessStderr, spago,
withCwd)
setup :: IO () -> IO ()
setup cmd = do
Temp.withTempDirectory "test/" "spago-test" $ \temp -> do
-- print ("Running in " <> temp)
withCwd (decodeString temp) cmd
spec :: Spec
spec = around_ setup $ do
describe "spago init" $ do
it "Spago should have set up a project" $ do
spago ["init"] >>= shouldBeSuccess
it "Spago should refuse to overwrite an existing project without -f" $ do
spago ["init"] >>= shouldBeSuccess
spago ["init"] >>= shouldBeFailure
it "Spago should not overwrite files when initing a project" $ do
mktree "src"
writeTextFile "src/Main.purs" "Something"
spago ["init"] >>= shouldBeSuccess
readTextFile "src/Main.purs" `shouldReturn` "Something"
it "Spago should always succeed in doing init with force" $ do
spago ["init"] >>= shouldBeSuccess
spago ["init", "-f"] >>= shouldBeSuccess
it "Spago should import config from psc-package" $ do
writeTextFile "psc-package.json" "{ \"name\": \"aaa\", \"depends\": [ \"prelude\" ], \"set\": \"foo\", \"source\": \"bar\" }"
spago ["init"] >>= shouldBeSuccess
cp "spago.dhall" "spago-psc-success.dhall"
checkFixture "spago-psc-success.dhall"
it "Spago should not import dependencies that are not in the package-set" $ do
writeTextFile "psc-package.json" "{ \"name\": \"aaa\", \"depends\": [ \"prelude\", \"foo\", \"bar\" ], \"set\": \"foo\", \"source\": \"bar\" }"
spago ["init", "-f"] >>= shouldBeSuccess
cp "spago.dhall" "spago-psc-failure.dhall"
checkFixture "spago-psc-failure.dhall"
it "Spago should import configs from Bower" $ do
shellStrictWithErr "git clone https://github.com/justinwoo/purescript-simple-json.git ." empty
shellStrictWithErr "git checkout v7.0.0" empty
spago ["init"] >>= shouldBeSuccess
mv "spago.dhall" "spago-bower-import.dhall"
checkFixture "spago-bower-import.dhall"
it "Spago should strip comments from spago.dhall and packages.dhall" $ do
spago ["init", "--no-comments"] >>= shouldBeSuccess
cp "spago.dhall" "spago-no-comments.dhall"
checkFixture "spago-no-comments.dhall"
-- We don't want fixture for packages.dhall to avoid having to maintain upstream package-set URL in fixture
dhallSource <- readTextFile "packages.dhall"
dhallSource `shouldNotSatisfy` (Text.isInfixOf "{-") -- comments not present
dhallSource `shouldSatisfy` (Text.isInfixOf "let overrides = {=}") -- some dhall stuff is present
describe "spago install" $ do
it "Subsequent installs should succeed after failed install" $ do
spago ["init"] >>= shouldBeSuccess
-- Run `install` once and kill it soon to simulate failure
runFor 5000 "spago" ["install", "-j", "3"]
-- Sleep for some time, as the above might take time to cleanup old processes
threadDelay 1000000
spago ["install", "-j", "10"] >>= shouldBeSuccess
it "Spago should warn that config was not changed, when trying to install package already present in project dependencies" $ do
spago ["init"] >>= shouldBeSuccess
spago ["install"] >>= shouldBeSuccess
spago ["install", "effect"] >>= shouldBeSuccessStderr "spago-install-existing-dep-stderr.txt"
it "Spago should strip 'purescript-' prefix and give warning if package without prefix is present in package set" $ do
spago ["init"] >>= shouldBeSuccess
spago ["install"] >>= shouldBeSuccess
spago ["install", "purescript-newtype"] >>= shouldBeSuccessStderr "spago-install-purescript-prefix-stderr.txt"
-- dep added without "purescript-" prefix
checkFileHasInfix "spago.dhall" "\"newtype\""
it "Spago should be able to add dependencies" $ do
writeTextFile "psc-package.json" "{ \"name\": \"aaa\", \"depends\": [ \"prelude\" ], \"set\": \"foo\", \"source\": \"bar\" }"
spago ["init"] >>= shouldBeSuccess
spago ["-j 10", "install", "simple-json", "foreign"] >>= shouldBeSuccess
mv "spago.dhall" "spago-install-success.dhall"
checkFixture "spago-install-success.dhall"
it "Spago should not add dependencies that are not in the package set" $ do
writeTextFile "psc-package.json" "{ \"name\": \"aaa\", \"depends\": [ \"prelude\" ], \"set\": \"foo\", \"source\": \"bar\" }"
spago ["init"] >>= shouldBeSuccess
spago ["install", "foo", "bar"] >>= shouldBeFailureStderr "missing-dependencies.txt"
mv "spago.dhall" "spago-install-failure.dhall"
checkFixture "spago-install-failure.dhall"
it "Spago should not allow circular dependencies" $ do
writeTextFile "psc-package.json" "{ \"name\": \"aaa\", \"depends\": [ \"prelude\" ], \"set\": \"foo\", \"source\": \"bar\" }"
spago ["init"] >>= shouldBeSuccess
writeTextFile "spago.dhall" "{- Welcome to a Spago project! You can edit this file as you like. -} { name = \"my-project\" , dependencies = [ \"effect\", \"console\", \"psci-support\", \"a\", \"b\" ] , packages = ./packages.dhall // { a = { version = \"a1\", dependencies = [\"b\"], repo = \"https://github.com/fake/fake.git\" }, b = { version = \"b1\", dependencies = [\"a\"], repo = \"https://github.com/fake/fake.git\" } } }"
spago ["install"] >>= shouldBeFailureStderr "circular-dependencies.txt"
it "Spago should be able to install a package in the set from a commit hash" $ do
spago ["init"] >>= shouldBeSuccess
mv "packages.dhall" "packagesBase.dhall"
writeTextFile "packages.dhall" "let pkgs = ./packagesBase.dhall in pkgs // { simple-json = pkgs.simple-json // { version = \"d45590f493d68baae174b2d3062d502c0cc4c265\" } }"
spago ["install", "simple-json"] >>= shouldBeSuccess
it "Spago should be able to install a package version by branch name with / in it" $ do
spago ["init"] >>= shouldBeSuccess
mv "packages.dhall" "packagesBase.dhall"
writeTextFile "packages.dhall" "let pkgs = ./packagesBase.dhall in pkgs // { metadata_ = { dependencies = [\"prelude\"], repo = \"https://github.com/spacchetti/purescript-metadata.git\", version = \"spago-test/branch-with-slash\" }}"
spago ["install", "metadata_"] >>= shouldBeSuccess
it "Spago should be able to install a package not in the set from a commit hash" $ do
spago ["init"] >>= shouldBeSuccess
mv "packages.dhall" "packagesBase.dhall"
writeTextFile "packages.dhall" "let pkgs = ./packagesBase.dhall in pkgs // { spago = { dependencies = [\"prelude\"], repo = \"https://github.com/spacchetti/spago.git\", version = \"cbdbbf8f8771a7e43f04b18cdefffbcb0f03a990\" }}"
spago ["install", "spago"] >>= shouldBeSuccess
it "Spago should not be able to install a package from a not-existing commit hash" $ do
spago ["init"] >>= shouldBeSuccess
mv "packages.dhall" "packagesBase.dhall"
writeTextFile "packages.dhall" "let pkgs = ./packagesBase.dhall in pkgs // { spago = { dependencies = [\"prelude\"], repo = \"https://github.com/spacchetti/spago.git\", version = \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\" }}"
spago ["install", "spago"] >>= shouldBeFailure
it "Spago should be able to update dependencies in an alternative config" $ do
spago ["init"] >>= shouldBeSuccess
writeTextFile "alternative1.dhall" "./spago.dhall // {dependencies = [\"prelude\"]}"
spago ["-x", "alternative1.dhall", "install", "simple-json"] >>= shouldBeSuccess
checkFixture "alternative1.dhall"
it "Spago should install successfully when the config file is in another directory" $ do
spago ["init"] >>= shouldBeSuccess
rm "spago.dhall"
mkdir "nested"
writeTextFile "./nested/spago.dhall" "{ name = \"nested\", sources = [ \"src/**/*.purs\" ], dependencies = [ \"effect\", \"console\", \"psci-support\" ] , packages = ../packages.dhall }"
spago ["install", "--config", "./nested/spago.dhall"] >>= shouldBeSuccess
it "Spago should not change the alternative config if it does not change dependencies" $ do
spago ["init"] >>= shouldBeSuccess
writeTextFile "alternative2.dhall" "./spago.dhall // { sources = [ \"src/**/*.purs\" ] }\n"
spago ["-x", "alternative2.dhall", "install", "simple-json"] >>= shouldBeSuccess
spago ["-x", "alternative2.dhall", "install", "simple-json"] >>= shouldBeSuccessStderr "alternative2install-stderr.txt"
checkFixture "alternative2.dhall"
it "Spago should install successfully when there are local dependencies sharing the same packages.dhall" $ do
-- Create local 'lib-a' package that depends on lib-c
mkdir "lib-a"
cd "lib-a"
spago ["init"] >>= shouldBeSuccess
rm "spago.dhall"
writeTextFile "spago.dhall" $ "{ name = \"lib-a\", dependencies = [\"console\", \"effect\", \"prelude\", \"lib-c\"], packages = ../packages.dhall }"
cd ".."
-- Create local 'lib-b' package that has its dependencies in a separate file
mkdir "lib-b"
cd "lib-b"
spago ["init"] >>= shouldBeSuccess
rm "spago.dhall"
writeTextFile "spago.dhall" $ "{ name = \"lib-b\", dependencies = ./spago-deps.dhall, packages = ../packages.dhall }"
writeTextFile "spago-deps.dhall" "[\"console\", \"effect\", \"prelude\"]"
cd ".."
-- Create local 'lib-c' package
mkdir "lib-c"
cd "lib-c"
spago ["init"] >>= shouldBeSuccess
rm "spago.dhall"
writeTextFile "spago.dhall" $ "{ name = \"lib-c\", dependencies = [\"console\", \"effect\", \"prelude\"], packages = ../packages.dhall }"
cd ".."
-- Create 'app' package that depends on 'lib-a' and 'lib-b'
spago ["init"] >>= shouldBeSuccess
rm "spago.dhall"
writeTextFile "spago.dhall" "{ name = \"app\", dependencies = [\"console\", \"effect\", \"prelude\", \"lib-a\", \"lib-b\"], packages = ./packages.dhall }"
packageDhall <- readTextFile "packages.dhall"
writeTextFile "packages.dhall" $ packageDhall <> " // { lib-a = ./lib-a/spago.dhall as Location, lib-b = ./lib-b/spago.dhall as Location, lib-c = ./lib-c/spago.dhall as Location }"
spago ["install"] >>= shouldBeSuccess
it "Spago should not warn about freezing remote imports if they can be located from spago.dhall" $ do
spago ["init"] >>= shouldBeSuccess
-- Do an initial installation so that it's easier to compare subsequent output
spago ["install"] >>= shouldBeSuccess
mkdir "elsewhere"
writeTextFile "elsewhere/a.dhall" "let p = ./b.dhall in p"
mv "packages.dhall" "elsewhere/b.dhall"
spagoDhall <- readTextFile "spago.dhall"
writeTextFile "spago.dhall" $ Text.replace "./packages.dhall" "./elsewhere/a.dhall" spagoDhall
spago ["install"] >>= shouldBeSuccessStderr "ensure-frozen-success.txt"
describe "spago sources" $ do
it "Spago should print both dependencies and project sources" $ do
spago ["init"] >>= shouldBeSuccess
spago ["sources"] >>= shouldBeSuccessOutput "sources-output.txt"
-- -- This is currently commented because it requires a GitHub token and Travis makes it hard to do it securely
-- describe "spago login" $ do
--
-- it "Spago should login correctly" $ do
--
-- spago ["login"] >>= shouldBeSuccessOutput "login-output.txt"
describe "spago build" $ do
it "Spago should build successfully" $ do
spago ["init"] >>= shouldBeSuccess
spago ["build"] >>= shouldBeSuccess
it "Spago should pass options to purs" $ do
spago ["init"] >>= shouldBeSuccess
spago ["build", "--purs-args", "-o myOutput"] >>= shouldBeSuccess
testdir "myOutput" `shouldReturn` True
it "Spago should pass multiple options to purs" $ do
spago ["init"] >>= shouldBeSuccess
spago ["build", "--purs-args", "-o", "--purs-args", "myOutput"] >>= shouldBeSuccess
testdir "myOutput" `shouldReturn` True
it "Spago should build successfully with sources included from custom path" $ do
spago ["init"] >>= shouldBeSuccess
mkdir "another_source_path"
mv "src/Main.purs" "another_source_path/Main.purs"
spago ["build", "--path", "another_source_path/*.purs"] >>= shouldBeSuccess
it "Spago should not install packages when passing the --no-install flag" $ do
spago ["init"] >>= shouldBeSuccess
spago ["build", "--no-install"] >>= shouldBeFailure
spago ["install"] >>= shouldBeSuccess
spago ["build", "--no-install"] >>= shouldBeSuccess
it "Spago should add sources to config when key is missing" $ do
configV1 <- readFixture "spago-configV1.dhall"
spago ["init"] >>= shouldBeSuccess
-- Replace initial config with the old config format (without 'sources')
mv "spago.dhall" "spago-old.dhall"
writeTextFile "spago.dhall" configV1
spago ["install"] >>= shouldBeSuccess
mv "spago.dhall" "spago-configV2.dhall"
checkFixture "spago-configV2.dhall"
it "Spago should create a local output folder when we are using --no-share-output" $ do
-- Create root-level packages.dhall
mkdir "monorepo"
cd "monorepo"
spago ["init"] >>= shouldBeSuccess
rm "spago.dhall"
-- Create local 'lib-a' package that uses packages.dhall on top level (but also has it's own one to confuse things)
mkdir "lib-a"
cd "lib-a"
spago ["init"] >>= shouldBeSuccess
rm "spago.dhall"
writeTextFile "spago.dhall" $ "{ name = \"lib-1\", dependencies = [\"console\", \"effect\", \"prelude\"], packages = ./packages.dhall }"
rm "packages.dhall"
writeTextFile "packages.dhall" $ "../packages.dhall"
spago ["build", "--no-share-output"] >>= shouldBeSuccess
testdir "output" `shouldReturn` True
cd ".."
testdir "output" `shouldReturn` False
it "Spago should use the main packages.dhall even when another packages.dhall is further up the tree" $ do
-- Create root-level packages.dhall that directs to middle one
mkdir "monorepo-1"
cd "monorepo-1"
spago ["init"] >>= shouldBeSuccess
rm "spago.dhall"
rm "packages.dhall"
writeTextFile "packages.dhall" $ "./monorepo-2/packages.dhall"
-- Create local 'monorepo-2' package that is the real root
mkdir "monorepo-2"
cd "monorepo-2"
spago ["init"] >>= shouldBeSuccess
rm "spago.dhall"
writeTextFile "spago.dhall" $ "{ name = \"lib-1\", dependencies = [\"console\", \"effect\", \"prelude\"], packages = ./packages.dhall }"
spago ["build", "--no-share-output"] >>= shouldBeSuccess
testdir "output" `shouldReturn` True
-- Create local 'monorepo-3' package that uses packages.dhall on top level
mkdir "monorepo-3"
cd "monorepo-3"
spago ["init"] >>= shouldBeSuccess
rm "spago.dhall"
writeTextFile "spago.dhall" $ "{ name = \"lib-1\", dependencies = [\"console\", \"effect\", \"prelude\"], packages = ./packages.dhall }"
rm "packages.dhall"
writeTextFile "packages.dhall" $ "../../packages.dhall"
spago ["build"] >>= shouldBeSuccess
testdir "output" `shouldReturn` True
cd ".."
testdir "output" `shouldReturn` True
cd ".."
testdir "output" `shouldReturn` False
it "Spago should find the middle packages.dhall even when another file is further up the tree" $ do
-- Create root-level module to confuse things
mkdir "monorepo-root"
cd "monorepo-root"
spago ["init"] >>= shouldBeSuccess
rm "spago.dhall"
writeTextFile "spago.dhall" $ "{ name = \"lib-extra\", dependencies = [\"console\", \"effect\", \"prelude\"], packages = ./packages.dhall }"
-- get rid of duplicate Main module
cd "src"
rm "Main.purs"
writeTextFile "Main.purs" $ "module OtherMain where \n import Prelude\n import Effect\n main :: Effect Unit\n main = pure unit"
cd ".."
-- create real root
mkdir "subfolder"
cd "subfolder"
spago ["init"] >>= shouldBeSuccess
packageDhall <- readTextFile "packages.dhall"
writeTextFile "packages.dhall" $ packageDhall <> " // { lib-extra = ../spago.dhall as Location }"
-- Create local 'lib-a' package that uses packages.dhall in middle folder
mkdir "lib-a"
cd "lib-a"
spago ["init"] >>= shouldBeSuccess
rm "spago.dhall"
writeTextFile "spago.dhall" $ "{ name = \"lib-1\", dependencies = [\"lib-extra\",\"console\", \"effect\", \"prelude\"], packages = ../packages.dhall }"
rm "packages.dhall"
spago ["build"] >>= shouldBeSuccess
-- don't use nested folder
testdir "output" `shouldReturn` True
-- use middle one
cd ".."
testdir "output" `shouldReturn` False
-- not the trick root folder
cd ".."
testdir "output" `shouldReturn` False
it "Spago should create an output folder in the root when we are not passing --no-share-output" $ do
-- Create root-level packages.dhall
mkdir "monorepo2"
cd "monorepo2"
spago ["init"] >>= shouldBeSuccess
rm "spago.dhall"
-- Create local 'lib-a' package that uses packages.dhall on top level (but also has it's own one to confuse things)
mkdir "lib-a"
cd "lib-a"
spago ["init"] >>= shouldBeSuccess
rm "packages.dhall"
writeTextFile "packages.dhall" $ "../packages.dhall"
rm "spago.dhall"
writeTextFile "spago.dhall" $ "{ name = \"lib-1\", license = \"MIT\", repository = \"https://github.com/fake/lib-1.git\", dependencies = [\"console\", \"effect\", \"prelude\"], sources = [\"src/**/*.purs\"], packages = ./packages.dhall }"
spago ["build"] >>= shouldBeSuccess
testdir "output" `shouldReturn` True
cd ".."
testdir "output" `shouldReturn` False
describe "alternate backend" $ do
it "Spago should use alternate backend if option is specified" $ do
configWithBackend <- readFixture "spago-configWithBackend.dhall"
spago ["init"] >>= shouldBeSuccess
mv "spago.dhall" "spago-old.dhall"
writeTextFile "spago.dhall" configWithBackend
-- Blocked by https://github.com/purescript/purescript/issues/3743
-- spago ["-j", "5", "build"] >>= shouldBeSuccess
-- checkFixture "alternate-backend-output.txt"
it "Passing `--codegen corefn` with backend option should fail" $ do
configWithBackend <- readFixture "spago-configWithBackend.dhall"
spago ["init"] >>= shouldBeSuccess
mv "spago.dhall" "spago-old.dhall"
writeTextFile "spago.dhall" configWithBackend
-- Blocked by https://github.com/purescript/purescript/issues/3743
-- spago ["-j", "5", "build"] >>= shouldBeSuccess
-- spago ["build", "--purs-args", "--codegen", "--purs-args", "corefn"] >>= shouldBeFailureOutput "codegen-opt-with-backend.txt"
-- spago ["build", "--purs-args", "--codegen", "--purs-args", "docs"] >>= shouldBeFailureOutput "codegen-opt-with-backend.txt"
it "Spago should run a before command" $ do
spago ["init"] >>= shouldBeSuccess
dir <- pwd
let dumpFile = dir </> "testOutput"
spago ["build", "--before", "echo before>> " <> ( Text.pack $ encodeString dumpFile )] >>= shouldBeSuccess
test <- readTextFile dumpFile
test `shouldBe` "before\n"
it "Spago should run a then command" $ do
spago ["init"] >>= shouldBeSuccess
dir <- pwd
let dumpFile = dir </> "testOutput"
spago [ "build"
, "--then", "echo then>> " <> ( Text.pack $ encodeString dumpFile )
, "--else", "echo else>> " <> ( Text.pack $ encodeString dumpFile )
] >>= shouldBeSuccess
test <- readTextFile dumpFile
test `shouldBe` "then\n"
it "Spago should run a before command before a then command" $ do
spago ["init"] >>= shouldBeSuccess
dir <- pwd
let dumpFile = dir </> "testOutput"
spago [ "build"
, "--before", "echo before>> " <> ( Text.pack $ encodeString dumpFile )
, "--then", "echo then>> " <> ( Text.pack $ encodeString dumpFile )
] >>= shouldBeSuccess
test <- readTextFile dumpFile
test `shouldBe` "before\nthen\n"
it "Spago should run an else command if there is an error" $ do
spago ["init"] >>= shouldBeSuccess
dir <- pwd
let dumpFile = dir </> "testOutput"
rm "src/Main.purs"
writeTextFile "src/Main.purs" "Invalid Purescript code"
spago [ "build"
, "--then", "echo then>> " <> ( Text.pack $ encodeString dumpFile )
, "--else", "echo else>> " <> ( Text.pack $ encodeString dumpFile )
] >>= shouldBeFailure
test <- readTextFile dumpFile
test `shouldBe` "else\n"
it "Spago should run multiple commands in order" $ do
spago ["init"] >>= shouldBeSuccess
dir <- pwd
let dumpFile = dir </> "testOutput"
spago [ "build"
, "--before", "echo before1>> " <> ( Text.pack $ encodeString dumpFile )
, "--before", "echo before2>> " <> ( Text.pack $ encodeString dumpFile )
, "--then", "echo then1>> " <> ( Text.pack $ encodeString dumpFile )
, "--then", "echo then2>> " <> ( Text.pack $ encodeString dumpFile )
] >>= shouldBeSuccess
test <- readTextFile dumpFile
test `shouldBe` "before1\nbefore2\nthen1\nthen2\n"
it "Spago should fail the build if a before command fails" $ do
spago ["init"] >>= shouldBeSuccess
spago [ "build"
, "--before", "exit 1"
] >>= shouldBeFailure
it "Spago should fail the build if a then command fails" $ do
spago ["init"] >>= shouldBeSuccess
spago [ "build"
, "--then", "exit 1"
] >>= shouldBeFailure
it "Spago should still fail the build if an else command fails" $ do
spago ["init"] >>= shouldBeSuccess
rm "src/Main.purs"
writeTextFile "src/Main.purs" "Invalid Purescript code"
spago [ "build"
, "--else", "exit 1"
] >>= shouldBeFailure
describe "spago test" $ do
it "Spago should test successfully" $ do
spago ["init"] >>= shouldBeSuccess
spago ["build"] >>= shouldBeSuccess
spago ["test"] >>= shouldBeSuccessOutputWithErr "test-output-stdout.txt" "test-output-stderr.txt"
it "Spago should fail nicely when the test module is not found" $ do
spago ["init"] >>= shouldBeSuccess
mv "test" "test2"
spago ["test"] >>= shouldBeFailureStderr "spago-test-not-found.txt"
it "Spago should test in custom output folder" $ do
spago ["init"] >>= shouldBeSuccess
spago ["test", "--purs-args", "-o", "--purs-args", "myOutput"] >>= shouldBeSuccess
testdir "myOutput" `shouldReturn` True
it "Spago should test successfully with a different output folder" $ do
-- Create root-level packages.dhall
mkdir "monorepo"
cd "monorepo"
spago ["init"] >>= shouldBeSuccess
rm "spago.dhall"
-- Create local 'lib-a' package that uses packages.dhall on top level (but also has it's own one to confuse things)
mkdir "lib-a"
cd "lib-a"
spago ["init"] >>= shouldBeSuccess
rm "spago.dhall"
writeTextFile "spago.dhall" $ "{ name = \"lib-1\", dependencies = [\"console\", \"effect\", \"prelude\"], packages = ./packages.dhall }"
rm "packages.dhall"
writeTextFile "packages.dhall" $ "../packages.dhall"
spago ["test"] >>= shouldBeSuccess
testdir "output" `shouldReturn` True
cd ".."
testdir "output" `shouldReturn` False
it "Spago should test successfully with --no-share-output" $ do
-- Create root-level packages.dhall
mkdir "monorepo"
cd "monorepo"
spago ["init"] >>= shouldBeSuccess
rm "spago.dhall"
-- Create local 'lib-a' package that uses packages.dhall on top level (but also has it's own one to confuse things)
mkdir "lib-a"
cd "lib-a"
spago ["init"] >>= shouldBeSuccess
rm "spago.dhall"
writeTextFile "spago.dhall" $ "{ name = \"lib-1\", dependencies = [\"console\", \"effect\", \"prelude\"], packages = ./packages.dhall }"
rm "packages.dhall"
writeTextFile "packages.dhall" $ "../packages.dhall"
spago ["test", "--no-share-output"] >>= shouldBeSuccess
testdir "output" `shouldReturn` True
cd ".."
testdir "output" `shouldReturn` False
describe "spago upgrade-set" $ do
it "Spago should migrate package-sets from src/packages.dhall to the released one" $ do
spago ["init"] >>= shouldBeSuccess
mv "packages.dhall" "packages-expected.dhall"
packages <- readTextFile "packages-expected.dhall"
let [packageSetUrl]
= map Text.strip
$ filter (not . null . Text.breakOnAll "https://github.com/purescript/package-sets")
$ Text.lines packages
writeTextFile "packages.dhall" "https://github.com/purescript/package-sets/releases/download/psc-0.13.4-20191025/packages.dhall sha256:f9eb600e5c2a439c3ac9543b1f36590696342baedab2d54ae0aa03c9447ce7d4"
spago ["-v", "upgrade-set"] >>= shouldBeSuccess
newPackages <- Text.strip <$> readTextFile "packages.dhall"
newPackages `shouldBe` packageSetUrl
describe "spago run" $ do
it "Spago should run successfully" $ do
spago ["init"] >>= shouldBeSuccess
spago ["build"] >>= shouldBeSuccess
shell "psa --version" empty >>= \case
ExitSuccess -> spago ["-v", "run"] >>= shouldBeSuccessOutputWithErr "run-output.txt" "run-stderr.txt"
ExitFailure _ -> spago ["-v", "run"] >>= shouldBeSuccessOutputWithErr "run-output.txt" "run-psa-not-installed-stderr.txt"
it "Spago should be able to not use `psa`" $ do
spago ["init"] >>= shouldBeSuccess
spago ["--no-psa", "build"] >>= shouldBeSuccess
spago ["-v", "--no-psa", "run"] >>= shouldBeSuccessOutputWithErr "run-output.txt" "run-no-psa-stderr.txt"
it "Spago should pass stdin to the child process" $ do
spago ["init"] >>= shouldBeSuccess
cp "../fixtures/spago-run-stdin.purs" "src/Main.purs"
spago ["install", "node-buffer", "node-streams", "node-process"] >>= shouldBeSuccess
spago ["build"] >>= shouldBeSuccess
shellStrictWithErr "echo wut| spago run" empty >>= shouldBeSuccessOutput "spago-run-passthrough.txt"
describe "spago bundle" $ do
it "Spago should fail but should point to the replacement command" $ do
spago ["bundle", "--to", "bundle.js"] >>= shouldBeFailureStderr "bundle-stderr.txt"
describe "spago bundle-app" $ do
it "Spago should bundle successfully" $ do
spago ["init"] >>= shouldBeSuccess
spago ["bundle-app", "--to", "bundle-app.js"] >>= shouldBeSuccess
checkFixture "bundle-app.js"
it "Spago should bundle successfully with source map" $ do
spago ["init"] >>= shouldBeSuccess
spago ["bundle-app", "--to", "bundle-app-src-map.js", "--source-maps"] >>= shouldBeSuccess
checkFixture "bundle-app-src-map.js"
checkFixture "bundle-app-src-map.js.map"
describe "spago make-module" $ do
it "Spago should fail but should point to the replacement command" $ do
spago ["make-module", "--to", "make-module.js"] >>= shouldBeFailureStderr "make-module-stderr.txt"
describe "spago bundle-module" $ do
it "Spago should successfully make a module" $ do
spago ["init"] >>= shouldBeSuccess
spago ["build"] >>= shouldBeSuccess
-- Now we don't remove the output folder, but we pass the `--no-build`
-- flag to skip rebuilding (i.e. we are counting on the previous command
-- to have built stuff for us)
spago ["bundle-module", "--to", "bundle-module.js", "--no-build"] >>= shouldBeSuccess
checkFixture "bundle-module.js"
describe "spago list-packages" $ do
it "Spago should list-packages successfully" $ do
spago ["init"] >>= shouldBeSuccess
mv "packages.dhall" "packages-old.dhall"
writeTextFile "packages.dhall" "https://github.com/purescript/package-sets/releases/download/psc-0.13.4-20191025/packages.dhall sha256:f9eb600e5c2a439c3ac9543b1f36590696342baedab2d54ae0aa03c9447ce7d4"
spago ["list-packages"] >>= shouldBeSuccessOutput "list-packages.txt"
it "Spago should list-packages in JSON successfully" $ do
spago ["init"] >>= shouldBeSuccess
mv "packages.dhall" "packages-old.dhall"
writeTextFile "packages.dhall" "https://github.com/purescript/package-sets/releases/download/psc-0.13.4-20191025/packages.dhall sha256:f9eb600e5c2a439c3ac9543b1f36590696342baedab2d54ae0aa03c9447ce7d4"
spago ["list-packages", "--json"] >>= shouldBeSuccessOutput "list-packages.json"
describe "spago path output" $ do
it "Spago should output the correct path" $ do
-- Create local 'monorepo-1' package that is the real root
mkdir "monorepo-1"
cd "monorepo-1"
spago ["init"] >>= shouldBeSuccess
-- Create local 'monorepo-2' package that uses packages.dhall on top level
mkdir "monorepo-2"
cd "monorepo-2"
spago ["init"] >>= shouldBeSuccess
rm "packages.dhall"
writeTextFile "packages.dhall" $ "../packages.dhall"
spago ["path", "output"] >>= outputShouldEqual "output\n"
pure ()
it "Spago should output the local path when no overrides" $ do
mkdir "monorepo-1"
cd "monorepo-1"
spago ["init"] >>= shouldBeSuccess
spago ["path", "output", "--no-share-output"] >>= outputShouldEqual "output\n"
describe "spago verify-set" $ do
it "Spago should fail when there is no spago.dhall or packages.dhall" $ do
spago ["init"] >>= shouldBeSuccess
rm "spago.dhall"
rm "packages.dhall"
spago ["verify-set"] >>= shouldBeFailureStderr "verify-set-failure-no-files.txt"
it "Spago should fail when packages.dhall is malformed" $ do
spago ["init"] >>= shouldBeSuccess
writeTextFile "packages.dhall" $ "abcdef"
spago ["verify-set"] >>= shouldBeFailureStderr "verify-set-failure-bad-packages-dhall.txt"