Skip to content

Commit

Permalink
Improve logs to help discerning what is being looked for, when and where
Browse files Browse the repository at this point in the history
  • Loading branch information
chipironcin committed Oct 8, 2018
1 parent d9d842f commit 1341ff8
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 18 deletions.
10 changes: 8 additions & 2 deletions src/main/java/hudson/plugins/textfinder/TextFinderPublisher.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,21 +129,27 @@ private void findText(Run<?, ?> run, FilePath workspace, TaskListener listener)

if (alsoCheckConsoleOutput) {
// Do not mention the pattern we are looking for to avoid false positives
logger.println("Looking for a specific pattern in the console output");
logger.println("[TextFinder plugin] Scanning console output...");
foundText |=
checkFile(
run.getLogFile(),
compilePattern(logger, regexp),
logger,
run.getCharset(),
true);
logger.println(
"[TextFinder plugin] Finished looking for pattern "
+ "'"
+ regexp
+ "'"
+ " in the console output");
}

final RemoteOutputStream ros = new RemoteOutputStream(logger);

if (fileSet != null) {
logger.println(
"Looking for pattern "
"[TextFinder plugin] Looking for pattern "
+ "'"
+ regexp
+ "'"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ public void failureIfFoundInFileOnAgent() throws Exception {
WorkflowRun build = project.scheduleBuild2(0).get();
rule.waitForCompletion(build);
rule.assertLogContains(
"Looking for pattern " + "'" + UNIQUE_TEXT + "'" + " in the files at", build);
"[TextFinder plugin] Looking for pattern "
+ "'"
+ UNIQUE_TEXT
+ "'"
+ " in the files at",
build);
assertLogContainsMatch(new File(getWorkspace(build), "out.txt"), UNIQUE_TEXT, build, false);
rule.assertBuildStatus(Result.FAILURE, build);
}
Expand All @@ -80,7 +85,12 @@ public void failureIfFoundInConsoleOnAgent() throws Exception {
agent.getNodeName(), agent.getNodeName())));
WorkflowRun build = project.scheduleBuild2(0).get();
rule.waitForCompletion(build);
rule.assertLogContains("Looking for a specific pattern in the console output", build);
rule.assertLogContains("[TextFinder plugin] Scanning console output...");
rule.assertLogContains(
"[TextFinder plugin] Finished looking for pattern '"
+ UNIQUE_TEXT
+ "' in the console output",
build);
assertLogContainsMatch(build.getLogFile(), ECHO_UNIQUE_TEXT, build, true);
rule.assertBuildStatus(Result.FAILURE, build);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ public void successIfFoundInConsole() throws Exception {
project.getPublishersList().add(textFinder);
FreeStyleBuild build = project.scheduleBuild2(0).get();
rule.waitForCompletion(build);
rule.assertLogContains("Looking for a specific pattern in the console output", build);
rule.assertLogContains("[TextFinder plugin] Scanning console output...");
rule.assertLogContains(
"[TextFinder plugin] Finished looking for pattern '"
+ UNIQUE_TEXT
+ "' in the console output",
build);
assertLogContainsMatch(build.getLogFile(), ECHO_UNIQUE_TEXT, build, true);
rule.assertBuildStatus(Result.SUCCESS, build);
}
Expand All @@ -66,7 +71,12 @@ public void failureIfFoundInConsole() throws Exception {
project.getPublishersList().add(textFinder);
FreeStyleBuild build = project.scheduleBuild2(0).get();
rule.waitForCompletion(build);
rule.assertLogContains("Looking for a specific pattern in the console output", build);
rule.assertLogContains("[TextFinder plugin] Scanning console output...");
rule.assertLogContains(
"[TextFinder plugin] Finished looking for pattern '"
+ UNIQUE_TEXT
+ "' in the console output",
build);
assertLogContainsMatch(build.getLogFile(), ECHO_UNIQUE_TEXT, build, true);
rule.assertBuildStatus(Result.FAILURE, build);
}
Expand All @@ -85,7 +95,12 @@ public void unstableIfFoundInConsole() throws Exception {
project.getPublishersList().add(textFinder);
FreeStyleBuild build = project.scheduleBuild2(0).get();
rule.waitForCompletion(build);
rule.assertLogContains("Looking for a specific pattern in the console output", build);
rule.assertLogContains("[TextFinder plugin] Scanning console output...");
rule.assertLogContains(
"[TextFinder plugin] Finished looking for pattern '"
+ UNIQUE_TEXT
+ "' in the console output",
build);
assertLogContainsMatch(build.getLogFile(), ECHO_UNIQUE_TEXT, build, true);
rule.assertBuildStatus(Result.UNSTABLE, build);
}
Expand All @@ -98,7 +113,12 @@ public void notFoundInConsole() throws Exception {
project.getPublishersList().add(textFinder);
FreeStyleBuild build = project.scheduleBuild2(0).get();
rule.waitForCompletion(build);
rule.assertLogContains("Looking for a specific pattern in the console output", build);
rule.assertLogContains("[TextFinder plugin] Scanning console output...");
rule.assertLogContains(
"[TextFinder plugin] Finished looking for pattern '"
+ UNIQUE_TEXT
+ "' in the console output",
build);
rule.assertBuildStatus(Result.SUCCESS, build);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ public void successIfFoundInFile() throws Exception {
WorkflowRun build = project.scheduleBuild2(0).get();
rule.waitForCompletion(build);
rule.assertLogContains(
"Looking for pattern '" + UNIQUE_TEXT + "' in the files at " + "'" + fileSet + "'",
"[TextFinder plugin] Looking for pattern '"
+ UNIQUE_TEXT
+ "' in the files at "
+ "'"
+ fileSet
+ "'",
build);
assertLogContainsMatch(new File(getWorkspace(build), fileSet), UNIQUE_TEXT, build, false);
rule.assertBuildStatus(Result.SUCCESS, build);
Expand All @@ -92,7 +97,12 @@ public void failureIfFoundInFile() throws Exception {
WorkflowRun build = project.scheduleBuild2(0).get();
rule.waitForCompletion(build);
rule.assertLogContains(
"Looking for pattern '" + UNIQUE_TEXT + "' in the files at " + "'" + fileSet + "'",
"[TextFinder plugin] Looking for pattern '"
+ UNIQUE_TEXT
+ "' in the files at "
+ "'"
+ fileSet
+ "'",
build);
assertLogContainsMatch(new File(getWorkspace(build), fileSet), UNIQUE_TEXT, build, false);
rule.assertBuildStatus(Result.FAILURE, build);
Expand All @@ -116,7 +126,12 @@ public void unstableIfFoundInFile() throws Exception {
WorkflowRun build = project.scheduleBuild2(0).get();
rule.waitForCompletion(build);
rule.assertLogContains(
"Looking for pattern '" + UNIQUE_TEXT + "' in the files at " + "'" + fileSet + "'",
"[TextFinder plugin] Looking for pattern '"
+ UNIQUE_TEXT
+ "' in the files at "
+ "'"
+ fileSet
+ "'",
build);
assertLogContainsMatch(new File(getWorkspace(build), fileSet), UNIQUE_TEXT, build, false);
rule.assertBuildStatus(Result.UNSTABLE, build);
Expand All @@ -140,7 +155,12 @@ public void notBuiltIfFoundInFile() throws Exception {
WorkflowRun build = project.scheduleBuild2(0).get();
rule.waitForCompletion(build);
rule.assertLogContains(
"Looking for pattern '" + UNIQUE_TEXT + "' in the files at " + "'" + fileSet + "'",
"[TextFinder plugin] Looking for pattern '"
+ UNIQUE_TEXT
+ "' in the files at "
+ "'"
+ fileSet
+ "'",
build);
assertLogContainsMatch(new File(getWorkspace(build), fileSet), UNIQUE_TEXT, build, false);
rule.assertBuildStatus(Result.NOT_BUILT, build);
Expand All @@ -162,7 +182,12 @@ public void notFoundInFile() throws Exception {
WorkflowRun build = project.scheduleBuild2(0).get();
rule.waitForCompletion(build);
rule.assertLogContains(
"Looking for pattern '" + UNIQUE_TEXT + "' in the files at " + "'" + fileSet + "'",
"[TextFinder plugin] Looking for pattern '"
+ UNIQUE_TEXT
+ "' in the files at "
+ "'"
+ fileSet
+ "'",
build);
rule.assertBuildStatus(Result.SUCCESS, build);
}
Expand All @@ -182,7 +207,12 @@ public void successIfFoundInConsole() throws Exception {
+ "', succeedIfFound: true, alsoCheckConsoleOutput: true}\n"));
WorkflowRun build = project.scheduleBuild2(0).get();
rule.waitForCompletion(build);
rule.assertLogContains("Looking for a specific pattern in the console output", build);
rule.assertLogContains("[TextFinder plugin] Scanning console output...");
rule.assertLogContains(
"[TextFinder plugin] Finished looking for pattern '"
+ UNIQUE_TEXT
+ "' in the console output",
build);
assertLogContainsMatch(build.getLogFile(), ECHO_UNIQUE_TEXT, build, true);
rule.assertBuildStatus(Result.SUCCESS, build);
}
Expand All @@ -202,7 +232,12 @@ public void failureIfFoundInConsole() throws Exception {
+ "', alsoCheckConsoleOutput: true}\n"));
WorkflowRun build = project.scheduleBuild2(0).get();
rule.waitForCompletion(build);
rule.assertLogContains("Looking for a specific pattern in the console output", build);
rule.assertLogContains("[TextFinder plugin] Scanning console output...");
rule.assertLogContains(
"[TextFinder plugin] Finished looking for pattern '"
+ UNIQUE_TEXT
+ "' in the console output",
build);
assertLogContainsMatch(build.getLogFile(), ECHO_UNIQUE_TEXT, build, true);
rule.assertBuildStatus(Result.FAILURE, build);
}
Expand All @@ -222,7 +257,12 @@ public void unstableIfFoundInConsole() throws Exception {
+ "', unstableIfFound: true, alsoCheckConsoleOutput: true}\n"));
WorkflowRun build = project.scheduleBuild2(0).get();
rule.waitForCompletion(build);
rule.assertLogContains("Looking for a specific pattern in the console output", build);
rule.assertLogContains("[TextFinder plugin] Scanning console output...");
rule.assertLogContains(
"[TextFinder plugin] Finished looking for pattern '"
+ UNIQUE_TEXT
+ "' in the console output",
build);
assertLogContainsMatch(build.getLogFile(), ECHO_UNIQUE_TEXT, build, true);
rule.assertBuildStatus(Result.UNSTABLE, build);
}
Expand All @@ -242,7 +282,12 @@ public void notBuiltIfFoundInConsole() throws Exception {
+ "', notBuiltIfFound: true, alsoCheckConsoleOutput: true}\n"));
WorkflowRun build = project.scheduleBuild2(0).get();
rule.waitForCompletion(build);
rule.assertLogContains("Looking for a specific pattern in the console output", build);
rule.assertLogContains("[TextFinder plugin] Scanning console output...");
rule.assertLogContains(
"[TextFinder plugin] Finished looking for pattern '"
+ UNIQUE_TEXT
+ "' in the console output",
build);
assertLogContainsMatch(build.getLogFile(), ECHO_UNIQUE_TEXT, build, true);
rule.assertBuildStatus(Result.NOT_BUILT, build);
}
Expand All @@ -257,7 +302,12 @@ public void notFoundInConsole() throws Exception {
+ "', alsoCheckConsoleOutput: true}\n"));
WorkflowRun build = project.scheduleBuild2(0).get();
rule.waitForCompletion(build);
rule.assertLogContains("Looking for a specific pattern in the console output", build);
rule.assertLogContains("[TextFinder plugin] Scanning console output...");
rule.assertLogContains(
"[TextFinder plugin] Finished looking for pattern '"
+ UNIQUE_TEXT
+ "' in the console output",
build);
rule.assertBuildStatus(Result.SUCCESS, build);
}
}

0 comments on commit 1341ff8

Please sign in to comment.