Skip to content

Commit b2c110e

Browse files
committed
Adicionado teste de integração para ComandLineLauncher
1 parent f237d2a commit b2c110e

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package liquidjava.verifier.integration;
2+
3+
import static org.junit.jupiter.api.Assertions.*;
4+
5+
import java.io.*;
6+
import java.nio.file.*;
7+
import java.util.*;
8+
9+
import org.junit.jupiter.api.*;
10+
11+
public class CommandLineLauncherIntegrationTest {
12+
13+
private static final String VERIFIER_MAIN = "liquidjava.api.CommandLineLauncher";
14+
15+
@BeforeAll
16+
static void setup() {
17+
// se necessário: compilar os exemplos ou garantir que os ficheiros de teste existem
18+
}
19+
20+
@Test
21+
void testCorrectExampleShouldPassVerification() throws Exception {
22+
// supondo que existe no projecto um ficheiro de exemplo “CorrectSimpleAssignment.java”
23+
Path example = Paths.get("liquidjava-example/src/main/java/testSuite/CorrectSimpleAssignment.java");
24+
assertTrue(Files.exists(example), "Ficheiro de exemplo correcto não encontrado: " + example);
25+
26+
ProcessBuilder pb = new ProcessBuilder(
27+
"java",
28+
"-cp",
29+
System.getProperty("java.class.path"),
30+
VERIFIER_MAIN,
31+
example.toString()
32+
);
33+
pb.redirectErrorStream(true);
34+
Process process = pb.start();
35+
36+
String output;
37+
try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
38+
output = reader.lines().reduce("", (a,b) -> a + b + System.lineSeparator());
39+
}
40+
int exitCode = process.waitFor();
41+
// verificar que passou
42+
assertEquals(0, exitCode, "Exit code devia ser 0 para caso correcto. Output:\n" + output);
43+
assertTrue(output.contains("Correct! Passed Verification") || output.contains("Passed Verification"),
44+
"Output inesperado para caso correcto: " + output);
45+
}
46+
47+
@Test
48+
void testErrorExampleShouldFailVerification() throws Exception {
49+
// supondo que existe o ficheiro “ErrorSimpleAssignment.java”
50+
Path example = Paths.get("liquidjava-example/src/main/java/testSuite/ErrorSimpleAssignment.java");
51+
assertTrue(Files.exists(example), "Ficheiro de exemplo de erro não encontrado: " + example);
52+
53+
ProcessBuilder pb = new ProcessBuilder(
54+
"java",
55+
"-cp",
56+
System.getProperty("java.class.path"),
57+
VERIFIER_MAIN,
58+
example.toString()
59+
);
60+
pb.redirectErrorStream(true);
61+
Process process = pb.start();
62+
63+
String output;
64+
try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
65+
output = reader.lines().reduce("", (a,b) -> a + b + System.lineSeparator());
66+
}
67+
int exitCode = process.waitFor();
68+
// verificar que falhou
69+
assertNotEquals(0, exitCode, "Exit code devia ser diferente de 0 para caso de erro. Output:\n" + output);
70+
assertTrue(output.toLowerCase().contains("error") || output.contains("Refinement violation"),
71+
"Output inesperado para caso de erro: " + output);
72+
}
73+
}

0 commit comments

Comments
 (0)