Skip to content

Commit

Permalink
* Fixed unit tests
Browse files Browse the repository at this point in the history
* Added Closure simulation for testing (#84)
* Refactored defaults scripts to inv-repo
  • Loading branch information
benjboyer committed Jul 30, 2020
1 parent fc51564 commit c67d89f
Show file tree
Hide file tree
Showing 18 changed files with 34 additions and 617 deletions.
7 changes: 7 additions & 0 deletions core/src/main/java/io/peasoup/inv/run/InvExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ public PoolReport execute() {

Logger.info("---- [DIGEST] completed ----");

// TODO Horrible fix. PoolStacktraces print before pool has done printing even with flushing.
try {
Thread.sleep(100);
} catch (InterruptedException e) {
Logger.error(e);
}

new PoolReportTrace(pool, report).printPoolTrace();
new PoolReportMarkdown(pool).printPoolMarkdown();

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/io/peasoup/inv/run/Logger.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import java.util.Queue;

public final class Logger {

private static Queue<Object> captureQueue = null;
private static Closure<Object> captureClosure = null;


private static boolean systemEnabled = false;
private static boolean debugEnabled = false;

Expand Down
10 changes: 6 additions & 4 deletions core/src/main/java/io/peasoup/inv/testing/JunitRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,20 @@ public class JunitRunner {

public JunitRunner() {
junit = new JUnitCore();
junit.addListener(new InvTextListener(System.out));
junit.addListener(new TextListener(System.out));

ImportCustomizer importCustomizer = new ImportCustomizer();
importCustomizer.addStarImports("org.junit");
importCustomizer.addStaticStars("org.junit.Assert");

groovyLoader = new GroovyLoader(false, "io.peasoup.inv.testing.JUnitInvTestingBase", importCustomizer);
groovyLoader = new GroovyLoader(false, "io.peasoup.inv.testing.JunitScriptBase", importCustomizer);
}

public void add(String scriptLocation) {
final File scriptFile = new File(scriptLocation);
if (!scriptFile.exists()) {
Logger.warn(scriptFile.getAbsolutePath() + " does not exist on current filesystem.");
return;

}

// Load and put class into list
Expand All @@ -56,12 +55,15 @@ public void add(String scriptLocation) {
classes.add(scriptObj.getClass());
}

public void run() {
public boolean run() {
Result result = junit.run(classes.toArray(new Class[0]));

System.out.println("Finished. Result: Failures: " + result.getFailureCount() +
". Ignored: " + result.getIgnoreCount() +
". Tests run: " + result.getRunCount() +
". Time: " + result.getRunTime() + "ms.");

return result.getFailureCount() == 0;
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package io.peasoup.inv.testing;

import groovy.lang.Closure;
import groovy.lang.Script;
import io.peasoup.inv.run.InvExecutor;
import io.peasoup.inv.run.InvHandler;
import io.peasoup.inv.run.InvInvoker;
import io.peasoup.inv.run.PoolReport;
import org.apache.commons.lang.StringUtils;
Expand All @@ -10,7 +12,7 @@
import java.io.File;
import java.net.URL;

public abstract class JUnitInvTestingBase extends Script {
public abstract class JunitScriptBase extends Script {

protected InvExecutor invExecutor;
protected PoolReport report;
Expand All @@ -35,32 +37,33 @@ public boolean getHasExceptions() {
return report != null && !report.getErrors().isEmpty();
}

public void invoke(String... files) throws IllegalAccessException {
if (files == null) throw new IllegalArgumentException("files");
if (files.length == 0) return;
public void simulate(Object... invs) throws IllegalAccessException, InvHandler.INVOptionRequiredException {
if (invs == null) throw new IllegalArgumentException("invs");
if (invs.length == 0) return;

if (called) throw new IllegalAccessException("Only call sequence once for test method");
called = true;

for (String file : files) {
runInv(file);
for (Object inv : invs) {
if (inv instanceof CharSequence) loadInvScriptfile((String)inv);
if (inv instanceof Closure) new InvHandler(invExecutor).call((Closure)inv);
}

report = invExecutor.execute();
}

private void runInv(String value) {
if (StringUtils.isEmpty(value)) throw new IllegalArgumentException("Inv must be a valid non-null, non-empty value");
private void loadInvScriptfile(String invScriptfile) {
if (StringUtils.isEmpty(invScriptfile)) throw new IllegalArgumentException("Inv must be a valid non-null, non-empty value");

File invFile = new File(value);
File invFile = new File(invScriptfile);

if (!invFile.exists()) {
String testClassLocation = (String)getMetaClass().getProperty(this, "$0");
invFile = new File(new File(testClassLocation).getParentFile(), value);
invFile = new File(new File(testClassLocation).getParentFile(), invScriptfile);
}

if (!invFile.exists()) {
URL location = this.getClass().getResource(value);
URL location = this.getClass().getResource(invScriptfile);
if (location != null)
invFile = new File(location.getPath());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package io.peasoup.inv.testing;

import org.junit.internal.JUnitSystem;
import org.junit.internal.TextListener;
import org.junit.runner.Description;
import org.junit.runner.notification.Failure;

import java.io.PrintStream;

public class InvTextListener extends TextListener {
public class TextListener extends org.junit.internal.TextListener {

private final PrintStream writer;

public InvTextListener(JUnitSystem system) {
public TextListener(JUnitSystem system) {
this(system.out());
}

public InvTextListener(PrintStream writer) {
public TextListener(PrintStream writer) {
super(writer);

this.writer = writer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,6 @@ Vue.component('configure-parameters', {
vm.$bus.$emit('toast', `warn:Reset <strong>parameters</strong> successfully!`)
},
saveParameter: function(parameter) {
var vm = this

if (parameter.sending)
return

Expand Down
80 changes: 0 additions & 80 deletions core/src/test/groovy/io/peasoup/inv/defaults/FilesTests.groovy

This file was deleted.

61 changes: 0 additions & 61 deletions core/src/test/groovy/io/peasoup/inv/defaults/HttpTests.groovy

This file was deleted.

73 changes: 0 additions & 73 deletions core/src/test/groovy/io/peasoup/inv/defaults/MavenTests.groovy

This file was deleted.

Empty file.
Empty file.

This file was deleted.

Loading

0 comments on commit c67d89f

Please sign in to comment.