Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
cs11-async
grep
Commits
445f82d9
Commit
445f82d9
authored
4 years ago
by
Caleb C. Sander
Browse files
Options
Download
Email Patches
Plain Diff
Fix path separators passed to grep
parent
1cef1e77
master
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/test.js
+8
-4
tests/test.js
tests/util.js
+4
-1
tests/util.js
with
12 additions
and
5 deletions
+12
-5
tests/test.js
View file @
445f82d9
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
'
)
...
...
This diff is collapsed.
Click to expand it.
tests/util.js
View file @
445f82d9
...
...
@@ -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
)
{
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help