+ * Im gleichen Ordner wie die diese Datei (TestCompilerOutput.java) muss die selbstkompilierte CompilerInput.java Datei sein. + * --->>>> Diese muss man also vom Ordner classFileOutput in diesen ordner hier (test/java) rein kopieren. (bis es eine bessere Lösung gibt) <<<<--- + * Die selbstkompilierte .class Datei wird dann hier drin geladen und eine Instanz von ihr erstellt, es können auch Methoden aufgerufen werden. + * Diese TestCompilerOutput.java Datei wird dann mit "javac .\TestCompilerOutput.java" kompiliert und mit "java TestCompilerOutput" ausgeführt. + * Wenn unser Compiler funktioniert, sollten keine Errors kommen (sondern nur die Ausgaben, die wir in der CompilerInput.java Datei gemacht haben, + * oder Methoden, die wir hier aufrufen). + * PROBLEM: hier kommen errors, was eigentlich heißt, dass der Compiler nicht funktioniert, der der Test sollt eigentlich passen + */ +public class TestCompilerOutput { + + public static void main(String[] args) { + try { + // Try to load the class named "CompilerInput" + Class> cls = Class.forName("CompilerInput"); + // Print a success message if the class is loaded successfully + System.out.println("Class loaded successfully: " + cls.getName()); + + // Try to create an instance of the loaded class + Object instance = cls.getDeclaredConstructor().newInstance(); + // Print a success message if the instance is created successfully + System.out.println("Instance created: " + instance); + + + // If the class has a main method, you can invoke it + // cls.getMethod("main", String[].class).invoke(null, (Object) new String[]{}); + + // If the class has other methods, you can invoke them as well + // Example: cls.getMethod("someMethod").invoke(instance); + + } catch (ClassNotFoundException e) { + // Print an error message if the class is not found + System.err.println("Class not found: " + e.getMessage()); + } catch (Exception e) { + // Print an error message if any other exception occurs during class loading or instance creation + System.err.println("Error during class loading or execution: " + e.getMessage()); + } + } +} diff --git a/src/test/java/Tester.java b/src/test/java/Tester.java deleted file mode 100644 index 2c62e40..0000000 --- a/src/test/java/Tester.java +++ /dev/null @@ -1,12 +0,0 @@ -public class Tester { - public static void main(String[] args) { - - - } -} -// cp mitgeben -// java -jar pfadtocompiler.jar EmptyClass.java -// mit bash scipt ode rmakefile test automatisieren -// mvn package -// javac tester // tester compilen -// java tester // tester ausführen \ No newline at end of file diff --git a/src/test/java/make.md b/src/test/java/make.md deleted file mode 100644 index e69de29..0000000 diff --git a/src/test/resources/CompilerInput.java b/src/test/resources/CompilerInput.java index 918c686..91b2625 100644 --- a/src/test/resources/CompilerInput.java +++ b/src/test/resources/CompilerInput.java @@ -1,13 +1,9 @@ -public class Example { - - public int testVar; - - public static int testMethod(char b){ - - int a; - int a; +public class CompilerInput { + public int a; + public static int testMethod(char x){ + return 0; } +} -} \ No newline at end of file