-
-
Notifications
You must be signed in to change notification settings - Fork 270
/
cli_run.rs
1560 lines (1376 loc) · 47.7 KB
/
cli_run.rs
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
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#[macro_use]
extern crate pretty_assertions;
extern crate bumpalo;
extern crate indoc;
extern crate roc_collections;
extern crate roc_load;
extern crate roc_module;
#[cfg(test)]
mod cli_run {
use cli_utils::helpers::{
extract_valgrind_errors, file_path_from_root, fixture_file, fixtures_dir, known_bad_file,
run_cmd, run_roc, run_with_valgrind, strip_colors, Out, ValgrindError, ValgrindErrorXWhat,
};
use const_format::concatcp;
use indoc::indoc;
use roc_cli::{CMD_BUILD, CMD_CHECK, CMD_DEV, CMD_FORMAT, CMD_RUN, CMD_TEST};
use roc_test_utils::assert_multiline_str_eq;
use serial_test::serial;
use std::iter;
use std::path::Path;
#[cfg(all(unix, not(target_os = "macos")))]
const ALLOW_VALGRIND: bool = true;
// Disallow valgrind on macOS by default, because it reports a ton
// of false positives. For local development on macOS, feel free to
// change this to true!
#[cfg(target_os = "macos")]
const ALLOW_VALGRIND: bool = false;
#[cfg(windows)]
const ALLOW_VALGRIND: bool = false;
// use valgrind (if supported on the current platform)
#[derive(Debug, Clone, Copy)]
enum UseValgrind {
Yes,
No,
}
#[derive(Debug, Clone, Copy)]
enum TestCliCommands {
Many,
Run,
Test,
Dev,
}
const OPTIMIZE_FLAG: &str = concatcp!("--", roc_cli::FLAG_OPTIMIZE);
const LINKER_FLAG: &str = concatcp!("--", roc_cli::FLAG_LINKER);
const CHECK_FLAG: &str = concatcp!("--", roc_cli::FLAG_CHECK);
const PREBUILT_PLATFORM: &str = concatcp!("--", roc_cli::FLAG_PREBUILT);
#[allow(dead_code)]
const TARGET_FLAG: &str = concatcp!("--", roc_cli::FLAG_TARGET);
#[derive(Debug)]
enum CliMode {
Roc, // buildAndRunIfNoErrors
RocBuild, // buildOnly
RocRun, // buildAndRun
RocTest,
RocDev,
}
#[cfg(all(target_os = "linux", target_arch = "x86_64"))]
const TEST_LEGACY_LINKER: bool = true;
// Surgical linker currently only supports linux x86_64,
// so we're always testing the legacy linker on other targets.
#[cfg(not(all(target_os = "linux", target_arch = "x86_64")))]
const TEST_LEGACY_LINKER: bool = false;
#[derive(Debug, PartialEq, Eq)]
enum Arg<'a> {
ExamplePath(&'a str),
PlainText(&'a str),
}
fn check_compile_error(file: &Path, flags: &[&str], expected: &str) {
let compile_out = run_roc(
[CMD_CHECK, file.to_str().unwrap()].iter().chain(flags),
&[],
&[],
);
let err = compile_out.stdout.trim();
let err = strip_colors(err);
// e.g. "1 error and 0 warnings found in 123 ms."
let (before_first_digit, _) = err.split_at(err.rfind("found in ").unwrap());
let err = format!("{}found in <ignored for test> ms.", before_first_digit);
// make paths consistent
let err = err.replace('\\', "/");
// consistency with typewriters, very important
let err = err.replace('\r', "");
assert_multiline_str_eq!(err.as_str(), expected);
}
fn check_format_check_as_expected(file: &Path, expects_success_exit_code: bool) {
let out = run_roc([CMD_FORMAT, file.to_str().unwrap(), CHECK_FLAG], &[], &[]);
assert_eq!(out.status.success(), expects_success_exit_code);
}
fn run_roc_on_failure_is_panic<'a, I: IntoIterator<Item = &'a str>>(
file: &'a Path,
args: I,
stdin: &[&str],
roc_app_args: &[String],
env: &[(&str, &str)],
) -> Out {
let compile_out = run_roc_on(file, args, stdin, roc_app_args, env);
assert!(
compile_out.status.success(),
"\n___________\nRoc command failed with status {:?}:\n\n {} {}\n___________\n",
compile_out.status,
compile_out.stdout,
compile_out.stderr,
);
compile_out
}
fn run_roc_on<'a, I: IntoIterator<Item = &'a str>>(
file: &'a Path,
args: I,
stdin: &[&str],
roc_app_args: &[String],
env: &[(&str, &str)],
) -> Out {
let compile_out = run_roc(
// converting these all to String avoids lifetime issues
args.into_iter()
.map(|arg| arg.to_string())
.chain([file.to_str().unwrap().to_string(), "--".to_string()])
.chain(roc_app_args.iter().cloned()),
stdin,
env,
);
let ignorable = "🔨 Rebuilding platform...\n";
let stderr = compile_out.stderr.replacen(ignorable, "", 1);
// for some reason, llvm prints out this warning when targeting windows
let ignorable = "warning: ignoring debug info with an invalid version (0) in app\r\n";
let stderr = stderr.replacen(ignorable, "", 1);
let is_reporting_runtime = stderr.starts_with("runtime: ") && stderr.ends_with("ms\n");
if !(stderr.is_empty() || is_reporting_runtime) {
panic!("\n___________\nThe roc command:\n\n {:?}\n\nhad unexpected stderr:\n\n {}\n___________\n", compile_out.cmd_str, stderr);
}
compile_out
}
#[allow(clippy::too_many_arguments)]
fn check_output_with_stdin(
file: &Path,
stdin: &[&str],
executable_filename: &str,
flags: &[&str],
roc_app_args: &[String],
extra_env: &[(&str, &str)],
expected_ending: &str,
use_valgrind: UseValgrind,
test_cli_commands: TestCliCommands,
) {
// valgrind does not yet support avx512 instructions, see #1963.
// we can't enable this only when testing with valgrind because of host re-use between tests
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
if is_x86_feature_detected!("avx512f") {
std::env::set_var("NO_AVX512", "1");
}
// TODO: expects don't currently work on windows
let cli_commands = if cfg!(windows) {
match test_cli_commands {
TestCliCommands::Many => vec![CliMode::RocBuild, CliMode::RocRun],
TestCliCommands::Run => vec![CliMode::RocRun],
TestCliCommands::Test => vec![],
TestCliCommands::Dev => vec![],
}
} else {
match test_cli_commands {
TestCliCommands::Many => vec![CliMode::RocBuild, CliMode::RocRun, CliMode::Roc],
TestCliCommands::Run => vec![CliMode::Roc],
TestCliCommands::Test => vec![CliMode::RocTest],
TestCliCommands::Dev => vec![CliMode::RocDev],
}
};
for cli_mode in cli_commands.iter() {
let flags = {
let mut vec = flags.to_vec();
// max-threads segfaults on windows right now
if !cfg!(windows) {
vec.push("--max-threads=1");
}
vec.into_iter()
};
let out = match cli_mode {
CliMode::RocBuild => {
run_roc_on_failure_is_panic(
file,
iter::once(CMD_BUILD).chain(flags.clone()),
&[],
&[],
&[],
);
if matches!(use_valgrind, UseValgrind::Yes) && ALLOW_VALGRIND {
let mut valgrind_args = vec![file
.with_file_name(executable_filename)
.to_str()
.unwrap()
.to_string()];
valgrind_args.extend(roc_app_args.iter().cloned());
let (valgrind_out, raw_xml) =
run_with_valgrind(stdin.iter().copied(), &valgrind_args);
if valgrind_out.status.success() {
let memory_errors = extract_valgrind_errors(&raw_xml).unwrap_or_else(|err| {
panic!("failed to parse the `valgrind` xml output:\n\n Error was:\n\n {:?}\n\n valgrind xml was:\n\n \"{}\"\n\n valgrind stdout was:\n\n \"{}\"\n\n valgrind stderr was:\n\n \"{}\"", err, raw_xml, valgrind_out.stdout, valgrind_out.stderr);
});
if !memory_errors.is_empty() {
for error in memory_errors {
let ValgrindError {
kind,
what: _,
xwhat,
} = error;
println!("Valgrind Error: {}\n", kind);
if let Some(ValgrindErrorXWhat {
text,
leakedbytes: _,
leakedblocks: _,
}) = xwhat
{
println!(" {}", text);
}
}
panic!("Valgrind reported memory errors");
}
} else {
let exit_code = match valgrind_out.status.code() {
Some(code) => format!("exit code {}", code),
None => "no exit code".to_string(),
};
panic!("`valgrind` exited with {}. valgrind stdout was: \"{}\"\n\nvalgrind stderr was: \"{}\"", exit_code, valgrind_out.stdout, valgrind_out.stderr);
}
valgrind_out
} else {
run_cmd(
file.with_file_name(executable_filename).to_str().unwrap(),
stdin.iter().copied(),
roc_app_args,
extra_env.iter().copied(),
)
}
}
CliMode::Roc => {
run_roc_on_failure_is_panic(file, flags.clone(), stdin, roc_app_args, extra_env)
}
CliMode::RocRun => run_roc_on_failure_is_panic(
file,
iter::once(CMD_RUN).chain(flags.clone()),
stdin,
roc_app_args,
extra_env,
),
CliMode::RocTest => {
// here failure is what we expect
run_roc_on(
file,
iter::once(CMD_TEST).chain(flags.clone()),
stdin,
roc_app_args,
extra_env,
)
}
CliMode::RocDev => {
// here failure is what we expect
run_roc_on(
file,
iter::once(CMD_DEV).chain(flags.clone()),
stdin,
roc_app_args,
extra_env,
)
}
};
let mut actual = strip_colors(&out.stdout);
// e.g. "1 failed and 0 passed in 123 ms."
if let Some(split) = actual.rfind("passed in ") {
let (before_first_digit, _) = actual.split_at(split);
actual = format!("{}passed in <ignored for test> ms.", before_first_digit);
}
let self_path = file.display().to_string();
actual = actual.replace(&self_path, "<ignored for tests>");
if !actual.ends_with(expected_ending) {
panic!(
"expected output to end with:\n{}\nbut instead got:\n{}\n stderr was:\n{}",
expected_ending, actual, out.stderr
);
}
if !out.status.success() && !matches!(cli_mode, CliMode::RocTest) {
// We don't need stdout, Cargo prints it for us.
panic!(
"Example program exited with status {:?}\nstderr was:\n{:#?}",
out.status, out.stderr
);
}
}
}
// when you want to run `roc test` to execute `expect`s, perhaps on a library rather than an application.
fn test_roc_expect(dir_name: &str, roc_filename: &str) {
let path = file_path_from_root(dir_name, roc_filename);
let out = run_roc([CMD_TEST, path.to_str().unwrap()], &[], &[]);
assert!(out.status.success());
}
// when you don't need args, stdin or extra_env
fn test_roc_app_slim(
dir_name: &str,
roc_filename: &str,
executable_filename: &str,
expected_ending: &str,
use_valgrind: UseValgrind,
) {
test_roc_app(
dir_name,
roc_filename,
executable_filename,
&[],
&[],
&[],
expected_ending,
use_valgrind,
TestCliCommands::Run,
)
}
#[allow(clippy::too_many_arguments)]
fn test_roc_app(
dir_name: &str,
roc_filename: &str,
executable_filename: &str,
stdin: &[&str],
args: &[Arg],
extra_env: &[(&str, &str)],
expected_ending: &str,
use_valgrind: UseValgrind,
test_cli_commands: TestCliCommands,
) {
let file_name = file_path_from_root(dir_name, roc_filename);
let mut roc_app_args: Vec<String> = Vec::new();
for arg in args {
match arg {
Arg::ExamplePath(file) => {
roc_app_args.push(
file_path_from_root(dir_name, file)
.to_str()
.unwrap()
.to_string(),
);
}
Arg::PlainText(arg) => {
roc_app_args.push(arg.to_string());
}
}
}
// workaround for surgical linker issue, see PR #3990
let mut custom_flags: Vec<&str> = Vec::new();
match executable_filename {
"form" | "hello-gui" | "breakout" | "libhello" => {
// Since these require things the build system often doesn't have
// (e.g. GUIs open a window, Ruby needs ruby installed, WASM needs a browser)
// we do `roc build` on them but don't run them.
run_roc_on(&file_name, [CMD_BUILD, OPTIMIZE_FLAG], &[], &[], &[]);
return;
}
"swiftui" | "rocLovesSwift" => {
if cfg!(not(target_os = "macos")) {
eprintln!(
"WARNING: skipping testing example {} because it only works on MacOS.",
roc_filename
);
return;
} else {
run_roc_on(&file_name, [CMD_BUILD, OPTIMIZE_FLAG], &[], &[], &[]);
return;
}
}
"rocLovesWebAssembly" => {
// this is a web assembly example, but we don't test with JS at the moment
eprintln!(
"WARNING: skipping testing example {} because it only works in a browser!",
roc_filename
);
return;
}
"args" => {
custom_flags = vec![LINKER_FLAG, "legacy"];
}
_ => {}
}
// Check with and without optimizations
check_output_with_stdin(
&file_name,
stdin,
executable_filename,
&custom_flags,
&roc_app_args,
extra_env,
expected_ending,
use_valgrind,
test_cli_commands,
);
custom_flags.push(OPTIMIZE_FLAG);
// This is mostly because the false interpreter is still very slow -
// 25s for the cli tests is just not acceptable during development!
#[cfg(not(debug_assertions))]
check_output_with_stdin(
&file_name,
stdin,
executable_filename,
&custom_flags,
&roc_app_args,
extra_env,
expected_ending,
use_valgrind,
test_cli_commands,
);
// Also check with the legacy linker.
if TEST_LEGACY_LINKER {
check_output_with_stdin(
&file_name,
stdin,
executable_filename,
&[LINKER_FLAG, "legacy"],
&roc_app_args,
extra_env,
expected_ending,
use_valgrind,
test_cli_commands,
);
}
}
#[test]
#[serial(zig_platform_parser_package_basic_cli_url)]
#[cfg_attr(windows, ignore)]
fn hello_world() {
test_roc_app_slim(
"examples",
"helloWorld.roc",
"helloWorld",
"Hello, World!\n",
UseValgrind::Yes,
)
}
#[test]
#[serial(cli_platform)]
#[cfg_attr(windows, ignore)]
fn hello_world_no_url() {
test_roc_app_slim(
"examples",
"helloWorldNoURL.roc",
"helloWorld",
"Hello, World!\n",
UseValgrind::Yes,
)
}
#[cfg(windows)]
const LINE_ENDING: &str = "\r\n";
#[cfg(not(windows))]
const LINE_ENDING: &str = "\n";
#[test]
#[cfg_attr(windows, ignore)]
// uses C platform
fn platform_switching_main() {
test_roc_app_slim(
"examples/platform-switching",
"main.roc",
"rocLovesPlatforms",
&("Which platform am I running on now?".to_string() + LINE_ENDING),
UseValgrind::Yes,
)
}
// We exclude the C platforming switching example
// because the main platform switching example runs the c platform.
// If we don't, a race condition leads to test flakiness.
#[test]
#[cfg_attr(windows, ignore)]
fn platform_switching_rust() {
test_roc_app_slim(
"examples/platform-switching",
"rocLovesRust.roc",
"rocLovesRust",
"Roc <3 Rust!\n",
UseValgrind::Yes,
)
}
// zig_platform_parser_package_basic_cli_url use to be split up but then things could get stuck
#[test]
#[serial(zig_platform_parser_package_basic_cli_url)]
#[cfg_attr(windows, ignore)]
fn platform_switching_zig() {
test_roc_app_slim(
"examples/platform-switching",
"rocLovesZig.roc",
"rocLovesZig",
"Roc <3 Zig!\n",
UseValgrind::Yes,
)
}
#[test]
fn platform_switching_wasm() {
test_roc_app_slim(
"examples/platform-switching",
"rocLovesWebAssembly.roc",
"rocLovesWebAssembly",
"Roc <3 Web Assembly!\n",
UseValgrind::Yes,
)
}
#[test]
fn platform_switching_swift() {
test_roc_app_slim(
"examples/platform-switching",
"rocLovesSwift.roc",
"rocLovesSwift",
"Roc <3 Swift!\n",
UseValgrind::Yes,
)
}
#[test]
#[cfg_attr(windows, ignore)]
fn expects_dev_and_test() {
// these are in the same test function so we don't have to worry about race conditions
// on the building of the platform
test_roc_app(
"crates/cli_testing_examples/expects",
"expects.roc",
"expects-test",
&[],
&[],
&[],
indoc!(
r#"
This expectation failed:
18│ expect x != x
^^^^^^
When it failed, these variables had these values:
x : Num *
x = 42
[<ignored for tests> 19:9] 42
[<ignored for tests> 20:9] "Fjoer en ferdjer frieten oan dyn geve lea"
[<ignored for tests> 13:9] "abc"
[<ignored for tests> 13:9] 10
[<ignored for tests> 13:9] A (B C)
Program finished!
"#
),
UseValgrind::Yes,
TestCliCommands::Dev,
);
test_roc_app(
"crates/cli_testing_examples/expects",
"expects.roc",
"expects-test",
&[],
&[],
&[],
indoc!(
r#"
This expectation failed:
6│> expect
7│> a = 1
8│> b = 2
9│>
10│> a == b
When it failed, these variables had these values:
a : Num *
a = 1
b : Num *
b = 2
1 failed and 0 passed in <ignored for test> ms."#
),
UseValgrind::Yes,
TestCliCommands::Test,
);
}
#[test]
#[cfg_attr(
windows,
ignore = "this platform is broken, and `roc run --lib` is missing on windows"
)]
fn ruby_interop() {
test_roc_app_slim(
"examples/ruby-interop",
"main.roc",
"libhello",
"",
UseValgrind::Yes,
)
}
#[test]
#[cfg_attr(windows, ignore)]
fn fibonacci() {
test_roc_app_slim(
"crates/cli_testing_examples/algorithms",
"fibonacci.roc",
"fibonacci",
"",
UseValgrind::Yes,
)
}
#[test]
fn hello_gui() {
test_roc_app_slim(
"examples/gui",
"hello.roc",
"hello-gui",
"",
UseValgrind::No,
)
}
#[cfg_attr(windows, ignore)] // flaky error; issue #5024
#[serial(breakout)]
#[test]
fn breakout() {
test_roc_app_slim(
"examples/gui/breakout",
"breakout.roc",
"breakout",
"",
UseValgrind::No,
)
}
#[test]
#[serial(breakout)]
fn breakout_hello_gui() {
test_roc_app_slim(
"examples/gui/breakout",
"hello-gui.roc",
"hello-gui",
"",
UseValgrind::No,
)
}
#[test]
#[cfg_attr(windows, ignore)]
fn quicksort() {
test_roc_app_slim(
"crates/cli_testing_examples/algorithms",
"quicksort.roc",
"quicksort",
"[0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2]\n",
UseValgrind::Yes,
)
}
#[test]
#[cfg_attr(windows, ignore = "missing __udivdi3 and some other symbols")]
#[serial(cli_platform)]
fn cli_args() {
test_roc_app(
"examples/cli",
"args.roc",
"args",
&[],
&[
Arg::PlainText("log"),
Arg::PlainText("-b"),
Arg::PlainText("3"),
Arg::PlainText("--num"),
Arg::PlainText("81"),
],
&[],
"4\n",
UseValgrind::No,
TestCliCommands::Run,
)
}
// TODO: remove in favor of cli_args once mono bugs are resolved in investigation
#[test]
#[cfg_attr(windows, ignore = "missing __udivdi3 and some other symbols")]
#[serial(cli_platform)]
fn cli_args_check() {
let path = file_path_from_root("examples/cli", "args.roc");
let out = run_roc([CMD_CHECK, path.to_str().unwrap()], &[], &[]);
assert!(out.status.success());
}
// TODO: write a new test once mono bugs are resolved in investigation
#[test]
#[cfg(not(debug_assertions))] // https://github.com/roc-lang/roc/issues/4806
fn check_virtual_dom_server() {
let path = file_path_from_root("examples/virtual-dom-wip", "example-server.roc");
let out = run_roc([CMD_CHECK, path.to_str().unwrap()], &[], &[]);
assert!(out.status.success());
}
// TODO: write a new test once mono bugs are resolved in investigation
#[test]
#[cfg(not(debug_assertions))] // https://github.com/roc-lang/roc/issues/4806
fn check_virtual_dom_client() {
let path = file_path_from_root("examples/virtual-dom-wip", "example-client.roc");
let out = run_roc([CMD_CHECK, path.to_str().unwrap()], &[], &[]);
assert!(out.status.success());
}
#[test]
#[cfg_attr(windows, ignore)]
fn interactive_effects() {
test_roc_app(
"examples/cli",
"effects.roc",
"effects",
&["hi there!"],
&[],
&[],
"hi there!\nIt is known\n",
UseValgrind::Yes,
TestCliCommands::Run,
)
}
#[test]
#[cfg_attr(windows, ignore)]
// tea = The Elm Architecture
fn terminal_ui_tea() {
test_roc_app(
"examples/cli",
"tui.roc",
"tui",
&["foo\n"], // NOTE: adding more lines leads to memory leaks
&[],
&[],
"Hello Worldfoo!\n",
UseValgrind::Yes,
TestCliCommands::Run,
)
}
#[test]
#[cfg_attr(windows, ignore)]
fn false_interpreter() {
test_roc_app(
"examples/cli/false-interpreter",
"False.roc",
"false",
&[],
&[Arg::ExamplePath("examples/sqrt.false")],
&[],
"1414",
UseValgrind::Yes,
TestCliCommands::Many,
)
}
#[test]
fn swift_ui() {
test_roc_app_slim(
"examples/swiftui",
"main.roc",
"swiftui",
"",
UseValgrind::No,
)
}
#[test]
#[cfg_attr(windows, ignore)]
fn static_site_gen() {
test_roc_app(
"examples/static-site-gen",
"static-site.roc",
"static-site",
&[],
&[Arg::ExamplePath("input"), Arg::ExamplePath("output")],
&[],
"Processed 4 files with 3 successes and 0 errors\n",
UseValgrind::No,
TestCliCommands::Run,
)
}
#[test]
#[serial(cli_platform)]
#[cfg_attr(windows, ignore)]
fn with_env_vars() {
test_roc_app(
"examples/cli",
"env.roc",
"env",
&[],
&[],
&[
("EDITOR", "roc-editor"),
("SHLVL", "3"),
("LETTERS", "a,c,e,j"),
],
"Your favorite editor is roc-editor!\n\
Your current shell level is 3!\n\
Your favorite letters are: a c e j\n",
UseValgrind::No,
TestCliCommands::Run,
)
}
#[test]
#[serial(cli_platform)]
#[cfg_attr(windows, ignore)]
fn ingested_file() {
test_roc_app(
"examples/cli",
"ingested-file.roc",
"ingested-file",
&[],
&[],
&[],
indoc!(
r#"
This roc file can print it's own source code. The source is:
app "ingested-file"
packages { pf: "cli-platform/main.roc" }
imports [
pf.Stdout,
"ingested-file.roc" as ownCode : Str,
]
provides [main] to pf
main =
Stdout.line "\nThis roc file can print it's own source code. The source is:\n\n\(ownCode)"
"#
),
UseValgrind::No,
TestCliCommands::Run,
)
}
#[test]
#[serial(cli_platform)]
#[cfg_attr(windows, ignore)]
fn ingested_file_bytes() {
test_roc_app(
"examples/cli",
"ingested-file-bytes.roc",
"ingested-file-bytes",
&[],
&[],
&[],
"22424\n",
UseValgrind::No,
TestCliCommands::Run,
)
}
#[test]
#[serial(zig_platform_parser_package_basic_cli_url)]
#[cfg_attr(windows, ignore)]
fn parse_movies_csv() {
test_roc_app_slim(
"examples/parser/examples",
"parse-movies-csv.roc",
"example",
"Parse success!\n",
UseValgrind::No,
)
}
#[test]
#[serial(zig_platform_parser_package_basic_cli_url)]
#[cfg_attr(windows, ignore)]
fn parse_letter_counts() {
test_roc_app_slim(
"examples/parser/examples",
"letter-counts.roc",
"example",
"I counted 7 letter A's!\n",
UseValgrind::No,
)
}
#[test]
#[cfg_attr(windows, ignore)]
fn parse_http() {
test_roc_expect("examples/parser/package", "ParserHttp.roc")
}
// TODO not sure if this cfg should still be here: #[cfg(not(debug_assertions))]
// this is for testing the benchmarks, to perform proper benchmarks see crates/cli/benches/README.md
mod test_benchmarks {
use super::{TestCliCommands, UseValgrind};
use cli_utils::helpers::cli_testing_dir;
use super::{check_output_with_stdin, OPTIMIZE_FLAG, PREBUILT_PLATFORM};
use std::{path::Path, sync::Once};
static BENCHMARKS_BUILD_PLATFORM: Once = Once::new();
fn test_benchmark(
roc_filename: &str,
executable_filename: &str,
stdin: &[&str],
expected_ending: &str,
use_valgrind: UseValgrind,
) {
let file_name = cli_testing_dir("benchmarks").join(roc_filename);
// TODO fix QuicksortApp and then remove this!
match roc_filename {
"QuicksortApp.roc" => {
eprintln!(
"WARNING: skipping testing benchmark {} because the test is broken right now!",
roc_filename
);
return;
}
"TestAStar.roc" => {
if cfg!(feature = "wasm32-cli-run") {
eprintln!(
"WARNING: skipping testing benchmark {} because it currently does not work on wasm32 due to dictionaries.",
roc_filename
);
return;
}
}
_ => {}
}
#[cfg(all(not(feature = "wasm32-cli-run"), not(feature = "i386-cli-run")))]
check_output_regular(
&file_name,
stdin,
executable_filename,
expected_ending,
use_valgrind,
);