Skip to content

Commit

Permalink
Fixed CliTest of first plugin in list not running
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
AurumTheEnd committed Oct 15, 2021
1 parent a19262b commit 17459ed
Showing 1 changed file with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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(" "));
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 17459ed

Please sign in to comment.