This repository has been archived by the owner on Jan 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
185 lines (159 loc) · 5.42 KB
/
cli.js
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
"use strict";
const fs = require('fs');
const path = require('path');
const nodeunit = require('nodeunit');
const compiler = require('../dist/cli/Compiler')['commandLine'];
const interpreter = require('../dist/cli/Interpreter')['commandLine'];
const helpers = require('./helpers');
const createConsole = helpers.createConsole;
const fate = require('../dist/Fate');
const runtime = require('../dist/runtime');
const baseDir = './test/assets';
exports.cli = nodeunit.testCase({
"Command Line Help": function (test) {
let cons = createConsole();
compiler([], cons, function () {
test.ok(cons.contains("Usage"));
test.done();
});
},
"Bad Arguments": function (test) {
let cons = createConsole();
compiler(["--poo"], cons, function () {
test.ok(cons.contains("Usage"));
test.done();
});
},
"Successful Compile": function (test) {
let cons = createConsole();
compiler([`${baseDir}/cli_success/*.fate`], cons, function () {
test.ok(cons.contains("Fate Compilation Complete"));
test.ok(cons.contains("Success"));
test.ok(!cons.contains("Warnings"));
test.ok(!cons.contains("Failures"));
helpers.monkeyPatchRequires('./test', {
'fatejs': '../../../dist/Fate'
});
let compiled = require('./assets/cli_success/test1.js');
test.ok(runtime.isObject(compiled));
// cleanup
fs.unlinkSync(`${baseDir}/cli_success/test1.js`);
fs.unlinkSync(`${baseDir}/cli_success/test2.js`);
test.done();
});
},
"Warning Compile": function (test) {
let cons = createConsole();
compiler([`${baseDir}/cli_warning/*.fate`], cons, function () {
test.ok(cons.contains("Fate Compilation Complete"));
test.ok(cons.contains("Success"));
test.ok(cons.contains("Warnings"));
test.ok(cons.contains("unguarded Function 'query' will replace " +
"the previous definition(s)"));
test.ok(cons.contains("sure you wanted to immediately reassign 'a'?"));
test.ok(cons.contains("sure you wanted to immediately reassign 'b'?"));
test.ok(!cons.contains("Failures"));
fs.unlinkSync(`${baseDir}/cli_warning/test1.js`); // cleanup
test.done();
});
},
"Failure Compile": function (test) {
let cons = createConsole();
compiler(["--in", `${baseDir}/cli_failure/`], cons, function () {
test.ok(cons.contains("Fate Compilation Complete"));
test.ok(!cons.contains("Success"));
test.ok(!cons.contains("Warnings"));
test.ok(cons.contains("Failures"));
test.ok(cons.contains("Unexpected 'a'"));
test.done();
});
},
"Empty Path": function (test) {
let cons = createConsole();
compiler([`${baseDir}/cli_empty/*.fate`], cons, function () {
test.ok(!cons.contains("Fate Compilation Complete"));
test.ok(!cons.contains("Success"));
test.ok(!cons.contains("Warnings"));
test.ok(cons.contains("Error!"));
test.ok(cons.contains("No files found matching"));
test.done();
});
},
"Parse Only": function (test) {
let cons = createConsole();
compiler(["--parse", `${baseDir}/cli_success/*.fate`], cons, function () {
test.ok(cons.contains("Fate Compilation Complete"));
test.ok(cons.contains("Success"));
test.ok(!cons.contains("Warnings"));
test.ok(!cons.contains("Failures"));
test.done();
});
},
"Clean Compiled Files": function (test) {
let cons = createConsole();
compiler([`${baseDir}/cli_success/*.fate`], cons, function () {
test.ok(cons.contains("Fate Compilation Complete"));
test.ok(cons.contains("Success"));
test.ok(!cons.contains("Warnings"));
test.ok(!cons.contains("Failures"));
compiler(["--clean", `${baseDir}/**/*.fate`], cons, function () {
test.ok(cons.contains("Deleted: 2"));
test.done();
});
});
},
"Mutually Exclusive Actions": function (test) {
let cons = createConsole();
compiler(["--clean", "--parse"], cons, function () {
test.ok(cons.contains("Error!"));
test.ok(cons.contains("Only one action can be performed"));
test.done();
});
},
"Multiple Input Paths": function (test) {
let cons = createConsole();
compiler(["--parse", `${baseDir}/cli_success/*.fate`,
`${baseDir}/cli_warning/*.fate`], cons, function () {
test.ok(cons.contains("Fate Compilation Complete"));
test.ok(cons.contains("Success"));
test.ok(cons.contains("Warnings"));
test.ok(!cons.contains("Failures"));
test.done();
});
},
"Interpreter": function (test) {
let cons, logHolder;
start();
function start() {
cons = createConsole();
logHolder = console.log;
console.log = cons.log.bind(cons.log);
successTest();
}
function successTest() {
interpreter([`${baseDir}/hello`], cons, function (exitCode) {
test.equal(exitCode, 0);
test.ok(cons.contains("Hello, World!"));
noArgsTest();
});
}
function noArgsTest() {
interpreter([], cons, function (exitCode) {
test.equal(exitCode, 0);
test.ok(cons.contains("Usage"));
badArgsTest();
});
}
function badArgsTest() {
interpreter(["--poop"], cons, function (exitCode) {
test.equal(exitCode, -1);
test.ok(cons.contains("Usage"));
finish();
});
}
function finish() {
console.log = logHolder;
test.done();
}
}
});