From ea133d52f3b13eb4ddfe905b890d17ba11aed202 Mon Sep 17 00:00:00 2001 From: AurumTheEnd <47597303+AurumTheEnd@users.noreply.github.com> Date: Thu, 14 Oct 2021 23:13:06 +0200 Subject: [PATCH] Fixed CliTest of first plugin in list not running Instead of using some word-boundary using regex to match the plugin, we can skip the whole CLI and temp file ordeal by using the plugin manager. --- .../backend/data/CompileUploadCliTest.java | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/runtime-decompiler/src/test/java/org/jrd/backend/data/CompileUploadCliTest.java b/runtime-decompiler/src/test/java/org/jrd/backend/data/CompileUploadCliTest.java index 75c17873..74c05e92 100644 --- a/runtime-decompiler/src/test/java/org/jrd/backend/data/CompileUploadCliTest.java +++ b/runtime-decompiler/src/test/java/org/jrd/backend/data/CompileUploadCliTest.java @@ -219,21 +219,17 @@ void testOverwriteWarning() { Assertions.assertTrue(output.contains("WARNING:")); } - public static boolean checkPlugin(String plugin, Model model) throws Exception { - File f = File.createTempFile("jrd", "plugins.txt"); - String[] args = new String[]{ - Cli.LIST_PLUGINS, - Cli.SAVE_AS, f.getAbsolutePath() - }; - Cli cli = new Cli(args, model); - cli.consumeCli(); - return Files.readAllLines(f.toPath()).stream().collect(Collectors.joining(" ")).contains(" " + plugin + " "); + public static boolean pluginExists(String plugin, Model model) throws Exception { + return model.getPluginManager() + .getWrappers() + .stream() + .anyMatch(wrapper -> wrapper.getName().equals(plugin)); } @Test void testDecompileCompileCfr() throws Exception { final String plugin = "Cfr"; - Assumptions.assumeTrue(checkPlugin(plugin, model), "plugin: " + plugin + " not available"); + Assumptions.assumeTrue(pluginExists(plugin, model), "plugin: " + plugin + " not available"); File decompiledFile = decompile(plugin, dummy, model); String sOrig = Files.readAllLines( decompiledFile.toPath(), StandardCharsets.UTF_8).stream() @@ -313,7 +309,7 @@ private static File decompile(String plugin, AbstractSourceTestClass dummy, Mode @Test void testDecompileCompileJasm() throws Exception { final String plugin = "jasm"; - Assumptions.assumeTrue(checkPlugin(plugin, model), "plugin: " + plugin + " not available"); + Assumptions.assumeTrue(pluginExists(plugin, model), "plugin: " + plugin + " not available"); File decompiledFile = decompile(plugin, dummy, model); String sOrig = Files.readAllLines(decompiledFile.toPath(), StandardCharsets.UTF_8).stream().collect(Collectors.joining("\n")); String sLine = Files.readAllLines(decompiledFile.toPath(), StandardCharsets.UTF_8).stream().collect(Collectors.joining(" ")); @@ -345,7 +341,7 @@ void testDecompileCompileJasm() throws Exception { @Test void testDecompileCompileJcoder() throws Exception { final String plugin = "jcoder"; - Assumptions.assumeTrue(checkPlugin(plugin, model), "plugin: " + plugin + " not available"); + Assumptions.assumeTrue(pluginExists(plugin, model), "plugin: " + plugin + " not available"); File decompiledFile = decompile(plugin, dummy, model); String sOrig = Files.readAllLines(decompiledFile.toPath(), StandardCharsets.UTF_8).stream().collect(Collectors.joining("\n")); //unluckily there is nothing to compare to, unless we wish to call jcoder from here "again"