void (String text, String expected, Consumer<? super PsiBuilder> parser) { PlatformTestUtil.withStdErrSuppressed(() -> { try { PsiBuilder builder = PsiBuilderFactory.getInstance().createBuilder(new PlainTextParserDefinition(), new MyTestLexer(), text); builder.setDebugMode(true); parser.accept(builder); builder.getLightTree(); fail("should fail"); } catch (AssertionError e) { assertEquals(expected, e.getMessage()); } }); }