Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions liquidjava-verifier/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,46 @@
<compilerTargetPlatform>20</compilerTargetPlatform>
</configuration>
</plugin>

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.14</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>default-check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule>
<element>BUNDLE</element>
<limits>
<limit>
<counter>COMPLEXITY</counter>
<value>COVEREDRATIO</value>
<minimum>0.4</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package liquidjava.verifier.integration;

import static org.junit.jupiter.api.Assertions.*;

import java.io.*;
import java.nio.file.*;
import java.util.*;

import org.junit.jupiter.api.*;

public class CommandLineLauncherIntegrationTest {

private static final String VERIFIER_MAIN = "liquidjava.api.CommandLineLauncher";

@BeforeAll
static void setup() {
// se necessário: compilar os exemplos ou garantir que os ficheiros de teste existem
}

@Test
void testCorrectExampleShouldPassVerification() throws Exception {
// supondo que existe no projecto um ficheiro de exemplo “CorrectSimpleAssignment.java”
Path example = Paths.get("liquidjava-example/src/main/java/testSuite/CorrectSimpleAssignment.java");
assertTrue(Files.exists(example), "Ficheiro de exemplo correcto não encontrado: " + example);

ProcessBuilder pb = new ProcessBuilder(
"java",
"-cp",
System.getProperty("java.class.path"),
VERIFIER_MAIN,
example.toString()
);
pb.redirectErrorStream(true);
Process process = pb.start();

String output;
try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
output = reader.lines().reduce("", (a,b) -> a + b + System.lineSeparator());
}
int exitCode = process.waitFor();
// verificar que passou
assertEquals(0, exitCode, "Exit code devia ser 0 para caso correcto. Output:\n" + output);
assertTrue(output.contains("Correct! Passed Verification") || output.contains("Passed Verification"),
"Output inesperado para caso correcto: " + output);
}

@Test
void testErrorExampleShouldFailVerification() throws Exception {
// supondo que existe o ficheiro “ErrorSimpleAssignment.java”
Path example = Paths.get("liquidjava-example/src/main/java/testSuite/ErrorSimpleAssignment.java");
assertTrue(Files.exists(example), "Ficheiro de exemplo de erro não encontrado: " + example);

ProcessBuilder pb = new ProcessBuilder(
"java",
"-cp",
System.getProperty("java.class.path"),
VERIFIER_MAIN,
example.toString()
);
pb.redirectErrorStream(true);
Process process = pb.start();

String output;
try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
output = reader.lines().reduce("", (a,b) -> a + b + System.lineSeparator());
}
int exitCode = process.waitFor();
// verificar que falhou
assertNotEquals(0, exitCode, "Exit code devia ser diferente de 0 para caso de erro. Output:\n" + output);
assertTrue(output.toLowerCase().contains("error") || output.contains("Refinement violation"),
"Output inesperado para caso de erro: " + output);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package liquidjava.integration;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

import liquidjava.rj_language.ast.BinaryExpression;
import liquidjava.rj_language.ast.LiteralInt;
import liquidjava.rj_language.opt.ConstantFolding;
import liquidjava.rj_language.opt.derivation_node.ValDerivationNode;

public class TestIntegration {
@Test
public void testConstantFoldingIntegration() {
BinaryExpression expr = new BinaryExpression(new LiteralInt(3), "*", new LiteralInt(4));
ValDerivationNode result = ConstantFolding.fold(new ValDerivationNode(expr, null));
assertEquals(new LiteralInt(12), result.getValue());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package liquidjava.rj_language;

import static org.junit.Assert.assertNotEquals;
import org.junit.Test;
import liquidjava.rj_language.ast.LiteralString;

public class TestLiteralString {
@Test
public void testLiteralString() {
LiteralString s1 = new LiteralString("hello");
LiteralString s2 = new LiteralString("world");
assertNotEquals(s1.hashCode(), s2.hashCode());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import static org.junit.Assert.assertEquals;

import org.junit.Test;

import liquidjava.rj_language.ast.BinaryExpression;
import liquidjava.rj_language.ast.LiteralInt;
import liquidjava.rj_language.opt.ConstantFolding;
import liquidjava.rj_language.opt.derivation_node.ValDerivationNode;

public class TestOptimization {
@Test
public void testBinaryFold() {
BinaryExpression b = new BinaryExpression(new LiteralInt(1), "+", new LiteralInt(2));

ValDerivationNode r = ConstantFolding.fold(new ValDerivationNode(b, null));
assertEquals(r.getValue(), new LiteralInt(3));
}
}
Loading