From 1cf1aaf8374f2363c860768808a1a68452e625b5 Mon Sep 17 00:00:00 2001 From: Lucas <89882946+notbad3500@users.noreply.github.com> Date: Wed, 3 Jul 2024 14:08:27 +0200 Subject: [PATCH] Doku, AllFeaturesClassExample not running!!! --- .lib/Kurzdokumentation.md | 58 +++++++++++++++++++ src/test/java/main/E2EReflectionsTest.java | 16 ++++- src/test/java/main/InputFilesTest.java | 32 +++++----- .../AllFeaturesClassExample.java | 10 +++- 4 files changed, 96 insertions(+), 20 deletions(-) create mode 100644 .lib/Kurzdokumentation.md diff --git a/.lib/Kurzdokumentation.md b/.lib/Kurzdokumentation.md new file mode 100644 index 0000000..b298cf9 --- /dev/null +++ b/.lib/Kurzdokumentation.md @@ -0,0 +1,58 @@ +# Kurzdokumentation + +## Aufgabenverteilung + +### Maximilian Stahl und Jannik Rombach: +- **Scanner** +- **Parser** +- **AST** +- **AstBuilder** + - **Modul: ast** + - Alle + - **Modul: parser** + - Alle + - **Modul: visitor** + - Alle + - **Testmodul: parser** + - AstBuildertest.java + - Helper.java + - **Testfiles: singleFeatureTests** + - Alle + +### Johannes Ehlert: +- **Semantische Analyse** + - **Modul: semantic** + - **Modul: typecheck** + - **Testmodul: parser** + - AstBuildertest.java + - **Testfiles: typedAstFeatureTests** + - Großteil + - **Testfiles: typedAstExceptionsTests** + - Großteil + +### David Große: +- **Bytecodegenerator** + - **Modul: bytecode** + - Alle + +### Lucas Janker: +- **Tests** + - **Modul: main** + - Alle + - **Testmodul: main** + - Alle + - **Testmodul: parser** + - ScannerTest.java + - ParserTest.java + - **Testmodul: semantic** + - **Testfiles: combinedFeatureTests** + - Alle + - **Testfiles: failureTests** + - Alle + - **Testfiles: Alle** + - Refactoring + - **Ordnerstrukturen** + - Großteil + - **Build** + - **Makefile** + - **Dokumentation** \ No newline at end of file diff --git a/src/test/java/main/E2EReflectionsTest.java b/src/test/java/main/E2EReflectionsTest.java index 6d3e5b2..f461417 100644 --- a/src/test/java/main/E2EReflectionsTest.java +++ b/src/test/java/main/E2EReflectionsTest.java @@ -7,13 +7,25 @@ import java.util.Arrays; import org.junit.jupiter.api.Test; +import javax.tools.JavaCompiler; +import javax.tools.ToolProvider; + import static org.junit.jupiter.api.Assertions.*; public class E2EReflectionsTest { @Test public void AllFeaturesClassExampleTest(){ try { - Class clazz = Class.forName("resources.input.combinedFeatureTests.AllFeaturesClassExample"); + Main.main(new String[]{"src/test/resources/input/combinedFeatureTests/AllFeaturesClassExample.java", "src/test/resources/output/raupenpiler"}); + // Get the system Java compiler + JavaCompiler javac = ToolProvider.getSystemJavaCompiler(); + // Assert that the compiler is available + assertNotNull(javac, "Java Compiler is not available"); + javac.run(null, null, null, "src/test/resources/input/combinedFeatureTests/AllFeaturesClassExample.java"); + + Class clazz = Class.forName("src.resources.input.combinedFeatureTests.AllFeaturesClassExample"); + ClassLoader classLoader = getClass().getClassLoader(); + // Class clazz = classLoader.loadClass("main.AllFeaturesClassExample"); // Class Name assertEquals("main.AllFeaturesClassExample", clazz.getName()); @@ -76,6 +88,8 @@ public class E2EReflectionsTest { } catch (ClassNotFoundException | NoSuchFieldException | NoSuchMethodException e) { e.printStackTrace(); + } catch (Exception e) { + throw new RuntimeException(e); } } } \ No newline at end of file diff --git a/src/test/java/main/InputFilesTest.java b/src/test/java/main/InputFilesTest.java index f3b5c81..4529c9d 100644 --- a/src/test/java/main/InputFilesTest.java +++ b/src/test/java/main/InputFilesTest.java @@ -54,33 +54,33 @@ public class InputFilesTest { * The test passes if all the files fail to compile. */ @Test - public void areTestFilesActuallyFails() { + public void areTestFilesActuallyFails() throws IOException { // Get the system Java compiler JavaCompiler javac = ToolProvider.getSystemJavaCompiler(); // Assert that the compiler is available assertNotNull(javac, "Java Compiler is not available"); - String directoryPath = "src/test/resources/input/failureTests"; - File folder = new File(directoryPath); - if (folder.isDirectory()) { - File[] files = folder.listFiles((dir, name) -> name.endsWith(".java")); + File folder1 = new File("src/test/resources/input/failureTests"); + File folder2 = new File("src/test/resources/input/typedAstExceptionsTest"); - if (files != null) { - for (File file : files) { - // Try to compile the file and get the result - // The run method returns 0 if the compilation was successful, and non-zero otherwise - int result = javac.run(null, null, null, file.getPath()); + List files = getJavaFilesFromDirectory(folder1); + files.addAll(getJavaFilesFromDirectory(folder2)); - // Assert that the compilation failed (i.e., the result is non-zero) - assertTrue(result != 0, "Expected compilation failure for " + file.getName()); - } - } else { - System.out.println("No files found in the directory."); + + if (!files.isEmpty()) { + for (File file : files) { + // Try to compile the file and get the result + // The run method returns 0 if the compilation was successful, and non-zero otherwise + int result = javac.run(null, null, null, file.getPath()); + + // Assert that the compilation failed (i.e., the result is non-zero) + assertTrue(result != 0, "Expected compilation failure for " + file.getName()); } } else { - System.out.println("The provided path is not a directory."); + System.out.println("No files found in the directory."); } + } /** diff --git a/src/test/resources/input/combinedFeatureTests/AllFeaturesClassExample.java b/src/test/resources/input/combinedFeatureTests/AllFeaturesClassExample.java index 8f5b3c6..ed7c73a 100644 --- a/src/test/resources/input/combinedFeatureTests/AllFeaturesClassExample.java +++ b/src/test/resources/input/combinedFeatureTests/AllFeaturesClassExample.java @@ -4,7 +4,7 @@ public class AllFeaturesClassExample { char c; // Konstruktor - AllFeaturesClassExample(int a, boolean b, char c) { + public AllFeaturesClassExample(int a, boolean b, char c) { this.a = a; this.b = b; this.c = c; @@ -19,12 +19,12 @@ public class AllFeaturesClassExample { // while Schleife while (a > 0) { - System.out.println("a ist " + a); a--; } - + int c = 0; // for Schleife for (int i = 0; i < 5; i++) { + c++; } } @@ -60,6 +60,10 @@ public class AllFeaturesClassExample { return a % b; } + boolean greaterThan(int a, int b) { + return a > b; + } + public static void main(String[] args) { AllFeaturesClassExample obj = new AllFeaturesClassExample(12, true, 'a'); obj.controlStructures();