forked from StarOpenSource/Engine
Added hacky way for controlling the execution of tests
This commit is contained in:
parent
94fb91197a
commit
ed9c94f17c
14 changed files with 58 additions and 5 deletions
|
@ -131,6 +131,12 @@ javadoc {
|
|||
test {
|
||||
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)
|
||||
setForkEvery(1)
|
||||
setFailFast(true)
|
||||
|
|
|
@ -149,12 +149,11 @@ public final class Logger {
|
|||
.group(Engine.getThreadGroup())
|
||||
.stackSize(10)
|
||||
.start(threadLogic);
|
||||
} else {
|
||||
} else
|
||||
// Restart logging thread if dead
|
||||
if (!loggingThread.isAlive())
|
||||
loggingThread.start();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints all queued log messages.
|
||||
|
|
|
@ -43,6 +43,7 @@ class EngineConfigurationTest extends TestBase {
|
|||
@Test
|
||||
@DisplayName("Method loadConfiguration")
|
||||
void testLoadConfiguration() {
|
||||
if (checkCondition()) return;
|
||||
getLogger().testCall("testLoadConfiguration");
|
||||
|
||||
Map<@NotNull String, @NotNull Object[]> settings = new HashMap<>();
|
||||
|
|
|
@ -22,9 +22,11 @@ package de.staropensource.sosengine.base.srctests;
|
|||
import de.staropensource.sosengine.base.Engine;
|
||||
import de.staropensource.sosengine.unittests.UnitLogger;
|
||||
import lombok.Getter;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* A class implemented by all tests.
|
||||
*/
|
||||
|
@ -61,6 +63,31 @@ public class TestBase {
|
|||
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.
|
||||
*/
|
||||
|
|
|
@ -50,6 +50,7 @@ public class FourNumberVersioningSystemTest extends TestBase {
|
|||
"1.1.0.0, 1.1.1.1, 2",
|
||||
})
|
||||
void testCompare(String a, String b, int expected) throws Throwable {
|
||||
if (checkCondition()) return;
|
||||
getLogger().testCall("testCompare", a, b, expected);
|
||||
|
||||
try {
|
||||
|
|
|
@ -47,6 +47,7 @@ public class OneNumberVersioningSystemTest extends TestBase {
|
|||
"1, 2, 2",
|
||||
})
|
||||
void testCompare(String a, String b, int expected) throws Throwable {
|
||||
if (checkCondition()) return;
|
||||
getLogger().testCall("testCompare", a, b, expected);
|
||||
|
||||
try {
|
||||
|
|
|
@ -55,6 +55,7 @@ public class SemanticVersioningSystemTest extends TestBase {
|
|||
"1.1.0+5, 1.1.0+6, 2",
|
||||
})
|
||||
void testCompare(String a, String b, int expected) throws Throwable {
|
||||
if (checkCondition()) return;
|
||||
getLogger().testCall("testCompare", a, b, expected);
|
||||
|
||||
try {
|
||||
|
|
|
@ -54,6 +54,7 @@ public class StarOpenSourceVersioningSystemTest extends TestBase {
|
|||
"v9-beta5, v9-releasecandidate1, 2",
|
||||
})
|
||||
void testCompare(String a, String b, int expected) throws Throwable {
|
||||
if (checkCondition()) return;
|
||||
getLogger().testCall("testCompare", a, b, expected);
|
||||
|
||||
try {
|
||||
|
|
|
@ -46,6 +46,7 @@ public class ThreeNumberVersioningSystemTest extends TestBase {
|
|||
"1.1.0, 1.1.1, 2",
|
||||
})
|
||||
void testCompare(String a, String b, int expected) throws Throwable {
|
||||
if (checkCondition()) return;
|
||||
getLogger().testCall("testCompare", a, b, expected);
|
||||
|
||||
try {
|
||||
|
|
|
@ -46,6 +46,7 @@ public class TwoNumberVersioningSystemTest extends TestBase {
|
|||
"1.5, 2.0, 2",
|
||||
})
|
||||
void testCompare(String a, String b, int expected) throws Throwable {
|
||||
if (checkCondition()) return;
|
||||
getLogger().testCall("testCompare", a, b, expected);
|
||||
|
||||
try {
|
||||
|
|
|
@ -63,6 +63,8 @@ public class MiscellaneousTest extends TestBase {
|
|||
"5819853, 10, 0005819853"
|
||||
})
|
||||
void testPadNumbers(int number, int length, String expected) {
|
||||
if (checkCondition()) return;
|
||||
|
||||
getLogger().testCall("testPadNumbers", number, length, expected);
|
||||
String result = Math.padNumbers(number, length);
|
||||
assertEquals(expected, result, "Result \"" + result + "\" does not match expected output \"" + expected + "\"");
|
||||
|
@ -77,6 +79,7 @@ public class MiscellaneousTest extends TestBase {
|
|||
100, 250, 500
|
||||
})
|
||||
void testMeasureExecutionTime(int sleepingDuration) {
|
||||
if (checkCondition()) return;
|
||||
getLogger().testCall("testMeasureExecutionTime", sleepingDuration);
|
||||
|
||||
long executionTime = Miscellaneous.measureExecutionTime(() -> {
|
||||
|
@ -96,6 +99,7 @@ public class MiscellaneousTest extends TestBase {
|
|||
@Test
|
||||
@DisplayName("getMapValues")
|
||||
void testGetMapValues() {
|
||||
if (checkCondition()) return;
|
||||
getLogger().testCall("testGetMapValues");
|
||||
|
||||
Map<String, String> testMap = new HashMap<>();
|
||||
|
@ -118,10 +122,10 @@ public class MiscellaneousTest extends TestBase {
|
|||
@Test
|
||||
@DisplayName("executeSafely (test 0)")
|
||||
void testExecuteSafely0() {
|
||||
if (checkCondition()) return;
|
||||
getLogger().testCall("testExecuteSafely0");
|
||||
|
||||
throwableCaught = false;
|
||||
|
||||
Miscellaneous.executeSafely(() -> System.out.println("You can safely ignore this message (this comes from MiscellaneousTest#testExecuteSafely0)"), "MiscellaneousTest#testExecuteSafely0");
|
||||
|
||||
assertFalse(throwableCaught, "Event was triggered");
|
||||
|
@ -133,8 +137,8 @@ public class MiscellaneousTest extends TestBase {
|
|||
@Test
|
||||
@DisplayName("executeSafely (test 1)")
|
||||
void testExecuteSafely1() {
|
||||
if (checkCondition()) return;
|
||||
getLogger().testCall("testExecuteSafely1");
|
||||
|
||||
throwableCaught = false;
|
||||
|
||||
// Disable event optimization for instant results
|
||||
|
|
|
@ -49,6 +49,7 @@ class PlaceholderEngineTest extends TestBase {
|
|||
"This %status%!, This works!",
|
||||
})
|
||||
void testProcess(String text, String expected) {
|
||||
if (checkCondition()) return;
|
||||
getLogger().testCall("testProcess", text, expected);
|
||||
|
||||
List<@NotNull Placeholder> placeholders = new ArrayList<>();
|
||||
|
|
|
@ -46,6 +46,7 @@ class PropertiesReaderTest extends TestBase {
|
|||
"a.property.mightLookLikeThis, some value"
|
||||
})
|
||||
void testGetString(String propertyName, String propertyValue) {
|
||||
if (checkCondition()) return;
|
||||
getLogger().testCall("testGetString", propertyName, propertyValue);
|
||||
|
||||
Properties properties = new Properties();
|
||||
|
@ -70,6 +71,7 @@ class PropertiesReaderTest extends TestBase {
|
|||
"nah, no, false",
|
||||
})
|
||||
void testGetBoolean(String propertyName, String propertyValue, boolean expected) {
|
||||
if (checkCondition()) return;
|
||||
getLogger().testCall("testGetBoolean", propertyName, propertyValue, expected);
|
||||
|
||||
Properties properties = new Properties();
|
||||
|
@ -94,6 +96,7 @@ class PropertiesReaderTest extends TestBase {
|
|||
"he's a 1 but he likes 0s, 1, 1",
|
||||
})
|
||||
void testGetByte(String propertyName, String propertyValue, byte expected) {
|
||||
if (checkCondition()) return;
|
||||
getLogger().testCall("testGetByte", propertyName, propertyValue, expected);
|
||||
|
||||
Properties properties = new Properties();
|
||||
|
@ -118,6 +121,7 @@ class PropertiesReaderTest extends TestBase {
|
|||
"he's a 1 but he likes 0s, 1, 1",
|
||||
})
|
||||
void testGetShort(String propertyName, String propertyValue, short expected) {
|
||||
if (checkCondition()) return;
|
||||
getLogger().testCall("testGetShort", propertyName, propertyValue, expected);
|
||||
|
||||
Properties properties = new Properties();
|
||||
|
@ -143,6 +147,7 @@ class PropertiesReaderTest extends TestBase {
|
|||
"he's a 10 but he likes 69, 10, 10",
|
||||
})
|
||||
void testGetInteger(String propertyName, String propertyValue, int expected) {
|
||||
if (checkCondition()) return;
|
||||
getLogger().testCall("testGetInteger", propertyName, propertyValue, expected);
|
||||
|
||||
Properties properties = new Properties();
|
||||
|
@ -168,6 +173,7 @@ class PropertiesReaderTest extends TestBase {
|
|||
"he's a 10 but he likes 69, 10, 10",
|
||||
})
|
||||
void testGetLong(String propertyName, String propertyValue, long expected) {
|
||||
if (checkCondition()) return;
|
||||
getLogger().testCall("testGetLong", propertyName, propertyValue, expected);
|
||||
|
||||
Properties properties = new Properties();
|
||||
|
@ -194,6 +200,7 @@ class PropertiesReaderTest extends TestBase {
|
|||
"he's a 10 but he likes 69, 10.69, 10.69",
|
||||
})
|
||||
void testGetFloat(String propertyName, String propertyValue, float expected) {
|
||||
if (checkCondition()) return;
|
||||
getLogger().testCall("testGetFloat", propertyName, propertyValue, expected);
|
||||
|
||||
Properties properties = new Properties();
|
||||
|
@ -218,6 +225,7 @@ class PropertiesReaderTest extends TestBase {
|
|||
"he's a 10 but he likes 69, 10.69, 10.69",
|
||||
})
|
||||
void testGetDouble(String propertyName, String propertyValue, double expected) {
|
||||
if (checkCondition()) return;
|
||||
getLogger().testCall("testGetDouble", propertyName, propertyValue, expected);
|
||||
|
||||
Properties properties = new Properties();
|
||||
|
|
|
@ -44,6 +44,7 @@ class StackTraceParserTest extends TestBase {
|
|||
"Some description here..."
|
||||
})
|
||||
void testGetHeader(@NotNull String message) {
|
||||
if (checkCondition()) return;
|
||||
getLogger().testCall("testGetHeader", message);
|
||||
|
||||
String output;
|
||||
|
|
Loading…
Reference in a new issue