1
1
2
+ open TestFramework ;
3
+
2
4
open Analyze ;
3
5
4
6
let checkExampleProject = (rootPath, sourcePaths) => {
5
- let state = {
6
- ... TopTypes . empty(),
7
- rootPath,
8
- rootUri: Util . Utils . toUri(rootPath),
9
- };
10
- print_endline(" Project directory in " ++ rootPath);
7
+
8
+ let {describe, describeSkip, describeOnly} =
9
+ describeConfig
10
+ |> withLifecycle(testLifecycle =>
11
+ testLifecycle
12
+ |> beforeAll(() => {
13
+ let state = {
14
+ ... TopTypes . empty(),
15
+ rootPath,
16
+ rootUri: Util . Utils . toUri(rootPath),
17
+ };
18
+ state
19
+ })
20
+ )
21
+ |> build;
22
+
11
23
let files = sourcePaths-> Belt . List . map(path => {
12
- print_endline(" Source directory " ++ path);
24
+ // print_endline(" Source directory " ++ path);
13
25
Files . collect(path, FindFiles . isSourceFile)
14
26
})-> Belt . List . toArray-> Belt . List . concatMany;
15
- files-> Belt . List . reduce([] , (failures, path) => {
16
- let uri = Utils . toUri(path);
17
- switch (Packages . getPackage(~reportDiagnostics= (_, _) => () , uri, state)) {
18
- | Error (message ) =>
19
- print_endline(" Unable to get package: " ++ uri)
20
- print_endline(message);
21
- [ ` PackageFail (uri, message), ... failures]
22
- | Ok (package ) => switch (State . getCompilationResult(uri, state, ~package)) {
23
- | Error (message ) =>
24
- print_endline(" Invalid compilation result: " ++ message);
25
- [ ` FileFail (uri, message), ... failures]
26
- | Ok (Success (_ )) =>
27
- print_endline(" Good: " ++ uri);
28
- failures
29
- | Ok (TypeError (message , _ ) | SyntaxError (message , _ , _ )) =>
30
- print_endline(" Error compiling: " ++ uri);
31
- [ ` FileFail (uri, message)]
32
- }
33
- }
27
+
28
+ describe(rootPath, ({test}) => {
29
+ files-> Belt . List . forEach(path => {
30
+ let uri = Utils . toUri(path);
31
+ test(uri, ({expect, env: state}) => {
32
+ switch (Packages . getPackage(~reportDiagnostics= (_, _) => () , uri, state)) {
33
+ | Error (message ) =>
34
+ expect. string("Unable to get package: " ++ message).toEqual("" )
35
+ // print_endline(" Unable to get package: " ++ uri)
36
+ // print_endline(message);
37
+ // [`PackageFail(uri, message), ...failures]
38
+ | Ok (package ) => switch (State . getCompilationResult(uri, state, ~package)) {
39
+ | Error (message ) =>
40
+ expect. string("Invalid compilation result: " ++ message).toEqual("" )
41
+ // print_endline(" Invalid compilation result: " ++ message);
42
+ // [`FileFail(uri, message), ...failures]
43
+ | Ok (Success (_ )) =>
44
+ expect. bool(true ).toBeTrue()
45
+ // print_endline(" Good: " ++ uri);
46
+ // failures
47
+ | Ok (TypeError (message , _ ) | SyntaxError (message , _ , _ )) =>
48
+ expect. string("Error compiling: " ++ message).toEqual("" )
49
+ // print_endline(" Error compiling: " ++ uri);
50
+ // [`FileFail(uri, message)]
51
+ }
52
+ }
53
+ })
54
+ })
34
55
})
56
+
57
+ // print_endline(" Project directory in " ++ rootPath);
58
+ // files->Belt.List.reduce([], (failures, path) => {
59
+ // })
35
60
};
36
61
37
62
let esyProjects = [
@@ -49,47 +74,69 @@ let projects = (Sys.os_type == "Unix" ? esyProjects : []) @ [
49
74
("bs-3.1.5" , [ "src" ] , "npm install" ),
50
75
] ;
51
76
77
+ // let main = (baseDir, _verbose, args) => {
78
+ // print_endline("Checking each example project to make sure we can analyze each source file...");
79
+ let baseDir = Sys . getcwd() ;
80
+ projects-> Belt . List . forEach(((root, sourcePaths, prepareCommand)) => {
81
+ // if (args == [] || List.mem(root, args)) {
82
+ describe(root, ({test}) => {
83
+ let root = Filename . concat(baseDir, Filename . concat("examples" , root));
52
84
53
- let main = (baseDir, _verbose, args) => {
54
- print_endline("Checking each example project to make sure we can analyze each source file..." );
55
- projects-> Belt . List . reduce([] , (failures, (root, sourcePaths, prepareCommand)) => {
56
- if (args == [] || List . mem(root, args)) {
57
- print_endline("\027 [43;30m# Example " ++ root ++ "\027 [0m" );
58
- let root = Filename . concat(baseDir, Filename . concat("examples" , root));
59
- print_endline("Running \027 [32m" ++ prepareCommand ++ "\027 [0m in " ++ root);
60
- let (stdout , stderr , success ) = Util . Commands . execFull(~pwd= root, prepareCommand);
61
- if (! success) {
62
- [ ` Project (root, prepareCommand, stdout @ stderr), ... failures]
63
- } else {
64
- let sourcePaths = sourcePaths-> Belt . List . map(Filename . concat(root));
65
- checkExampleProject(root, sourcePaths) @ failures
66
- }
67
- } else {
68
- failures
69
- }
85
+ let {describe, describeSkip, describeOnly} =
86
+ describeConfig
87
+ |> withLifecycle(testLifecycle =>
88
+ testLifecycle
89
+ |> beforeEach(() => {
90
+ let (stdout , stderr , success ) = Util . Commands . execFull(~pwd= root, prepareCommand);
91
+ if (! success) {
92
+ failwith ("Unable to run " ++ prepareCommand ++ " in " ++ root)
93
+ }
94
+ })
95
+ )
96
+ |> build;
97
+
98
+ // print_endline("\027[43;30m# Example " ++ root ++ "\027[0m");
99
+ // print_endline("Running \027[32m" ++ prepareCommand ++ "\027[0m in " ++ root);
100
+ // test("Setup Project", ({expect}) => {
101
+ // expect.bool(success).toBeTrue()
102
+ // });
103
+ // if (!success) {
104
+ // [`Project(root, prepareCommand, stdout @ stderr), ...failures]
105
+ // } else {
106
+ let sourcePaths = sourcePaths-> Belt . List . map(Filename . concat(root));
107
+ // sourcePaths->Belt.List.forEach(sourcePath => {
108
+ // describe(sourcePath, ({test}) => checkExampleProject(root, sourcePath))
109
+ // })
110
+ checkExampleProject(root, sourcePaths)
111
+ // }
112
+ })
113
+ // } else {
114
+ // failures
115
+ // }
70
116
})
71
- };
117
+ // };
72
118
73
- let (verbose , args ) = Belt . List . reduce(Belt . List . fromArray(Sys . argv)-> List . tl, (false , [] ), ((verbose, args), arg) => switch arg {
74
- | "-v" | "--verbose" => (true , args)
75
- | _ => (verbose, [ arg, ... args] )
76
- });
77
- if (verbose) {
78
- Util . Log . spamError := true ;
79
- };
80
- let failures = main(Sys . getcwd() , verbose, List . rev(args));
119
+ // let (verbose, args) = Belt.List.reduce(Belt.List.fromArray(Sys.argv)->List.tl, (false, []), ((verbose, args), arg) => switch arg {
120
+ // | "-v" | "--verbose" => (true, args)
121
+ // | _ => (verbose, [arg, ...args])
122
+ // });
123
+
124
+ // if (verbose) {
125
+ // Util.Log.spamError := true;
126
+ // };
127
+ // let failures = main(Sys.getcwd(), verbose, List.rev(args));
81
128
82
- if (failures == [] ) {
83
- print_endline("\n\027 [42;30m## All clear! ##\027 [0m" );
84
- exit(0 );
85
- } else {
86
- print_endline("\n\027 [41;30m## Tests failed! ##\027 [0m" );
87
- failures-> Belt . List . forEach(failure => switch failure {
88
- | ` Project (root , prepareCommand , output ) =>
89
- print_endline("- Project prepare failed: " ++ root ++ " : " ++ prepareCommand);
90
- print_endline(" " ++ String . concat("\n " , output));
91
- | ` PackageFail (uri , message ) => print_endline("- Failed to get package for " ++ uri ++ " : " ++ message)
92
- | ` FileFail (uri , message ) => print_endline("- Failed to get compilation info for " ++ uri ++ " : " ++ message)
93
- });
94
- exit(10 )
95
- }
129
+ // if (failures == []) {
130
+ // print_endline("\n\027[42;30m## All clear! ##\027[0m");
131
+ // exit(0);
132
+ // } else {
133
+ // print_endline("\n\027[41;30m## Tests failed! ##\027[0m");
134
+ // failures->Belt.List.forEach(failure => switch failure {
135
+ // | `Project(root, prepareCommand, output) =>
136
+ // print_endline("- Project prepare failed: " ++ root ++ " : " ++ prepareCommand);
137
+ // print_endline(" " ++ String.concat("\n ", output));
138
+ // | `PackageFail(uri, message) => print_endline("- Failed to get package for " ++ uri ++ " : " ++ message)
139
+ // | `FileFail(uri, message) => print_endline("- Failed to get compilation info for " ++ uri ++ " : " ++ message)
140
+ // });
141
+ // exit(10)
142
+ // }
0 commit comments