Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix grep per line rather than the whole content #260

Merged
merged 2 commits into from
Nov 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/test/groovy/IsGitRegionMatchStepTests.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -317,4 +317,21 @@ class IsGitRegionMatchStepTests extends ApmBasePipelineTest {
assertFalse(script.isGrepPatternFound('bar', 'pattern'))
assertJobStatusSuccess()
}

@Test
void testIsFullPatternMatchWithMultipleLines() throws Exception {
def script = loadScript(scriptName)
def changeset = ''' foo
| bar
'''.stripMargin().stripIndent()
helper.registerAllowedMethod('readFile', [String.class], { return changeset })
script.isFullPatternMatch('whatever', [ 'foo', 'bar' ], true)
printCallStack()
assertTrue(helper.callStack.findAll { call ->
call.methodName == 'sh'
}.any { call ->
callArgsToString(call).contains("echo 'bar'")
})
assertJobStatusSuccess()
}
}
2 changes: 1 addition & 1 deletion vars/isGitRegionMatch.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def isFullPatternMatch(gitDiffFile, patterns, isGlob) {
fileContent.split('\n').each { String line ->
log(level: 'DEBUG', text: "changeset element: '${line}'")
if (isGlob) {
if (!patterns.every { pattern -> isGrepPatternFound(fileContent, pattern) }) {
if (!patterns.every { pattern -> isGrepPatternFound(line, pattern) }) {
match = false
}
} else {
Expand Down