diff --git a/tests/test.js b/tests/test.js index f76e9b8a9a4479d0702ea363d335e8bb9c619dd9..fa2351d4619bf090a90a2cddde2bcc0ac9fbeba3 100644 --- a/tests/test.js +++ b/tests/test.js @@ -1,6 +1,8 @@ const fs = require('fs') const test = require('ava') -const {execFilePromise, matchOutput, reorderings, updateExpectedPaths} = require('./util') +const { + execFilePromise, matchOutput, reorderings, updateExpectedPaths, updatePath +} = require('./util') // We are going to run the server directly, not through npm const {INIT_CWD, ...GREP_ENV} = process.env @@ -557,6 +559,8 @@ const TESTS = [ for (const {args, expected} of TESTS) { const flags = args.filter(arg => arg.startsWith('-')) const parameters = args.filter(arg => !arg.startsWith('-')) + // Update all paths in the parameters to have correct separators + for (let i = 1; i < parameters.length; i++) parameters[i] = updatePath(parameters[i]) for (const args of reorderings(parameters, flags)) { test(`grep ${args.join(' ')}`, async t => { const {stdout} = await execFilePromise( @@ -573,7 +577,7 @@ test('grep no matches', async t => { let stdout try { ({stdout} = await execFilePromise( - 'node', ['../grep.js', 'no-such-string', 'files/independence.txt'], + 'node', ['../grep.js', 'no-such-string', updatePath('files/independence.txt')], {env: GREP_ENV} )) } @@ -606,7 +610,7 @@ test('multiple-chunk input file', async t => { for (let i = 0; i < 10; i++) { const search = `${i}` const {stdout} = await execFilePromise( - 'node', ['../grep.js', search, 'files/long.txt'], + 'node', ['../grep.js', search, updatePath('files/long.txt')], {env: GREP_ENV} ) const expectedLines = lines.filter(line => line.includes(search)) @@ -620,7 +624,7 @@ test('multiple-chunk lines', async t => { const lines = contents.trim().split('\n') for (let i = 0; i < 10; i++) { const {stdout} = await execFilePromise( - 'node', ['../grep.js', `${i}`, 'files/long-lines.txt'], + 'node', ['../grep.js', `${i}`, updatePath('files/long-lines.txt')], {env: GREP_ENV} ) t.deepEqual(stdout, lines[i] + '\n') diff --git a/tests/util.js b/tests/util.js index 513d3262386ade866883af72bcb24a13b8efcbc4..25115401f21aa437bc6d6d844ad42245139f95f6 100644 --- a/tests/util.js +++ b/tests/util.js @@ -17,12 +17,15 @@ function* reorderings(fixed, reorderable) { } exports.reorderings = reorderings +const updatePath = filename => path.join(...filename.split('/')) +exports.updatePath = updatePath + /** Updates the path separators in an expected output to match the OS's separator */ exports.updateExpectedPaths = expected => expected.map(lineGroup => lineGroup.map(line => { const pathEnd = line.indexOf(':') if (pathEnd < 0) throw new Error('Line does not have a path') - return path.join(...line.slice(0, pathEnd).split('/')) + line.slice(pathEnd) + return updatePath(line.slice(0, pathEnd)) + line.slice(pathEnd) })) function toLines(text) {