Search in sources :

Example 1 with Directive

use of edu.rice.cs.caper.floodgage.application.floodgage.model.directive.Directive in project bayou by capergroup.

the class FloodGage method run.

/**
 * Parses "trials.xml" as found as a resource on the current class path and executes the trials against
 * the given Synthesizer reporting progress to the given View.
 *
 * Expects a trialpack to be on the current classpath.
 *
 * @param synthesizer the Synthesizer to use for creating programs from draft programs identified in trials.
 * @param view the UI component for reporting execution progress.
 * @throws IOException if there is a program reading resources (like "trails.xml") on the classpath.
 * @throws ParseException if "trials.xml" is not of the expected format
 * @throws ClassCastException if "PassProgram" or "PassProgramTest" cannot be loaded from teh current classpath.
 */
void run(Synthesizer synthesizer, View view) throws IOException, ParseException, ClassNotFoundException {
    if (synthesizer == null)
        throw new NullPointerException("synthesizer");
    if (view == null)
        throw new NullPointerException("view");
    /*
         * Parse trials.xml from inside the trialpack (assumed to be on classpath) into a Directive structure.
         */
    Directive directive;
    {
        // We expect the trialpack jar file to be on the classpath.  That jar file should have a
        // trails.xml file its root directory.  So look for it at just "trails.xml" path.
        String trailsXml = new String(getResource("trials.xml"), StandardCharsets.UTF_8);
        directive = DirectiveXmlV1Parser.makeDefault().parse(trailsXml);
    }
    /*
         * Test the test suite by asserting that all test cases pass when given the pass program.
         *
         * Stop the program if this is not the case.
         */
    // expect PassProgram class inside the trailpack which is assumed to be on the class path
    Class passProgram = getClass().getClassLoader().loadClass("PassProgram");
    // expect PassProgramTest class inside the trailpack which is assumed to be on the class path
    Class passProgramTestSuite = getClass().getClassLoader().loadClass("PassProgramTest");
    view.declareTestingTestSuite(passProgramTestSuite, passProgram);
    // run the test cases against PassProgram
    Result result = new JUnitCore().run(passProgramTestSuite);
    view.declareNumberOfTestCasesInSuite(result.getRunCount());
    if (// if the pass program did not pass the test suite
    result.getFailureCount() > 0) {
        for (Failure f : result.getFailures()) view.declarePassProgramTestFailure(f.getTrace());
    } else // pass program did pass the test suite, proceed to running the user specified trials
    {
        List<Trial> trials = makeTrials(directive, DraftBuilderBayou1_1_0::new);
        TrialsRunner.runTrails(trials, synthesizer, view);
    }
}
Also used : Trial(edu.rice.cs.caper.floodgage.application.floodgage.model.plan.Trial) JUnitCore(org.junit.runner.JUnitCore) DraftBuilderBayou1_1_0(edu.rice.cs.caper.floodgage.application.floodgage.draft_building.DraftBuilderBayou1_1_0) Directive(edu.rice.cs.caper.floodgage.application.floodgage.model.directive.Directive) Failure(org.junit.runner.notification.Failure) Result(org.junit.runner.Result)

Aggregations

DraftBuilderBayou1_1_0 (edu.rice.cs.caper.floodgage.application.floodgage.draft_building.DraftBuilderBayou1_1_0)1 Directive (edu.rice.cs.caper.floodgage.application.floodgage.model.directive.Directive)1 Trial (edu.rice.cs.caper.floodgage.application.floodgage.model.plan.Trial)1 JUnitCore (org.junit.runner.JUnitCore)1 Result (org.junit.runner.Result)1 Failure (org.junit.runner.notification.Failure)1