Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes JUnit before and after being called on cleanup regardless of override #6276

Merged
merged 3 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/main/java/ch/njol/skript/Skript.java
Original file line number Diff line number Diff line change
Expand Up @@ -752,13 +752,17 @@ protected void afterErrors() {
TestTracker.JUnitTestFailed(test, message);
Skript.exception(failure.getException(), "JUnit test '" + failure.getTestHeader() + " failed.");
});
if (SkriptJUnitTest.class.isAssignableFrom(clazz))
((SkriptJUnitTest) clazz.getConstructor().newInstance()).cleanup();
SkriptJUnitTest.clearJUnitTest();
}
} catch (IOException e) {
Skript.exception(e, "Failed to execute JUnit runtime tests.");
} catch (ClassNotFoundException e) {
// Should be the Skript test jar gradle task.
assert false : "Class 'ch.njol.skript.variables.FlatFileStorageTest' was not found.";
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
Skript.exception(e, "Failed to initalize test JUnit classes.");
}
if (ignored > 0)
Skript.warning("There were " + ignored + " ignored test cases! This can mean they are not properly setup in order in that class!");
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/ch/njol/skript/test/runner/SkriptJUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Pig;
import org.junit.After;
import org.junit.Before;

import ch.njol.skript.Skript;

Expand Down Expand Up @@ -79,8 +77,6 @@ public static void setShutdownDelay(long delay) {
/**
* Override this method if your JUnit test requires block modification with delay over 1 tick.
*/
@Before
@After
public void cleanup() {
getTestWorld().getEntities().forEach(Entity::remove);
setBlock(Material.AIR);
Expand Down
Loading