Search in sources :

Example 1 with Fact

use of com.google.common.truth.Fact in project compile-testing by google.

the class CompilationSubject method checkGeneratedFile.

private JavaFileObjectSubject checkGeneratedFile(Optional<JavaFileObject> generatedFile, Location location, String path) {
    if (!generatedFile.isPresent()) {
        // TODO(b/132162475): Use Facts if it becomes public API.
        ImmutableList.Builder<Fact> facts = ImmutableList.builder();
        facts.add(fact("in location", location.getName()));
        facts.add(simpleFact("it generated:"));
        for (JavaFileObject generated : actual.generatedFiles()) {
            if (generated.toUri().getPath().contains(location.getName())) {
                facts.add(simpleFact("  " + generated.toUri().getPath()));
            }
        }
        failWithoutActual(fact("expected to generate file", "/" + path), facts.build().toArray(new Fact[0]));
        return ignoreCheck().about(javaFileObjects()).that(ALREADY_FAILED);
    }
    return check("generatedFile(/%s)", path).about(javaFileObjects()).that(generatedFile.get());
}
Also used : JavaFileObject(javax.tools.JavaFileObject) ImmutableList(com.google.common.collect.ImmutableList) Fact(com.google.common.truth.Fact) Fact.simpleFact(com.google.common.truth.Fact.simpleFact)

Example 2 with Fact

use of com.google.common.truth.Fact in project java-smt by sosy-lab.

the class BooleanFormulaSubject method checkIsUnsat.

private void checkIsUnsat(final BooleanFormula subject, final Fact expected) throws SolverException, InterruptedException {
    try (ProverEnvironment prover = context.newProverEnvironment(ProverOptions.GENERATE_MODELS)) {
        prover.push(subject);
        if (prover.isUnsat()) {
            // success
            return;
        }
        // get model for failure message
        try (Model model = prover.getModel()) {
            List<Fact> facts = new ArrayList<>();
            facts.add(Fact.fact("but was", formulaUnderTest));
            if (!subject.equals(formulaUnderTest)) {
                facts.add(Fact.fact("checked formula was", subject));
            }
            facts.add(Fact.fact("which has model", model));
            failWithoutActual(expected, facts.toArray(new Fact[0]));
        }
    }
}
Also used : Model(org.sosy_lab.java_smt.api.Model) ArrayList(java.util.ArrayList) ProverEnvironment(org.sosy_lab.java_smt.api.ProverEnvironment) Fact(com.google.common.truth.Fact)

Aggregations

Fact (com.google.common.truth.Fact)2 ImmutableList (com.google.common.collect.ImmutableList)1 Fact.simpleFact (com.google.common.truth.Fact.simpleFact)1 ArrayList (java.util.ArrayList)1 JavaFileObject (javax.tools.JavaFileObject)1 Model (org.sosy_lab.java_smt.api.Model)1 ProverEnvironment (org.sosy_lab.java_smt.api.ProverEnvironment)1