diff --git a/.gitignore b/.gitignore index 566fc2dae1252bda32086a4a6be2690464917f12..79861d1ed8af7411f42c2b84ac1e069a683aec3e 100644 --- a/.gitignore +++ b/.gitignore @@ -102,5 +102,10 @@ build build/* test.json +test1.json +test2.json oof -hello.jar \ No newline at end of file +hello.jar +comm.puml +seq.puml +kiskacsa.exe diff --git a/src/main/java/tester/Main.java b/src/main/java/tester/Main.java index 5136bb3efd2ac87384969c542f21e4bde807d249..ad9bb97448475b6534454f9a449697bcd295233a 100644 --- a/src/main/java/tester/Main.java +++ b/src/main/java/tester/Main.java @@ -5,7 +5,6 @@ import com.google.gson.Gson; import java.io.*; import java.nio.charset.StandardCharsets; import java.nio.file.Files; -import java.nio.file.Path; import java.nio.file.Paths; import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Stream; @@ -24,40 +23,26 @@ public class Main { return sb.toString(); } - public static void main(String[] args) throws FileNotFoundException { - if (args.length < 2) { - System.out.println("usage: <tested_app.jar> <testcase.json>"); - System.exit(1); - } - + private static boolean runTest(String jarfile, String testName) throws FileNotFoundException { + System.out.printf("Running test \"%s\"\n", testName); + Gson gson = new Gson(); - TestCase test = gson.fromJson(new FileReader(args[1]), TestCase.class); + TestCase test = gson.fromJson(new FileReader(testName), TestCase.class); test.input = yeetEmpty(test.input); test.output = yeetEmpty(test.output); - - if (System.getProperty("os.name").toLowerCase().contains("win")){ - try { - ProcessBuilder pb = new ProcessBuilder("cmd.exe", "/c", "@chcp", "65001>nul").inheritIO(); - Process p = pb.start(); - p.waitFor(); - System.setOut(new PrintStream(System.out, true, StandardCharsets.UTF_8)); - } catch (Exception e) { - e.printStackTrace(); - } - } + Process proc; try { - proc = Runtime.getRuntime().exec(String.format("java -jar %s --testing", args[0])); + proc = Runtime.getRuntime().exec(String.format("java -jar %s --testing", jarfile)); } catch (Exception e) { System.out.print("❌ "); - System.out.printf("Nem sikerület elindítani a folyamatot, kérlek ellenőrizd, hogy tesztelendő program tényleg itt van-e: \"%s\"\n", args[0]); - System.exit(1); - return; + System.out.printf("Nem sikerület elindítani a folyamatot, kérlek ellenőrizd, hogy tesztelendő program tényleg itt van-e: \"%s\"\n", jarfile); + return false; } - + var in = proc.getOutputStream(); var out = proc.getInputStream(); @@ -68,8 +53,7 @@ public class Main { } catch (Exception e) { System.out.print("❌ "); System.out.println("A program nem fogadott annyi inputot, amennyi meg volt adva."); - System.exit(1); - return; + return false; } try { @@ -77,10 +61,9 @@ public class Main { } catch (Exception e) { System.out.print("❌ "); System.out.println("Nem sikerült a programnak helyesen bezáródni."); - System.exit(1); - return; + return false; } - + String o = ""; try { byte[] by = out.readAllBytes(); @@ -132,7 +115,7 @@ public class Main { } else { System.out.print("✅ "); } - + System.out.print("A program tesztelése siker"); if (error.get()) { System.out.print("telenül"); @@ -140,8 +123,39 @@ public class Main { System.out.print("esen"); } System.out.println(" végződött."); + + System.out.println("=============="); + System.out.println(); + + return !error.get(); + } + + public static void main(String[] args) throws FileNotFoundException { + if (args.length < 2) { + System.out.println("usage: <tested_app.jar> <testcase.json> [testcase.json...]"); + System.exit(1); + } - if (error.get()) { + if (System.getProperty("os.name").toLowerCase().contains("win")){ + try { + ProcessBuilder pb = new ProcessBuilder("cmd.exe", "/c", "@chcp", "65001>nul").inheritIO(); + Process p = pb.start(); + p.waitFor(); + System.setOut(new PrintStream(System.out, true, StandardCharsets.UTF_8)); + } catch (Exception e) { + e.printStackTrace(); + } + } + + var everythingIsFine = true; + var jar = args[0]; + for (int i = 1; i < args.length; i++) { + if (!runTest(jar, args[i])) { + everythingIsFine = false; + } + } + + if (!everythingIsFine) { System.exit(1); } }