|
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,163 @@ 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 | + // Shows build help with --help arg |
| 78 | + const out = await exec(`../../../rescript`, ["build", "--help"]); |
| 79 | + assert.equal(out.stdout, buildHelp); |
| 80 | + assert.equal(out.stderr, ""); |
| 81 | + assert.equal(out.status, 0); |
| 82 | + } |
| 83 | + |
| 84 | + { |
| 85 | + const out = await exec(`../../../rescript`, ["build", "-w", "--help"]); |
| 86 | + assert.equal(out.stdout, buildHelp); |
| 87 | + assert.equal(out.stderr, ""); |
| 88 | + assert.equal(out.status, 0); |
| 89 | + } |
| 90 | + |
| 91 | + { |
| 92 | + const out = await exec(`../../../rescript`, ["-w", "--help"]); |
| 93 | + assert.equal(out.stdout, cliHelp); |
| 94 | + assert.equal(out.stderr, ""); |
| 95 | + assert.equal(out.status, 0); |
| 96 | + } |
| 97 | + |
| 98 | + { |
| 99 | + // Shows cli help with --help arg even if there are invalid arguments after it |
| 100 | + const out = await exec(`../../../rescript`, ["--help", "-w"]); |
| 101 | + assert.equal(out.stdout, cliHelp); |
| 102 | + assert.equal(out.stderr, ""); |
| 103 | + assert.equal(out.status, 0); |
| 104 | + } |
| 105 | + |
| 106 | + { |
| 107 | + // Shows build help with -h arg |
| 108 | + const out = await exec(`../../../rescript`, ["build", "-h"]); |
| 109 | + assert.equal(out.stdout, buildHelp); |
| 110 | + assert.equal(out.stderr, ""); |
| 111 | + assert.equal(out.status, 0); |
| 112 | + } |
| 113 | + |
| 114 | + { |
| 115 | + // Exits with build help with unknown arg |
| 116 | + const out = await exec(`../../../rescript`, ["build", "-foo"]); |
| 117 | + assert.equal(out.stdout, ""); |
| 118 | + assert.equal(out.stderr, 'Error: Unknown option "-foo".\n' + buildHelp); |
| 119 | + assert.equal(out.status, 2); |
| 120 | + } |
| 121 | + |
| 122 | + { |
| 123 | + // Shows cli help with --help arg |
| 124 | + const out = await exec(`../../../rescript`, ["--help"]); |
| 125 | + assert.equal(out.stdout, cliHelp); |
| 126 | + assert.equal(out.stderr, ""); |
| 127 | + assert.equal(out.status, 0); |
| 128 | + } |
| 129 | + |
| 130 | + { |
| 131 | + // Shows cli help with -h arg |
| 132 | + const out = await exec(`../../../rescript`, ["-h"]); |
| 133 | + assert.equal(out.stdout, cliHelp); |
| 134 | + assert.equal(out.stderr, ""); |
| 135 | + assert.equal(out.status, 0); |
| 136 | + } |
| 137 | + |
| 138 | + { |
| 139 | + // Shows cli help with -h arg |
| 140 | + const out = await exec(`../../../rescript`, ["help"]); |
| 141 | + assert.equal(out.stdout, cliHelp); |
| 142 | + assert.equal(out.stderr, ""); |
| 143 | + assert.equal(out.status, 0); |
| 144 | + } |
| 145 | + |
| 146 | + { |
| 147 | + const out = await exec(`../../../rescript`, ["built"]); |
| 148 | + assert.equal(out.stdout, ""); |
| 149 | + assert.equal(out.stderr, `Error: Unknown command "built".\n` + cliHelp); |
| 150 | + assert.equal(out.status, 2); |
| 151 | + } |
| 152 | + |
| 153 | + { |
| 154 | + // Exits with build help with unknown args |
| 155 | + const out = await exec(`../../../rescript`, ["-foo"]); |
| 156 | + assert.equal(out.stdout, ""); |
| 157 | + assert.equal(out.stderr, 'Error: Unknown option "-foo".\n' + buildHelp); |
| 158 | + assert.equal(out.status, 2); |
| 159 | + } |
| 160 | + |
| 161 | + { |
| 162 | + // Shows clean help with --help arg |
| 163 | + const out = await exec(`../../../rescript`, ["clean", "--help"]); |
| 164 | + assert.equal(out.stdout, cleanHelp); |
| 165 | + assert.equal(out.stderr, ""); |
| 166 | + assert.equal(out.status, 0); |
| 167 | + } |
| 168 | + |
| 169 | + { |
| 170 | + // Shows clean help with -h arg |
| 171 | + const out = await exec(`../../../rescript`, ["clean", "-h"]); |
| 172 | + assert.equal(out.stdout, cleanHelp); |
| 173 | + assert.equal(out.stderr, ""); |
| 174 | + assert.equal(out.status, 0); |
| 175 | + } |
| 176 | + |
| 177 | + { |
| 178 | + // Exits with clean help with unknown arg |
| 179 | + const out = await exec(`../../../rescript`, ["clean", "-foo"]); |
| 180 | + assert.equal(out.stdout, ""); |
| 181 | + assert.equal(out.stderr, 'Error: Unknown option "-foo".\n' + cleanHelp); |
| 182 | + assert.equal(out.status, 2); |
| 183 | + } |
| 184 | + |
| 185 | + { |
| 186 | + // Shows format help with --help arg |
| 187 | + const out = await exec(`../../../rescript format`, ["--help"]); |
| 188 | + assert.equal(out.stdout, formatHelp); |
| 189 | + assert.equal(out.stderr, ""); |
| 190 | + assert.equal(out.status, 0); |
| 191 | + } |
| 192 | + |
| 193 | + { |
| 194 | + // Shows format help with -h arg |
| 195 | + const out = await exec(`../../../rescript format`, ["-h"]); |
| 196 | + assert.equal(out.stdout, formatHelp); |
| 197 | + assert.equal(out.stderr, ""); |
| 198 | + assert.equal(out.status, 0); |
| 199 | + } |
| 200 | + |
| 201 | + { |
| 202 | + // Shows convert help with --help arg |
| 203 | + const out = await exec(`../../../rescript convert`, ["--help"]); |
| 204 | + assert.equal(out.stdout, convertHelp); |
| 205 | + assert.equal(out.stderr, ""); |
| 206 | + assert.equal(out.status, 0); |
| 207 | + } |
| 208 | + |
| 209 | + { |
| 210 | + // Shows convert help with -h arg |
| 211 | + const out = await exec(`../../../rescript convert`, ["-h"]); |
| 212 | + assert.equal(out.stdout, convertHelp); |
| 213 | + assert.equal(out.stderr, ""); |
| 214 | + assert.equal(out.status, 0); |
| 215 | + } |
| 216 | + |
| 217 | + { |
| 218 | + // Shows dump help with --help arg |
| 219 | + const out = await exec(`../../../rescript dump`, ["--help"]); |
| 220 | + assert.equal(out.stdout, dumpHelp); |
| 221 | + assert.equal(out.stderr, ""); |
| 222 | + assert.equal(out.status, 0); |
| 223 | + } |
| 224 | + |
| 225 | + { |
| 226 | + // Shows dump help with -h arg |
| 227 | + const out = await exec(`../../../rescript dump`, ["-h"]); |
| 228 | + assert.equal(out.stdout, dumpHelp); |
| 229 | + assert.equal(out.stderr, ""); |
| 230 | + assert.equal(out.status, 0); |
| 231 | + } |
| 232 | +} |
| 233 | + |
| 234 | +void test(); |
0 commit comments