This is an automated email from the ASF dual-hosted git repository. desruisseaux pushed a commit to branch geoapi-4.0 in repository https://gitbox.apache.org/repos/asf/sis.git
commit d3da88c0dd3e777237004b37809c4117b41d0a87 Author: Martin Desruisseaux <martin.desruisse...@geomatys.com> AuthorDate: Wed Feb 21 13:24:50 2024 +0100 Allow to enable extensive tests using environment variable instead of system properties. It appears that system properties were not propagated to the tests when running with Gradle. Fixed another "JUnit 4 to JUnit 5" migration mistake which appeared with extensive tests. --- .../test/org/apache/sis/image/ImageTestCase.java | 9 +-- .../sis/referencing/GeodeticCalculatorTest.java | 4 +- .../referencing/factory/sql/EPSGInstallerTest.java | 4 + .../sis/test/integration/ConsistencyTest.java | 2 +- .../org/apache/sis/test/widget/VisualCheck.java | 8 -- .../test/org/apache/sis/test/TestCase.java | 85 ++++++++++++++++------ .../org/apache/sis/test/TestConfiguration.java | 19 +++++ .../test/org/apache/sis/test/package-info.java | 25 +++++-- 8 files changed, 110 insertions(+), 46 deletions(-) diff --git a/endorsed/src/org.apache.sis.feature/test/org/apache/sis/image/ImageTestCase.java b/endorsed/src/org.apache.sis.feature/test/org/apache/sis/image/ImageTestCase.java index fdd3e98dbf..5212eca181 100644 --- a/endorsed/src/org.apache.sis.feature/test/org/apache/sis/image/ImageTestCase.java +++ b/endorsed/src/org.apache.sis.feature/test/org/apache/sis/image/ImageTestCase.java @@ -31,7 +31,6 @@ import static java.lang.StrictMath.round; import org.junit.jupiter.api.AfterAll; import static org.junit.jupiter.api.Assertions.*; import org.apache.sis.test.TestCase; -import org.apache.sis.test.TestConfiguration; /** @@ -58,10 +57,8 @@ public abstract class ImageTestCase extends TestCase { protected RenderedImage image; /** - * Set to {@code true} for enabling the display of test images. The default value is {@code false}, - * unless the {@value TestConfiguration#SHOW_WIDGET_KEY} system property has been set to {@code "true"}. - * - * @see TestConfiguration#SHOW_WIDGET_KEY + * Set to {@code true} for enabling the display of test images. + * The default value is the {@link #SHOW_WIDGET} value. */ protected boolean viewEnabled; @@ -75,7 +72,7 @@ public abstract class ImageTestCase extends TestCase { * Creates a new test case. */ protected ImageTestCase() { - viewEnabled = Boolean.getBoolean(TestConfiguration.SHOW_WIDGET_KEY); + viewEnabled = SHOW_WIDGET; } /** diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/GeodeticCalculatorTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/GeodeticCalculatorTest.java index 3181a1bcb8..fbfae3d861 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/GeodeticCalculatorTest.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/GeodeticCalculatorTest.java @@ -270,7 +270,7 @@ public class GeodeticCalculatorTest extends TestCase { c.setStartGeographicPoint(-33.0, -71.6); // Valparaíso c.setGeodesicDistance(100000); // 100 km Shape region = c.createGeodesicCircle2D(10000); - if (VisualCheck.SHOW_WIDGET) { + if (SHOW_WIDGET) { VisualCheck.show(region); } final Rectangle2D bounds = region.getBounds2D(); @@ -305,7 +305,7 @@ public class GeodeticCalculatorTest extends TestCase { * The more accurate curve cannot be simplified to a Java2D primitive. */ assertInstanceOf(Path2D.class, multiCurves); - if (VisualCheck.SHOW_WIDGET) { + if (SHOW_WIDGET) { VisualCheck.show(singleCurve, multiCurves); } } diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/factory/sql/EPSGInstallerTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/factory/sql/EPSGInstallerTest.java index 5efbbe76f9..1fd02c110f 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/factory/sql/EPSGInstallerTest.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/factory/sql/EPSGInstallerTest.java @@ -134,6 +134,8 @@ public final class EPSGInstallerTest extends TestCaseWithLogs { /** * Tests the creation of an EPSG database on HSQLDB. * This test is skipped if the SQL scripts are not found. + * Otherwise, this test is enabled by default because it is the fastest database tested in this class, + * at the cost of less data types and less concurrency mechanisms (not used for EPSG installer test). * * @throws Exception if an error occurred while creating the database. */ @@ -155,7 +157,9 @@ public final class EPSGInstallerTest extends TestCaseWithLogs { * @throws Exception if an error occurred while creating the database. */ @Test + @Tag(TAG_SLOW) public void testCreationOnH2() throws Exception { + assumeTrue(RUN_EXTENSIVE_TESTS, "Extensive tests not enabled."); final InstallationScriptProvider scripts = getScripts(); // Needs to be invoked first. try (TestDatabase db = TestDatabase.createOnH2("EPSGInstaller")) { createAndTest(db.source, scripts); diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/test/integration/ConsistencyTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/test/integration/ConsistencyTest.java index 1209abd486..bb04fc79f7 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/test/integration/ConsistencyTest.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/test/integration/ConsistencyTest.java @@ -274,7 +274,7 @@ public final class ConsistencyTest extends TestCase { * that lookup operation should not do a lot of work actually. */ final String lookup = IdentifiedObjects.lookupURN(parsed, null); - assertEquals("Failed to lookup the parsed CRS.", urn, lookup); + assertEquals(urn, lookup, "Failed to lookup the parsed CRS."); } else { print(id.getCode(), "SKIPPED", "Unit conversion factors differ."); } diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/test/widget/VisualCheck.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/test/widget/VisualCheck.java index 9b08432594..5ad9fc424e 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/test/widget/VisualCheck.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/test/widget/VisualCheck.java @@ -22,9 +22,6 @@ import java.awt.event.WindowEvent; import javax.swing.JFrame; import javax.swing.JPanel; -// Test dependencies -import org.apache.sis.test.TestConfiguration; - /** * Methods showing windows for performing visual checks. @@ -33,11 +30,6 @@ import org.apache.sis.test.TestConfiguration; * @author Martin Desruisseaux (Geomatys) */ public final class VisualCheck { - /** - * Whether to show widgets. - */ - public static final boolean SHOW_WIDGET = Boolean.getBoolean(TestConfiguration.SHOW_WIDGET_KEY); - /** * Do not allows instantiation of this class. */ diff --git a/endorsed/src/org.apache.sis.util/test/org/apache/sis/test/TestCase.java b/endorsed/src/org.apache.sis.util/test/org/apache/sis/test/TestCase.java index 42190f05e0..8c60ca339f 100644 --- a/endorsed/src/org.apache.sis.util/test/org/apache/sis/test/TestCase.java +++ b/endorsed/src/org.apache.sis.util/test/org/apache/sis/test/TestCase.java @@ -16,11 +16,13 @@ */ package org.apache.sis.test; +import java.util.Set; import java.io.Console; import java.io.PrintWriter; import java.io.StringWriter; import java.io.OutputStreamWriter; import java.io.UnsupportedEncodingException; +import org.apache.sis.util.internal.Strings; import org.apache.sis.util.logging.MonolineFormatter; // Test dependencies @@ -71,61 +73,96 @@ public abstract class TestCase { /** * Tolerance threshold for strict comparisons of floating point numbers. + * This value can be used in {@code assert} method calls when the method + * signature mandate a tolerance threshold. */ public static final double STRICT = 0; /** - * The output writer where to print debugging information (never {@code null}). - * Texts sent to this printer will be shown only if the test fails, or if the - * {@value org.apache.sis.test.TestConfiguration#VERBOSE_OUTPUT_KEY} system property - * is set to {@code true}. This writer will use the system default encoding, unless - * the {@value org.apache.sis.test.TestConfiguration#OUTPUT_ENCODING_KEY} system - * property has been set to a different value. + * Tag for tests that are slow. + * All tests annotated with this tag should check for the {@link #RUN_EXTENSIVE_TESTS} flag. * - * @see org.apache.sis.test.TestUtilities#forceFlushOutput() + * @see Benchmark#TAG */ - public static final PrintWriter out; + public static final String TAG_SLOW = "Slow"; /** - * The buffer which is backing the {@linkplain #out} stream. + * Whether to run more extensive tests. This is set to the value specified by the + * {@value org.apache.sis.test.TestConfiguration#EXTENSIVE_TESTS_KEY} system property if defined, + * or otherwise this is {@code true} if the {@value org.apache.sis.test.TestConfiguration#SIS_TEST_OPTIONS} + * environment variable contains the "extensive" word. If {@code true}, then Apache SIS will run some tests + * which were normally skipped because they are slow. + * + * <p>All tests using this condition should be annotated with {@code @Tag(TAG_SLOW)}.</p> */ - private static final StringWriter buffer; + public static final boolean RUN_EXTENSIVE_TESTS; /** - * {@code true} if the {@value org.apache.sis.test.TestConfiguration#VERBOSE_OUTPUT_KEY} - * system property is set to {@code true}. + * Whether the tests should print debugging information. This is set to the value specified by the + * {@value org.apache.sis.test.TestConfiguration#VERBOSE_OUTPUT_KEY} system property if defined, + * or otherwise this is {@code true} if the {@value org.apache.sis.test.TestConfiguration#SIS_TEST_OPTIONS} + * environment variable contains the "verbose" word. If {@code true}, then the content of {@link #out} will + * be sent to the standard output stream after each test. + * + * @see #out */ public static final boolean VERBOSE; /** - * Tag for tests that are slow. - * All tests annotated with this tag should check for the {@link #RUN_EXTENSIVE_TESTS} flag. - * - * @see Benchmark#TAG + * Whether the tests can allowed to popup a widget. This is set to the value specified by the + * {@value org.apache.sis.test.TestConfiguration#SHOW_WIDGET_KEY} system property if defined, + * or otherwise this is {@code true} if the {@value org.apache.sis.test.TestConfiguration#SIS_TEST_OPTIONS} + * environment variable contains the "widget" word. Only a few tests provide visualization widget. */ - public static final String TAG_SLOW = "Slow"; + public static final boolean SHOW_WIDGET; /** - * {@code true} if the {@value org.apache.sis.test.TestConfiguration#EXTENSIVE_TESTS_KEY} - * system property is set to {@code true}. - * If {@code true}, then Apache SIS will run some tests which were normally skipped because they are slow. + * The output writer where to print debugging information (never {@code null}). + * Texts sent to this printer will be shown only if the test fails, or if the + * {@link #VERBOSE} flag is {@code true}. This writer will use the system default encoding, + * unless the {@value org.apache.sis.test.TestConfiguration#OUTPUT_ENCODING_KEY} system property + * has been set to a different value. * - * <p>All tests using this condition should be annotated with {@code @Tag(TAG_SLOW)}.</p> + * @see TestUtilities#forceFlushOutput() */ - public static final boolean RUN_EXTENSIVE_TESTS; + public static final PrintWriter out; + + /** + * The buffer which is backing the {@linkplain #out} stream. + */ + private static final StringWriter buffer; /** * Sets the {@link #out} writer and its underlying {@link #buffer}. */ static { out = new PrintWriter(buffer = new StringWriter()); - VERBOSE = Boolean.getBoolean(TestConfiguration.VERBOSE_OUTPUT_KEY); - RUN_EXTENSIVE_TESTS = Boolean.getBoolean(TestConfiguration.EXTENSIVE_TESTS_KEY); + final Set<String> options = Set.of(Strings.orEmpty(System.getenv(TestConfiguration.SIS_TEST_OPTIONS)).split(",")); + RUN_EXTENSIVE_TESTS = isEnabled(options, "extensive", TestConfiguration.EXTENSIVE_TESTS_KEY); + SHOW_WIDGET = isEnabled(options, "widget", TestConfiguration.SHOW_WIDGET_KEY); + VERBOSE = isEnabled(options, "verbose", TestConfiguration.VERBOSE_OUTPUT_KEY); if (VERBOSE) { System.setErr(System.out); // For avoiding log records to be interleaved with block of text. } } + /** + * Returns whether the user has enabled an option. + * + * @param options {@value org.apache.sis.test.TestConfiguration#SIS_TEST_OPTIONS} environment variable content. + * @param keyword keyword to search in {@code options}. + * @param property system property to search. + * @return whether the specified option is enabled. + */ + private static boolean isEnabled(final Set<String> options, final String keyword, final String property) { + final String value = System.getProperty(property); + if (value != null) { + return Boolean.parseBoolean(value); + } else { + return options.contains(keyword); + } + } + /** * Installs Apache SIS monoline formatter for easier identification of Apache SIS log messages among Maven outputs. */ diff --git a/endorsed/src/org.apache.sis.util/test/org/apache/sis/test/TestConfiguration.java b/endorsed/src/org.apache.sis.util/test/org/apache/sis/test/TestConfiguration.java index 8b2e92012b..64dd808442 100644 --- a/endorsed/src/org.apache.sis.util/test/org/apache/sis/test/TestConfiguration.java +++ b/endorsed/src/org.apache.sis.util/test/org/apache/sis/test/TestConfiguration.java @@ -25,10 +25,23 @@ import org.apache.sis.util.Static; * @author Martin Desruisseaux (Geomatys) */ public final class TestConfiguration extends Static { + /** + * Environment variable to use as a fallback if a system property is not set. + * This is a comma-separated list of the following keywords, without spaces: + * {@code extensive}, {@code verbose}. + * + * @see TestCase#RUN_EXTENSIVE_TESTS + * @see TestCase#VERBOSE + * @see TestCase#SHOW_WIDGET + */ + public static final String SIS_TEST_OPTIONS = "SIS_TEST_OPTIONS"; + /** * The {@systemProperty org.apache.sis.test.extensive} system property for enabling more extensive tests. * If this {@linkplain System#getProperties() system property} is set to {@code true}, * then Apache SIS will run some tests which were normally skipped because they are slow. + * + * @see TestCase#RUN_EXTENSIVE_TESTS */ public static final String EXTENSIVE_TESTS_KEY = "org.apache.sis.test.extensive"; @@ -36,12 +49,16 @@ public final class TestConfiguration extends Static { * The {@systemProperty org.apache.sis.test.verbose} system property for enabling verbose outputs. * If this {@linkplain System#getProperties() system property} is set to {@code true}, * then the content sent to the {@link TestCase#out} field will be printed after each test. + * + * @see TestCase#VERBOSE */ public static final String VERBOSE_OUTPUT_KEY = "org.apache.sis.test.verbose"; /** * The {@systemProperty org.apache.sis.test.gui.show} system property * for enabling display of test images or widgets. + * + * @see TestCase#SHOW_WIDGET */ public static final String SHOW_WIDGET_KEY = "org.apache.sis.test.gui.show"; @@ -50,6 +67,8 @@ public final class TestConfiguration extends Static { * This property is used only if the {@link #VERBOSE_OUTPUT_KEY} property * is set to "{@code true}". If this property is not set, then the system * encoding will be used. + * + * @see TestCase#out */ public static final String OUTPUT_ENCODING_KEY = "org.apache.sis.test.encoding"; diff --git a/endorsed/src/org.apache.sis.util/test/org/apache/sis/test/package-info.java b/endorsed/src/org.apache.sis.util/test/org/apache/sis/test/package-info.java index 1ffd758d8d..c9fa88de61 100644 --- a/endorsed/src/org.apache.sis.util/test/org/apache/sis/test/package-info.java +++ b/endorsed/src/org.apache.sis.util/test/org/apache/sis/test/package-info.java @@ -22,12 +22,14 @@ * commonly used in SIS tests. * * <h2>Outputs configuration</h2> - * By default, successful tests do not produce any output. However, it is possible to ask for - * verbose outputs, which is sometimes useful for debugging purpose. This behavior is controlled - * from the command line by defining {@linkplain java.lang.System#getProperties() system properties} - * values like below: + * By default, successful tests should not print anything. However, it is sometime useful to get + * test outputs even when successful. This behavior can be controlled from the command line by + * defining {@linkplain java.lang.System#getProperties() system properties} values like below: * * <ul class="verbose"> + * <li><b>{@code -Dorg.apache.sis.test.extensive=true}</b><br> + * For enabling more extensive tests.</li> + * * <li><b>{@code -Dorg.apache.sis.test.verbose=true}</b><br> * For enabling verbose outputs to the {@linkplain java.lang.System#console() console} if any, * or to the {@linkplain java.lang.System#out standard output stream} otherwise.</li> @@ -35,10 +37,23 @@ * <li><b>{@code -Dorg.apache.sis.test.encoding=UTF-8}</b> (or any other valid encoding name)<br> * For the encoding of the above-cited verbose output, and the encoding of logging messages * sent to the {@linkplain java.util.logging.ConsoleHandler console handler}. - * This is useful on Windows or MacOS platforms having a console encoding different than the + * This is useful on Windows platforms having a console encoding different than the * platform encoding. If omitted, then the platform encoding will be used.</li> * </ul> * + * Alternatively, the behavior can also be controlled by specifying a comma-separated + * list of values in the {@code SIS_TEST_OPTIONS} environment variable. Values can be: + * + * <ul> + * <li><b>{@code extensive}:</b> + * For running more tests.</li> + * <li><b>{@code verbose}:</b> + * For enabling verbose outputs to the {@linkplain java.lang.System#console() console} if any, + * or to the {@linkplain java.lang.System#out standard output stream} otherwise.</li> + * </ul> + * + * If both system properties and environment variable are defined, the system property has precedence. + * * @author Martin Desruisseaux (Geomatys) */ package org.apache.sis.test;