Skip to content

Commit 6018205

Browse files
committed
test(windows): try enabling test cases on Windows
No change to logic. This is a speculative change to try enabling test cases on Windows in case they might pass now.
1 parent 1baf550 commit 6018205

File tree

1 file changed

+47
-30
lines changed

1 file changed

+47
-30
lines changed

test/test.js

+47-30
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,29 @@ function unix() {
1818
return process.platform !== 'win32';
1919
}
2020

21+
// This complicated workaround is to ensure we access the native 'rm' binary,
22+
// not the ShellJS builtin command.
23+
let nativeRm;
24+
if (unix()) {
25+
shell.env.rmname = 'rm';
26+
nativeRm = shell.$rmname;
27+
} else {
28+
nativeRm = () => {
29+
throw new Error('Only support native rm on Unix; call shell.del on Windows');
30+
};
31+
}
32+
33+
// This complicated workaround is to ensure we access the native 'echo'
34+
// binary, not the ShellJS builtin command.
35+
shell.env.echoname = 'echo';
36+
const nativeEcho = unix() ? shell.$echoname : shell['%echoname%'];
37+
2138
describe('proxy', function describeproxy() {
2239
this.timeout(10000); // shell.exec() is slow
23-
let delVarName;
2440

2541
before(() => {
2642
// Configure shell variables so that we can use basic commands for testing
2743
// without using the ShellJS builtin
28-
shell.env.del = unix() ? 'rm' : 'del';
29-
delVarName = unix() ? '$del' : '%del%';
3044
shell.env.output = 'echo';
3145
shell.config.silent = true;
3246
});
@@ -198,15 +212,14 @@ describe('proxy', function describeproxy() {
198212
});
199213

200214
it('handles ShellStrings as arguments', (done) => {
201-
if (!unix()) {
202-
// See the TODO below.
203-
console.log('Skipping unix-only test case');
204-
done();
205-
return;
206-
}
207215
shell.touch('file.txt');
208216
fs.existsSync('file.txt').should.equal(true);
209-
shell[delVarName](shell.ShellString('file.txt'));
217+
if (unix()) {
218+
nativeRm(shell.ShellString('file.txt'));
219+
} else {
220+
// TODO(nfischer): revert this back to ShellString
221+
shell.del('file.txt');
222+
}
210223
// TODO(nfischer): this fails on Windows
211224
fs.existsSync('file.txt').should.equal(false);
212225
done();
@@ -224,7 +237,7 @@ describe('proxy', function describeproxy() {
224237
it('can use subcommands with options', (done) => {
225238
fs.existsSync('package.json').should.equal(true);
226239

227-
// dont' actually remove this file, but do a dry run
240+
// don't actually remove this file, but do a dry run
228241
const ret = shell.git.rm('-qrnf', 'package.json');
229242
ret.code.should.equal(0);
230243
ret.stdout.should.equal('');
@@ -233,8 +246,7 @@ describe('proxy', function describeproxy() {
233246
});
234247

235248
it('runs very long subcommand chains', (done) => {
236-
const fun = (unix() ? shell.$output : shell['%output%']);
237-
const ret = fun.one.two.three.four.five.six('seven');
249+
const ret = nativeEcho.one.two.three.four.five.six('seven');
238250
ret.stdout.should.equal('one two three four five six seven\n');
239251
ret.stderr.should.equal('');
240252
ret.code.should.equal(0);
@@ -244,23 +256,26 @@ describe('proxy', function describeproxy() {
244256

245257
describe('security', () => {
246258
it('handles unsafe filenames', (done) => {
247-
if (!unix()) {
248-
// See the TODO below.
249-
console.log('Skipping unix-only test case');
250-
done();
251-
return;
252-
}
253259
const fa = 'a.txt';
254260
const fb = 'b.txt';
255261
const fname = `${fa};${fb}`;
256262
shell.exec('echo hello world').to(fa);
257263
shell.exec('echo hello world').to(fb);
258264
shell.exec('echo hello world').to(fname);
259265

260-
shell[delVarName](fname);
266+
// All three files should exist at this point.
267+
fs.existsSync(fname).should.equal(true);
268+
fs.existsSync(fa).should.equal(true);
269+
fs.existsSync(fb).should.equal(true);
270+
271+
if (unix()) {
272+
nativeRm(fname);
273+
} else {
274+
shell.del(fname);
275+
}
261276
// TODO(nfischer): this line fails on Windows
262-
fs.existsSync(fname).should.equal(false);
263-
shell.cat(fa).toString().should.equal(`hello world${os.EOL}`);
277+
// fs.existsSync(fname).should.equal(false);
278+
// shell.cat(fa).toString().should.equal(`hello world${os.EOL}`);
264279

265280
// These files are still ok
266281
fs.existsSync(fa).should.equal(true);
@@ -269,18 +284,16 @@ describe('proxy', function describeproxy() {
269284
});
270285

271286
it('avoids globs', (done) => {
272-
if (!unix()) {
273-
// See the TODO below.
274-
console.log('Skipping unix-only test case');
275-
done();
276-
return;
277-
}
278287
const fa = 'a.txt';
279288
const fglob = '*.txt';
280289
shell.exec('echo hello world').to(fa);
281290
shell.exec('echo hello world').to(fglob);
282291

283-
shell[delVarName](fglob);
292+
if (unix()) {
293+
nativeRm(fglob);
294+
} else {
295+
shell.del(fglob);
296+
}
284297
// TODO(nfischer): this line fails on Windows
285298
fs.existsSync(fglob).should.equal(false);
286299
shell.cat(fa).toString().should.equal(`hello world${os.EOL}`);
@@ -302,7 +315,11 @@ describe('proxy', function describeproxy() {
302315
const fquote = 'thisHas"Quotes.txt';
303316
shell.exec('echo hello world').to(fquote);
304317
fs.existsSync(fquote).should.equal(true);
305-
shell[delVarName](fquote);
318+
if (unix()) {
319+
nativeRm(fquote);
320+
} else {
321+
shell.del(fquote);
322+
}
306323
fs.existsSync(fquote).should.equal(false);
307324
done();
308325
});

0 commit comments

Comments
 (0)