/** * Asserts that the expected code is generated for the given source. * * @param source some valid source code written in the language under test * @param expected the expected Java source code. * @throws IOException if the resource loading fails */ public void assertCompilesTo(CharSequence source, final CharSequence expected) throws IOException { final boolean[] called = {false}; compile(source, new IAcceptor<CompilationTestHelper.Result>() { @Override public void accept(Result r) { Assert.assertEquals(expected.toString(), r.getSingleGeneratedCode()); called[0] = true; } }); Assert.assertTrue("Nothing was generated but the expectation was :\n"+expected, called[0]); }
/** * Parses, validates and compiles the given sources. Calls the given acceptor for each * resource which is generated from the source. * * @param sources some inputs written in the language under test. * @param acceptor gets called once for each file generated in {@link IGenerator} * @throws IOException if the resource loading fails * * @since 2.8 */ @SuppressWarnings("unchecked") public void compile(Iterable<? extends CharSequence> sources, IAcceptor<Result> acceptor) throws IOException { int index = 0; List<Pair<String, ? extends CharSequence>> pairs = newArrayList(); for (CharSequence source : sources) { String fileName = "MyFile" + (++index) + "." + extensionProvider.getPrimaryFileExtension(); pairs.add(new Pair<String, CharSequence>(fileName, source)); } compile(resourceSet(((Pair<String, ? extends CharSequence>[])Conversions.unwrapArray(pairs, Pair.class))), acceptor); }
/** * Parses, validates and compiles the given source. Calls the given acceptor for each * resource which is generated from the source. * * @param source some code written in the language under test. * @param acceptor gets called once for each file generated in {@link IGenerator} * @throws IOException if the resource loading fails */ @SuppressWarnings("unchecked") public void compile(CharSequence source, IAcceptor<Result> acceptor) throws IOException { String fileName = "MyFile."+extensionProvider.getPrimaryFileExtension(); compile(resourceSet(new Pair<String, CharSequence>(fileName, source)), acceptor); }
public void compile(CharSequence source, final IAcceptor<CompilationResult> acceptor) { try { compilationTestHelper.configureFreshWorkspace(); compilationTestHelper.compile(source, new IAcceptor<CompilationTestHelper.Result>() { @Override public void accept(final Result t) {