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