< prev index next >

test/compiler/compilercontrol/share/processors/CommandProcessor.java

Print this page
rev 9433 : [mq]: CommandProcessor
rev 9212 : 8140453: compiler control test failed with RuntimeException: CompileCommand: nonexistent missing
Summary: Replace incorrect check for validity of method pattern with full command check
Reviewed-by: kvn
rev 9149 : 8066153: JEP-JDK-8046155: Test task: cover existing
Summary: Tests for CompilerCommand and CompilerControl's directives
Reviewed-by: kvn

*** 22,58 **** */ package compiler.compilercontrol.share.processors; import compiler.compilercontrol.share.scenario.CompileCommand; import jdk.test.lib.OutputAnalyzer; import java.util.List; import java.util.function.Consumer; /** * Checks that output contains a string with commands and full method pattern */ public class CommandProcessor implements Consumer<OutputAnalyzer> { ! protected final List<CompileCommand> commands; ! ! public CommandProcessor(List<CompileCommand> commands) { ! this.commands = commands; } @Override public void accept(OutputAnalyzer outputAnalyzer) { ! for (CompileCommand command : commands) { if (command.isValid()) { ! outputAnalyzer.shouldContain("CompileCommand: " ! + command.command.name + " " ! + command.methodDescriptor.getCanonicalString()); ! outputAnalyzer.shouldNotContain("CompileCommand: An error " ! + "occurred during parsing"); } else { ! outputAnalyzer.shouldMatch("(CompileCommand: )" ! + "(unrecognized command)|(Bad pattern)|" ! + "(An error occurred during parsing)"); } } } } --- 22,90 ---- */ package compiler.compilercontrol.share.processors; import compiler.compilercontrol.share.scenario.CompileCommand; + import jdk.test.lib.Asserts; import jdk.test.lib.OutputAnalyzer; + import java.util.Iterator; import java.util.List; import java.util.function.Consumer; /** * Checks that output contains a string with commands and full method pattern */ public class CommandProcessor implements Consumer<OutputAnalyzer> { ! private static final String INVALID_COMMAND_MSG = "CompileCommand: " ! + "\\b(unrecognized command|Bad pattern|" ! + "An error occurred during parsing)\\b"; ! private final Iterator<CompileCommand> nonQuietedIterator; ! private final Iterator<CompileCommand> quietedIterator; ! ! public CommandProcessor(List<CompileCommand> nonQuieted, ! List<CompileCommand> quieted) { ! this.nonQuietedIterator = nonQuieted.iterator(); ! this.quietedIterator = quieted.iterator(); } @Override public void accept(OutputAnalyzer outputAnalyzer) { ! try { ! outputAnalyzer.asLines().stream() ! .filter(s -> s.startsWith("CompileCommand:")) ! .forEachOrdered(this::check); ! } catch (Exception e) { ! System.err.println(outputAnalyzer.getOutput()); ! throw e; ! } ! } ! ! private void check(String input) { ! if (nonQuietedIterator.hasNext()) { ! CompileCommand command = nonQuietedIterator.next(); if (command.isValid()) { ! Asserts.assertTrue(input.contains(getOutputString(command)), ! getOutputString(command) + "missing in output"); } else { ! Asserts.assertTrue(input.matches(INVALID_COMMAND_MSG), ! "Error message missing for: " + getOutputString( ! command)); ! } ! } else if (quietedIterator.hasNext()) { ! CompileCommand command = quietedIterator.next(); ! if (command.isValid()) { ! Asserts.assertFalse(input.contains(getOutputString(command))); ! } else { ! Asserts.assertTrue(input.matches(INVALID_COMMAND_MSG), ! "Error message missing for: " + getOutputString( ! command)); ! } } } + + private String getOutputString(CompileCommand command) { + return "CompileCommand: " + + command.command.name + " " + + command.methodDescriptor.getCanonicalString(); } }
< prev index next >