Added hacky way for controlling the execution of tests

This commit is contained in:
JeremyStar™ 2024-08-19 02:06:26 +02:00
parent 94fb91197a
commit ed9c94f17c
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D
14 changed files with 58 additions and 5 deletions

View file

@ -131,6 +131,12 @@ javadoc {
test { test {
useJUnitPlatform() useJUnitPlatform()
Map<String, String> testConfiguration = new HashMap<>();
for (String property : project.properties.keySet())
if (property.startsWith("test."))
testConfiguration.put(property, project.properties.get(property).toString())
systemProperties(testConfiguration)
setMaxParallelForks(project.hasProperty("jobs") ? Integer.parseInt((String) project.property("jobs")) : 8) setMaxParallelForks(project.hasProperty("jobs") ? Integer.parseInt((String) project.property("jobs")) : 8)
setForkEvery(1) setForkEvery(1)
setFailFast(true) setFailFast(true)

View file

@ -149,12 +149,11 @@ public final class Logger {
.group(Engine.getThreadGroup()) .group(Engine.getThreadGroup())
.stackSize(10) .stackSize(10)
.start(threadLogic); .start(threadLogic);
} else { } else
// Restart logging thread if dead // Restart logging thread if dead
if (!loggingThread.isAlive()) if (!loggingThread.isAlive())
loggingThread.start(); loggingThread.start();
} }
}
/** /**
* Prints all queued log messages. * Prints all queued log messages.

View file

@ -43,6 +43,7 @@ class EngineConfigurationTest extends TestBase {
@Test @Test
@DisplayName("Method loadConfiguration") @DisplayName("Method loadConfiguration")
void testLoadConfiguration() { void testLoadConfiguration() {
if (checkCondition()) return;
getLogger().testCall("testLoadConfiguration"); getLogger().testCall("testLoadConfiguration");
Map<@NotNull String, @NotNull Object[]> settings = new HashMap<>(); Map<@NotNull String, @NotNull Object[]> settings = new HashMap<>();

View file

@ -22,9 +22,11 @@ package de.staropensource.sosengine.base.srctests;
import de.staropensource.sosengine.base.Engine; import de.staropensource.sosengine.base.Engine;
import de.staropensource.sosengine.unittests.UnitLogger; import de.staropensource.sosengine.unittests.UnitLogger;
import lombok.Getter; import lombok.Getter;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import java.util.Locale;
import java.util.Objects;
/** /**
* A class implemented by all tests. * A class implemented by all tests.
*/ */
@ -61,6 +63,31 @@ public class TestBase {
instance = this; instance = this;
} }
/**
* Allows specifying that only some tests are executed.
*/
protected final boolean checkCondition() {
switch (System.getProperties().getProperty("test.controlmode")) {
case "force-disable" -> {
if (Objects.equals(System.getProperties().getProperty("test.control." + getClass().getName().replace(getClass().getPackageName() + ".", "").toLowerCase(Locale.ROOT)), "false")) {
if (!Objects.equals(System.getProperties().getProperty("test.silentdisable"), "true"))
logger.warn("The test " + getClass().getName() + " has been force-disabled and will be skipped");
return true;
}
}
case "force-enable" -> {
if (!Objects.equals(System.getProperties().getProperty("test.control." + getClass().getName().replace(getClass().getPackageName() + ".", "").toLowerCase(Locale.ROOT)), "true")) {
if (!Objects.equals(System.getProperties().getProperty("test.silentdisable"), "true"))
logger.warn("The test suite is currently in force-enable mode and " + getClass().getName() + " does not have clearance to execute, meaning it will be skipped");
return true;
}
}
case null, default -> {}
}
return false;
}
/** /**
* Initializes the engine before running tests. * Initializes the engine before running tests.
*/ */

View file

@ -50,6 +50,7 @@ public class FourNumberVersioningSystemTest extends TestBase {
"1.1.0.0, 1.1.1.1, 2", "1.1.0.0, 1.1.1.1, 2",
}) })
void testCompare(String a, String b, int expected) throws Throwable { void testCompare(String a, String b, int expected) throws Throwable {
if (checkCondition()) return;
getLogger().testCall("testCompare", a, b, expected); getLogger().testCall("testCompare", a, b, expected);
try { try {

View file

@ -47,6 +47,7 @@ public class OneNumberVersioningSystemTest extends TestBase {
"1, 2, 2", "1, 2, 2",
}) })
void testCompare(String a, String b, int expected) throws Throwable { void testCompare(String a, String b, int expected) throws Throwable {
if (checkCondition()) return;
getLogger().testCall("testCompare", a, b, expected); getLogger().testCall("testCompare", a, b, expected);
try { try {

View file

@ -55,6 +55,7 @@ public class SemanticVersioningSystemTest extends TestBase {
"1.1.0+5, 1.1.0+6, 2", "1.1.0+5, 1.1.0+6, 2",
}) })
void testCompare(String a, String b, int expected) throws Throwable { void testCompare(String a, String b, int expected) throws Throwable {
if (checkCondition()) return;
getLogger().testCall("testCompare", a, b, expected); getLogger().testCall("testCompare", a, b, expected);
try { try {

View file

@ -54,6 +54,7 @@ public class StarOpenSourceVersioningSystemTest extends TestBase {
"v9-beta5, v9-releasecandidate1, 2", "v9-beta5, v9-releasecandidate1, 2",
}) })
void testCompare(String a, String b, int expected) throws Throwable { void testCompare(String a, String b, int expected) throws Throwable {
if (checkCondition()) return;
getLogger().testCall("testCompare", a, b, expected); getLogger().testCall("testCompare", a, b, expected);
try { try {

View file

@ -46,6 +46,7 @@ public class ThreeNumberVersioningSystemTest extends TestBase {
"1.1.0, 1.1.1, 2", "1.1.0, 1.1.1, 2",
}) })
void testCompare(String a, String b, int expected) throws Throwable { void testCompare(String a, String b, int expected) throws Throwable {
if (checkCondition()) return;
getLogger().testCall("testCompare", a, b, expected); getLogger().testCall("testCompare", a, b, expected);
try { try {

View file

@ -46,6 +46,7 @@ public class TwoNumberVersioningSystemTest extends TestBase {
"1.5, 2.0, 2", "1.5, 2.0, 2",
}) })
void testCompare(String a, String b, int expected) throws Throwable { void testCompare(String a, String b, int expected) throws Throwable {
if (checkCondition()) return;
getLogger().testCall("testCompare", a, b, expected); getLogger().testCall("testCompare", a, b, expected);
try { try {

View file

@ -63,6 +63,8 @@ public class MiscellaneousTest extends TestBase {
"5819853, 10, 0005819853" "5819853, 10, 0005819853"
}) })
void testPadNumbers(int number, int length, String expected) { void testPadNumbers(int number, int length, String expected) {
if (checkCondition()) return;
getLogger().testCall("testPadNumbers", number, length, expected); getLogger().testCall("testPadNumbers", number, length, expected);
String result = Math.padNumbers(number, length); String result = Math.padNumbers(number, length);
assertEquals(expected, result, "Result \"" + result + "\" does not match expected output \"" + expected + "\""); assertEquals(expected, result, "Result \"" + result + "\" does not match expected output \"" + expected + "\"");
@ -77,6 +79,7 @@ public class MiscellaneousTest extends TestBase {
100, 250, 500 100, 250, 500
}) })
void testMeasureExecutionTime(int sleepingDuration) { void testMeasureExecutionTime(int sleepingDuration) {
if (checkCondition()) return;
getLogger().testCall("testMeasureExecutionTime", sleepingDuration); getLogger().testCall("testMeasureExecutionTime", sleepingDuration);
long executionTime = Miscellaneous.measureExecutionTime(() -> { long executionTime = Miscellaneous.measureExecutionTime(() -> {
@ -96,6 +99,7 @@ public class MiscellaneousTest extends TestBase {
@Test @Test
@DisplayName("getMapValues") @DisplayName("getMapValues")
void testGetMapValues() { void testGetMapValues() {
if (checkCondition()) return;
getLogger().testCall("testGetMapValues"); getLogger().testCall("testGetMapValues");
Map<String, String> testMap = new HashMap<>(); Map<String, String> testMap = new HashMap<>();
@ -118,10 +122,10 @@ public class MiscellaneousTest extends TestBase {
@Test @Test
@DisplayName("executeSafely (test 0)") @DisplayName("executeSafely (test 0)")
void testExecuteSafely0() { void testExecuteSafely0() {
if (checkCondition()) return;
getLogger().testCall("testExecuteSafely0"); getLogger().testCall("testExecuteSafely0");
throwableCaught = false; throwableCaught = false;
Miscellaneous.executeSafely(() -> System.out.println("You can safely ignore this message (this comes from MiscellaneousTest#testExecuteSafely0)"), "MiscellaneousTest#testExecuteSafely0"); Miscellaneous.executeSafely(() -> System.out.println("You can safely ignore this message (this comes from MiscellaneousTest#testExecuteSafely0)"), "MiscellaneousTest#testExecuteSafely0");
assertFalse(throwableCaught, "Event was triggered"); assertFalse(throwableCaught, "Event was triggered");
@ -133,8 +137,8 @@ public class MiscellaneousTest extends TestBase {
@Test @Test
@DisplayName("executeSafely (test 1)") @DisplayName("executeSafely (test 1)")
void testExecuteSafely1() { void testExecuteSafely1() {
if (checkCondition()) return;
getLogger().testCall("testExecuteSafely1"); getLogger().testCall("testExecuteSafely1");
throwableCaught = false; throwableCaught = false;
// Disable event optimization for instant results // Disable event optimization for instant results

View file

@ -49,6 +49,7 @@ class PlaceholderEngineTest extends TestBase {
"This %status%!, This works!", "This %status%!, This works!",
}) })
void testProcess(String text, String expected) { void testProcess(String text, String expected) {
if (checkCondition()) return;
getLogger().testCall("testProcess", text, expected); getLogger().testCall("testProcess", text, expected);
List<@NotNull Placeholder> placeholders = new ArrayList<>(); List<@NotNull Placeholder> placeholders = new ArrayList<>();

View file

@ -46,6 +46,7 @@ class PropertiesReaderTest extends TestBase {
"a.property.mightLookLikeThis, some value" "a.property.mightLookLikeThis, some value"
}) })
void testGetString(String propertyName, String propertyValue) { void testGetString(String propertyName, String propertyValue) {
if (checkCondition()) return;
getLogger().testCall("testGetString", propertyName, propertyValue); getLogger().testCall("testGetString", propertyName, propertyValue);
Properties properties = new Properties(); Properties properties = new Properties();
@ -70,6 +71,7 @@ class PropertiesReaderTest extends TestBase {
"nah, no, false", "nah, no, false",
}) })
void testGetBoolean(String propertyName, String propertyValue, boolean expected) { void testGetBoolean(String propertyName, String propertyValue, boolean expected) {
if (checkCondition()) return;
getLogger().testCall("testGetBoolean", propertyName, propertyValue, expected); getLogger().testCall("testGetBoolean", propertyName, propertyValue, expected);
Properties properties = new Properties(); Properties properties = new Properties();
@ -94,6 +96,7 @@ class PropertiesReaderTest extends TestBase {
"he's a 1 but he likes 0s, 1, 1", "he's a 1 but he likes 0s, 1, 1",
}) })
void testGetByte(String propertyName, String propertyValue, byte expected) { void testGetByte(String propertyName, String propertyValue, byte expected) {
if (checkCondition()) return;
getLogger().testCall("testGetByte", propertyName, propertyValue, expected); getLogger().testCall("testGetByte", propertyName, propertyValue, expected);
Properties properties = new Properties(); Properties properties = new Properties();
@ -118,6 +121,7 @@ class PropertiesReaderTest extends TestBase {
"he's a 1 but he likes 0s, 1, 1", "he's a 1 but he likes 0s, 1, 1",
}) })
void testGetShort(String propertyName, String propertyValue, short expected) { void testGetShort(String propertyName, String propertyValue, short expected) {
if (checkCondition()) return;
getLogger().testCall("testGetShort", propertyName, propertyValue, expected); getLogger().testCall("testGetShort", propertyName, propertyValue, expected);
Properties properties = new Properties(); Properties properties = new Properties();
@ -143,6 +147,7 @@ class PropertiesReaderTest extends TestBase {
"he's a 10 but he likes 69, 10, 10", "he's a 10 but he likes 69, 10, 10",
}) })
void testGetInteger(String propertyName, String propertyValue, int expected) { void testGetInteger(String propertyName, String propertyValue, int expected) {
if (checkCondition()) return;
getLogger().testCall("testGetInteger", propertyName, propertyValue, expected); getLogger().testCall("testGetInteger", propertyName, propertyValue, expected);
Properties properties = new Properties(); Properties properties = new Properties();
@ -168,6 +173,7 @@ class PropertiesReaderTest extends TestBase {
"he's a 10 but he likes 69, 10, 10", "he's a 10 but he likes 69, 10, 10",
}) })
void testGetLong(String propertyName, String propertyValue, long expected) { void testGetLong(String propertyName, String propertyValue, long expected) {
if (checkCondition()) return;
getLogger().testCall("testGetLong", propertyName, propertyValue, expected); getLogger().testCall("testGetLong", propertyName, propertyValue, expected);
Properties properties = new Properties(); Properties properties = new Properties();
@ -194,6 +200,7 @@ class PropertiesReaderTest extends TestBase {
"he's a 10 but he likes 69, 10.69, 10.69", "he's a 10 but he likes 69, 10.69, 10.69",
}) })
void testGetFloat(String propertyName, String propertyValue, float expected) { void testGetFloat(String propertyName, String propertyValue, float expected) {
if (checkCondition()) return;
getLogger().testCall("testGetFloat", propertyName, propertyValue, expected); getLogger().testCall("testGetFloat", propertyName, propertyValue, expected);
Properties properties = new Properties(); Properties properties = new Properties();
@ -218,6 +225,7 @@ class PropertiesReaderTest extends TestBase {
"he's a 10 but he likes 69, 10.69, 10.69", "he's a 10 but he likes 69, 10.69, 10.69",
}) })
void testGetDouble(String propertyName, String propertyValue, double expected) { void testGetDouble(String propertyName, String propertyValue, double expected) {
if (checkCondition()) return;
getLogger().testCall("testGetDouble", propertyName, propertyValue, expected); getLogger().testCall("testGetDouble", propertyName, propertyValue, expected);
Properties properties = new Properties(); Properties properties = new Properties();

View file

@ -44,6 +44,7 @@ class StackTraceParserTest extends TestBase {
"Some description here..." "Some description here..."
}) })
void testGetHeader(@NotNull String message) { void testGetHeader(@NotNull String message) {
if (checkCondition()) return;
getLogger().testCall("testGetHeader", message); getLogger().testCall("testGetHeader", message);
String output; String output;