Skip to content

Commit

Permalink
test: use os.EOL and various cross-platform fixes.
Browse files Browse the repository at this point in the history
This is one PR in a series to test and ensure Windows compatibility.

Issue #7
  • Loading branch information
nfischer committed Mar 17, 2018
1 parent 02cc0c4 commit 84d47a3
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const shell = require('../index');
const origShell = require('shelljs');
const assert = require('assert');
const fs = require('fs');
const os = require('os');
const cmdArrayAttr = require('../common').cmdArrayAttr;
require('should');

Expand Down Expand Up @@ -139,7 +140,8 @@ describe('proxy', () => {
const ret1 = shell.du(fname);
const ret2 = shell.exec(`du ${fname}`);
assertShellStringEqual(ret1, ret2);
ret1.stdout.should.equal(`0\t${fname}\n`);
// Don't assert the file size, since that may be OS dependent.
ret1.stdout.should.endWith(`\t${fname}${os.EOL}`);
} else {
console.log('skipping test');
}
Expand Down Expand Up @@ -193,6 +195,7 @@ describe('proxy', () => {
shell.touch('file.txt');
fs.existsSync('file.txt').should.equal(true);
shell[delVarName](shell.ShellString('file.txt'));
// TODO(nfischer): this fails on Windows
fs.existsSync('file.txt').should.equal(false);
done();
});
Expand All @@ -218,9 +221,9 @@ describe('proxy', () => {
});

it('runs very long subcommand chains', (done) => {
const fun = (unix() ? shell.$output : shell['%output']);
const fun = (unix() ? shell.$output : shell['%output%']);
const ret = fun.one.two.three.four.five.six('seven');
ret.stdout.should.equal('one two three four five six seven\n');
ret.stdout.should.equal(`one two three four five six seven${os.EOL}`);
ret.stderr.should.equal('');
ret.code.should.equal(0);
done();
Expand All @@ -238,7 +241,7 @@ describe('proxy', () => {

shell[delVarName](fname);
fs.existsSync(fname).should.equal(false);
shell.cat(fa).toString().should.equal('hello world\n');
shell.cat(fa).toString().should.equal(`hello world${os.EOL}`);

// These files are still ok
fs.existsSync(fa).should.equal(true);
Expand All @@ -253,8 +256,9 @@ describe('proxy', () => {
shell.exec('echo hello world').to(fglob);

shell[delVarName](fglob);
// TODO(nfischer): this line fails on Windows
fs.existsSync(fglob).should.equal(false);
shell.cat(fa).toString().should.equal('hello world\n');
shell.cat(fa).toString().should.equal(`hello world${os.EOL}`);

// These files are still ok
fs.existsSync(fa).should.equal(true);
Expand Down

0 comments on commit 84d47a3

Please sign in to comment.