|
1 | 1 | // @ts-check
|
2 | 2 |
|
3 | 3 | const assert = require("assert");
|
4 |
| -const child_process = require("child_process"); |
| 4 | +const { exec } = require("../utils.js"); |
5 | 5 |
|
6 | 6 | const cliHelp =
|
7 | 7 | "Usage: rescript <options> <subcommand>\n" +
|
@@ -72,194 +72,204 @@ const dumpHelp =
|
72 | 72 | "Usage: rescript dump <options> [target]\n" +
|
73 | 73 | "`rescript dump` dumps the information for the target\n";
|
74 | 74 |
|
75 |
| -// Shows build help with --help arg |
76 |
| -let out = child_process.spawnSync(`../../../rescript`, ["build", "--help"], { |
77 |
| - encoding: "utf8", |
78 |
| - cwd: __dirname, |
79 |
| -}); |
80 |
| -assert.equal(out.stdout, buildHelp); |
81 |
| -assert.equal(out.stderr, ""); |
82 |
| -assert.equal(out.status, 0); |
| 75 | +async function test() { |
| 76 | + { |
| 77 | + // Shows build help with --help arg |
| 78 | + const out = await exec(`../../../rescript`, ["build", "--help"], { |
| 79 | + cwd: __dirname, |
| 80 | + }); |
| 81 | + assert.equal(out.stdout, buildHelp); |
| 82 | + assert.equal(out.stderr, ""); |
| 83 | + assert.equal(out.status, 0); |
| 84 | + } |
83 | 85 |
|
84 |
| -// FIXME: Help works incorrectly in watch mode |
85 |
| -out = child_process.spawnSync(`../../../rescript`, ["build", "-w", "--help"], { |
86 |
| - encoding: "utf8", |
87 |
| - cwd: __dirname, |
88 |
| -}); |
89 |
| -// FIXME: Shouldn't have "Start compiling" for help |
90 |
| -assert.equal(out.stdout, ">>>> Start compiling\n" + buildHelp); |
91 |
| -// FIXME: Don't run the watcher when showing help |
92 |
| -assert.match( |
93 |
| - out.stderr, |
94 |
| - new RegExp( |
95 |
| - "Uncaught Exception Error: ENOENT: no such file or directory, watch 'bsconfig.json'\n" |
96 |
| - ) |
97 |
| -); |
98 |
| -// FIXME: Should be 0 |
99 |
| -assert.equal(out.status, 1); |
| 86 | + { |
| 87 | + const out = await exec(`../../../rescript`, ["build", "-w", "--help"], { |
| 88 | + cwd: __dirname, |
| 89 | + }); |
| 90 | + assert.equal(out.stdout, buildHelp); |
| 91 | + assert.equal(out.stderr, ""); |
| 92 | + assert.equal(out.status, 0); |
| 93 | + } |
100 | 94 |
|
101 |
| -// FIXME: Has the same problem with `rescript -w` |
102 |
| -out = child_process.spawnSync(`../../../rescript`, ["-w", "--help"], { |
103 |
| - encoding: "utf8", |
104 |
| - cwd: __dirname, |
105 |
| -}); |
106 |
| -assert.equal(out.stdout, ">>>> Start compiling\n" + buildHelp); |
107 |
| -assert.match( |
108 |
| - out.stderr, |
109 |
| - new RegExp( |
110 |
| - "Uncaught Exception Error: ENOENT: no such file or directory, watch 'bsconfig.json'\n" |
111 |
| - ) |
112 |
| -); |
| 95 | + { |
| 96 | + const out = await exec(`../../../rescript`, ["-w", "--help"], { |
| 97 | + cwd: __dirname, |
| 98 | + }); |
| 99 | + assert.equal(out.stdout, cliHelp); |
| 100 | + assert.equal(out.stderr, ""); |
| 101 | + assert.equal(out.status, 0); |
| 102 | + } |
113 | 103 |
|
114 |
| -// Shows cli help with --help arg even if there are invalid arguments after it |
115 |
| -out = child_process.spawnSync(`../../../rescript`, ["--help", "-w"], { |
116 |
| - encoding: "utf8", |
117 |
| - cwd: __dirname, |
118 |
| -}); |
119 |
| -assert.equal(out.stdout, cliHelp); |
120 |
| -assert.equal(out.stderr, ""); |
121 |
| -assert.equal(out.status, 0); |
| 104 | + { |
| 105 | + // Shows cli help with --help arg even if there are invalid arguments after it |
| 106 | + const out = await exec(`../../../rescript`, ["--help", "-w"], { |
| 107 | + cwd: __dirname, |
| 108 | + }); |
| 109 | + assert.equal(out.stdout, cliHelp); |
| 110 | + assert.equal(out.stderr, ""); |
| 111 | + assert.equal(out.status, 0); |
| 112 | + } |
122 | 113 |
|
123 |
| -// Shows build help with -h arg |
124 |
| -out = child_process.spawnSync(`../../../rescript`, ["build", "-h"], { |
125 |
| - encoding: "utf8", |
126 |
| - cwd: __dirname, |
127 |
| -}); |
128 |
| -assert.equal(out.stdout, buildHelp); |
129 |
| -assert.equal(out.stderr, ""); |
130 |
| -assert.equal(out.status, 0); |
| 114 | + { |
| 115 | + // Shows build help with -h arg |
| 116 | + const out = await exec(`../../../rescript`, ["build", "-h"], { |
| 117 | + cwd: __dirname, |
| 118 | + }); |
| 119 | + assert.equal(out.stdout, buildHelp); |
| 120 | + assert.equal(out.stderr, ""); |
| 121 | + assert.equal(out.status, 0); |
| 122 | + } |
131 | 123 |
|
132 |
| -// Exits with build help with unknown arg |
133 |
| -out = child_process.spawnSync(`../../../rescript`, ["build", "-foo"], { |
134 |
| - encoding: "utf8", |
135 |
| - cwd: __dirname, |
136 |
| -}); |
137 |
| -assert.equal(out.stdout, ""); |
138 |
| -assert.equal(out.stderr, 'Error: Unknown option "-foo".\n' + buildHelp); |
139 |
| -assert.equal(out.status, 2); |
| 124 | + { |
| 125 | + // Exits with build help with unknown arg |
| 126 | + const out = await exec(`../../../rescript`, ["build", "-foo"], { |
| 127 | + cwd: __dirname, |
| 128 | + }); |
| 129 | + assert.equal(out.stdout, ""); |
| 130 | + assert.equal(out.stderr, 'Error: Unknown option "-foo".\n' + buildHelp); |
| 131 | + assert.equal(out.status, 2); |
| 132 | + } |
140 | 133 |
|
141 |
| -// Shows cli help with --help arg |
142 |
| -out = child_process.spawnSync(`../../../rescript`, ["--help"], { |
143 |
| - encoding: "utf8", |
144 |
| - cwd: __dirname, |
145 |
| -}); |
146 |
| -assert.equal(out.stdout, cliHelp); |
147 |
| -assert.equal(out.stderr, ""); |
148 |
| -assert.equal(out.status, 0); |
| 134 | + { |
| 135 | + // Shows cli help with --help arg |
| 136 | + const out = await exec(`../../../rescript`, ["--help"], { |
| 137 | + cwd: __dirname, |
| 138 | + }); |
| 139 | + assert.equal(out.stdout, cliHelp); |
| 140 | + assert.equal(out.stderr, ""); |
| 141 | + assert.equal(out.status, 0); |
| 142 | + } |
149 | 143 |
|
150 |
| -// Shows cli help with -h arg |
151 |
| -out = child_process.spawnSync(`../../../rescript`, ["-h"], { |
152 |
| - encoding: "utf8", |
153 |
| - cwd: __dirname, |
154 |
| -}); |
155 |
| -assert.equal(out.stdout, cliHelp); |
156 |
| -assert.equal(out.stderr, ""); |
157 |
| -assert.equal(out.status, 0); |
| 144 | + { |
| 145 | + // Shows cli help with -h arg |
| 146 | + const out = await exec(`../../../rescript`, ["-h"], { |
| 147 | + cwd: __dirname, |
| 148 | + }); |
| 149 | + assert.equal(out.stdout, cliHelp); |
| 150 | + assert.equal(out.stderr, ""); |
| 151 | + assert.equal(out.status, 0); |
| 152 | + } |
158 | 153 |
|
159 |
| -// Shows cli help with help command |
160 |
| -out = child_process.spawnSync(`../../../rescript`, ["help"], { |
161 |
| - encoding: "utf8", |
162 |
| - cwd: __dirname, |
163 |
| -}); |
164 |
| -assert.equal(out.stdout, cliHelp); |
165 |
| -assert.equal(out.stderr, ""); |
166 |
| -assert.equal(out.status, 0); |
| 154 | + { |
| 155 | + // Shows cli help with -h arg |
| 156 | + const out = await exec(`../../../rescript`, ["help"], { |
| 157 | + cwd: __dirname, |
| 158 | + }); |
| 159 | + assert.equal(out.stdout, cliHelp); |
| 160 | + assert.equal(out.stderr, ""); |
| 161 | + assert.equal(out.status, 0); |
| 162 | + } |
167 | 163 |
|
168 |
| -// Exits with cli help with unknown command |
169 |
| -out = child_process.spawnSync(`../../../rescript`, ["built"], { |
170 |
| - encoding: "utf8", |
171 |
| - cwd: __dirname, |
172 |
| -}); |
173 |
| -assert.equal(out.stdout, ""); |
174 |
| -assert.equal(out.stderr, `Error: Unknown command "built".\n` + cliHelp); |
175 |
| -assert.equal(out.status, 2); |
| 164 | + { |
| 165 | + // Exits with cli help with unknown command |
| 166 | + const out = await exec(`../../../rescript`, ["built"], { |
| 167 | + cwd: __dirname, |
| 168 | + }); |
| 169 | + assert.equal(out.stdout, ""); |
| 170 | + assert.equal(out.stderr, `Error: Unknown command "built".\n` + cliHelp); |
| 171 | + assert.equal(out.status, 2); |
| 172 | + } |
176 | 173 |
|
177 |
| -// Exits with build help with unknown args |
178 |
| -out = child_process.spawnSync(`../../../rescript`, ["-foo"], { |
179 |
| - encoding: "utf8", |
180 |
| - cwd: __dirname, |
181 |
| -}); |
182 |
| -assert.equal(out.stdout, ""); |
183 |
| -assert.equal(out.stderr, 'Error: Unknown option "-foo".\n' + buildHelp); |
184 |
| -assert.equal(out.status, 2); |
| 174 | + { |
| 175 | + // Exits with build help with unknown args |
| 176 | + const out = await exec(`../../../rescript`, ["-foo"], { |
| 177 | + cwd: __dirname, |
| 178 | + }); |
| 179 | + assert.equal(out.stdout, ""); |
| 180 | + assert.equal(out.stderr, 'Error: Unknown option "-foo".\n' + buildHelp); |
| 181 | + assert.equal(out.status, 2); |
| 182 | + } |
185 | 183 |
|
186 |
| -// Shows clean help with --help arg |
187 |
| -out = child_process.spawnSync(`../../../rescript`, ["clean", "--help"], { |
188 |
| - encoding: "utf8", |
189 |
| - cwd: __dirname, |
190 |
| -}); |
191 |
| -assert.equal(out.stdout, cleanHelp); |
192 |
| -assert.equal(out.stderr, ""); |
193 |
| -assert.equal(out.status, 0); |
| 184 | + { |
| 185 | + // Shows clean help with --help arg |
| 186 | + const out = await exec(`../../../rescript`, ["clean", "--help"], { |
| 187 | + cwd: __dirname, |
| 188 | + }); |
| 189 | + assert.equal(out.stdout, cleanHelp); |
| 190 | + assert.equal(out.stderr, ""); |
| 191 | + assert.equal(out.status, 0); |
| 192 | + } |
194 | 193 |
|
195 |
| -// Shows clean help with -h arg |
196 |
| -out = child_process.spawnSync(`../../../rescript`, ["clean", "-h"], { |
197 |
| - encoding: "utf8", |
198 |
| - cwd: __dirname, |
199 |
| -}); |
200 |
| -assert.equal(out.stdout, cleanHelp); |
201 |
| -assert.equal(out.stderr, ""); |
202 |
| -assert.equal(out.status, 0); |
| 194 | + { |
| 195 | + // Shows clean help with -h arg |
| 196 | + const out = await exec(`../../../rescript`, ["clean", "-h"], { |
| 197 | + cwd: __dirname, |
| 198 | + }); |
| 199 | + assert.equal(out.stdout, cleanHelp); |
| 200 | + assert.equal(out.stderr, ""); |
| 201 | + assert.equal(out.status, 0); |
| 202 | + } |
203 | 203 |
|
204 |
| -// Exits with clean help with unknown arg |
205 |
| -out = child_process.spawnSync(`../../../rescript`, ["clean", "-foo"], { |
206 |
| - encoding: "utf8", |
207 |
| - cwd: __dirname, |
208 |
| -}); |
209 |
| -assert.equal(out.stdout, ""); |
210 |
| -assert.equal(out.stderr, 'Error: Unknown option "-foo".\n' + cleanHelp); |
211 |
| -assert.equal(out.status, 2); |
| 204 | + { |
| 205 | + // Exits with clean help with unknown arg |
| 206 | + const out = await exec(`../../../rescript`, ["clean", "-foo"], { |
| 207 | + cwd: __dirname, |
| 208 | + }); |
| 209 | + assert.equal(out.stdout, ""); |
| 210 | + assert.equal(out.stderr, 'Error: Unknown option "-foo".\n' + cleanHelp); |
| 211 | + assert.equal(out.status, 2); |
| 212 | + } |
212 | 213 |
|
213 |
| -// Shows format help with --help arg |
214 |
| -out = child_process.spawnSync(`../../../rescript`, ["format", "--help"], { |
215 |
| - encoding: "utf8", |
216 |
| - cwd: __dirname, |
217 |
| -}); |
218 |
| -assert.equal(out.stdout, formatHelp); |
219 |
| -assert.equal(out.stderr, ""); |
220 |
| -assert.equal(out.status, 0); |
| 214 | + { |
| 215 | + // Shows format help with --help arg |
| 216 | + const out = await exec(`../../../rescript format`, ["--help"], { |
| 217 | + cwd: __dirname, |
| 218 | + }); |
| 219 | + assert.equal(out.stdout, formatHelp); |
| 220 | + assert.equal(out.stderr, ""); |
| 221 | + assert.equal(out.status, 0); |
| 222 | + } |
221 | 223 |
|
222 |
| -// Shows format help with -h arg |
223 |
| -out = child_process.spawnSync(`../../../rescript`, ["format", "-h"], { |
224 |
| - encoding: "utf8", |
225 |
| - cwd: __dirname, |
226 |
| -}); |
227 |
| -assert.equal(out.stdout, formatHelp); |
228 |
| -assert.equal(out.stderr, ""); |
229 |
| -assert.equal(out.status, 0); |
| 224 | + { |
| 225 | + // Shows format help with -h arg |
| 226 | + const out = await exec(`../../../rescript format`, ["-h"], { |
| 227 | + cwd: __dirname, |
| 228 | + }); |
| 229 | + assert.equal(out.stdout, formatHelp); |
| 230 | + assert.equal(out.stderr, ""); |
| 231 | + assert.equal(out.status, 0); |
| 232 | + } |
230 | 233 |
|
231 |
| -// Shows convert help with --help arg |
232 |
| -out = child_process.spawnSync(`../../../rescript`, ["convert", "--help"], { |
233 |
| - encoding: "utf8", |
234 |
| - cwd: __dirname, |
235 |
| -}); |
236 |
| -assert.equal(out.stdout, convertHelp); |
237 |
| -assert.equal(out.stderr, ""); |
238 |
| -assert.equal(out.status, 0); |
| 234 | + { |
| 235 | + // Shows convert help with --help arg |
| 236 | + const out = await exec(`../../../rescript convert`, ["--help"], { |
| 237 | + cwd: __dirname, |
| 238 | + }); |
| 239 | + assert.equal(out.stdout, convertHelp); |
| 240 | + assert.equal(out.stderr, ""); |
| 241 | + assert.equal(out.status, 0); |
| 242 | + } |
239 | 243 |
|
240 |
| -// Shows convert help with -h arg |
241 |
| -out = child_process.spawnSync(`../../../rescript`, ["convert", "-h"], { |
242 |
| - encoding: "utf8", |
243 |
| - cwd: __dirname, |
244 |
| -}); |
245 |
| -assert.equal(out.stdout, convertHelp); |
246 |
| -assert.equal(out.stderr, ""); |
247 |
| -assert.equal(out.status, 0); |
| 244 | + { |
| 245 | + // Shows convert help with -h arg |
| 246 | + const out = await exec(`../../../rescript convert`, ["-h"], { |
| 247 | + cwd: __dirname, |
| 248 | + }); |
| 249 | + assert.equal(out.stdout, convertHelp); |
| 250 | + assert.equal(out.stderr, ""); |
| 251 | + assert.equal(out.status, 0); |
| 252 | + } |
248 | 253 |
|
249 |
| -// Shows dump help with --help arg |
250 |
| -out = child_process.spawnSync(`../../../rescript`, ["dump", "--help"], { |
251 |
| - encoding: "utf8", |
252 |
| - cwd: __dirname, |
253 |
| -}); |
254 |
| -assert.equal(out.stdout, dumpHelp); |
255 |
| -assert.equal(out.stderr, ""); |
256 |
| -assert.equal(out.status, 0); |
| 254 | + { |
| 255 | + // Shows dump help with --help arg |
| 256 | + const out = await exec(`../../../rescript dump`, ["--help"], { |
| 257 | + cwd: __dirname, |
| 258 | + }); |
| 259 | + assert.equal(out.stdout, dumpHelp); |
| 260 | + assert.equal(out.stderr, ""); |
| 261 | + assert.equal(out.status, 0); |
| 262 | + } |
257 | 263 |
|
258 |
| -// Shows dump help with -h arg |
259 |
| -out = child_process.spawnSync(`../../../rescript`, ["dump", "-h"], { |
260 |
| - encoding: "utf8", |
261 |
| - cwd: __dirname, |
262 |
| -}); |
263 |
| -assert.equal(out.stdout, dumpHelp); |
264 |
| -assert.equal(out.stderr, ""); |
265 |
| -assert.equal(out.status, 0); |
| 264 | + { |
| 265 | + // Shows dump help with -h arg |
| 266 | + const out = await exec(`../../../rescript dump`, ["-h"], { |
| 267 | + cwd: __dirname, |
| 268 | + }); |
| 269 | + assert.equal(out.stdout, dumpHelp); |
| 270 | + assert.equal(out.stderr, ""); |
| 271 | + assert.equal(out.status, 0); |
| 272 | + } |
| 273 | +} |
| 274 | + |
| 275 | +void test(); |
0 commit comments