From 6eae74c3e0ffcc31be87469909da03bb7a980a90 Mon Sep 17 00:00:00 2001 From: Not Zed Date: Sun, 3 Aug 2025 11:40:04 +0930 Subject: [PATCH] Use relative names for test sources Simplify some of the logic to use make functions rather than shell. --- junit4.make | 42 +++++++++++++++++++++++------------------- junit5.make | 10 ++++++---- 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/junit4.make b/junit4.make index 249b14e..abb7efc 100644 --- a/junit4.make +++ b/junit4.make @@ -28,28 +28,29 @@ # It needs some parameterisation, e.g. module path, generated tests, # etc. -# Where to get junit4: -# http://central.maven.org/maven2/junit/junit/4.12/junit-4.12.jar -# http://central.maven.org/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar +maven_central_JARS += junit:junit:4.13.2 org.hamcrest:hamcrest-core:1.3 -# this is from netbeans 11 -junit4_classpath ?= /usr/local/netbeans-11.0/platform/modules/ext/junit-4.12.jar \ - /usr/local/netbeans-11.0/platform/modules/ext/hamcrest-core-1.3.jar -junit4_runner ?= org.junit.runner.JUnitCore +junit4_runner = org.junit.runner.JUnitCore +junit4_classpath = .lib/junit-4.13.2.jar .lib/hamcrest-core-1.3.jar + +dist_EXTRA += junit4.make # ###################################################################### define java_tests= -ifndef $(1)_TEST_JAVA -$(1)_TEST_JAVA := $$(shell find src/$(1)/tests -type f -name '*.java') -$(1)_TEST := $$(subst /,.,$$(basename $$(shell find src/$(1)/tests -type f -name '*Test.java' -printf '%P\n'))) -$(1)_IT := $$(subst /,.,$$(basename $$(shell find src/$(1)/tests -type f -name '*IT.java' -printf '%P\n'))) +ifndef $1_TEST_JAVA +$1_TEST_JAVA := $$(patsubst src/$1/tests/%,%,$$(shell find src/$1/tests -type f -name '*.java')) +$1_TEST := $$(subst /,.,$$(basename $$(filter %Test.java,$$($1_TEST_JAVA)))) +$1_IT := $$(subst /,.,$$(basename $$(filter %IT.java,$$($1_TEST_JAVA)))) +$1_TEST_PACKAGE := $$(subst /,.,$$(patsubst %/,%,$$(sort $$(dir $$($1_TEST_JAVA))))) endif -test: $(1)-test -test-it: $(1)-it -check: $(1)-test $(1)-it -bin/status/$(1).tests: bin/status/$(1).classes $($1_TEST_JAVA) +ifdef $1_TEST_JAVA +test: $1-test +test-it: $1-it +check: $1-test $1-it +bin/status/$1.tests: bin/status/$(1).classes $$($1_TEST_JAVA:%=src/$1/tests/%) +endif endef $(foreach module,$(java_MODULES),$(if $(wildcard src/$(module)/tests),$(eval $(call java_tests,$(module))))) @@ -63,20 +64,21 @@ bin/status/%.tests: -classpath $(subst $(S),:,$(junit4_classpath) ) \ --patch-module $*=src/$*/tests \ --add-reads $*=ALL-UNNAMED \ - -source 11 \ --module-source-path 'src/*/tests' \ - --module-path bin/modules \ + --module-path $(subst $(S),:,bin/modules $(JAVAMODPATH)) \ -d bin/tests \ - $($*_TEST_JAVA) + $($*_TEST_JAVA:%=src/$*/tests/%) touch $@ %-test: bin/status/%.tests $(JAVA) \ --class-path $(subst $(S),:,$(junit4_classpath)) \ - --module-path bin/modules \ + --module-path $(subst $(S),:,bin/modules $(JAVAMODPATH)) \ --patch-module $*=bin/tests/$* \ --add-modules $* \ --add-reads $*=ALL-UNNAMED \ + $(patsubst %,--add-opens $*/%=ALL-UNNAMED,$($*_TEST_PACKAGE)) \ + $(patsubst %,--add-exports $*/%=ALL-UNNAMED,$($*_TEST_PACKAGE)) \ $(junit4_runner) \ $($*_TEST) @@ -87,5 +89,7 @@ bin/status/%.tests: --patch-module $*=bin/tests/$* \ --add-modules $* \ --add-reads $*=ALL-UNNAMED \ + $(patsubst %,--add-opens $*/%=ALL-UNNAMED,$($*_TEST_PACKAGE)) \ + $(patsubst %,--add-exports $*/%=ALL-UNNAMED,$($*_TEST_PACKAGE)) \ $(junit4_runner) \ $($*_IT) diff --git a/junit5.make b/junit5.make index 28513a6..4473e41 100644 --- a/junit5.make +++ b/junit5.make @@ -36,19 +36,21 @@ maven_central_JARS += org.junit.platform:junit-platform-console-standalone:1.13. junit5_module = org.junit.platform.console.standalone junit5_launcher = org.junit.platform.console.ConsoleLauncher +dist_EXTRA += junit5.make + # ###################################################################### define java_tests= ifndef $$($1_TEST_JAVA) -$1_TEST_JAVA := $(shell find src/$1/tests -type f -name '*.java') -$1_TEST_PACKAGE = $$(subst /,.,$$(patsubst src/$1/tests/%/,%,$$(sort $$(dir $$($1_TEST_JAVA))))) +$1_TEST_JAVA := $$(patsubst src/$1/tests/%,%,$(shell find src/$1/tests -type f -name '*.java')) +$1_TEST_PACKAGE = $$(subst /,.,$$(patsubst %/,%,$$(sort $$(dir $$($1_TEST_JAVA))))) endif ifdef $1_TEST_JAVA test: $1-test test-it: $1-it check: $1-test $1-it -bin/status/$1.tests: bin/status/$1.classes $$($1_TEST_JAVA) +bin/status/$1.tests: bin/status/$1.classes $$($1_TEST_JAVA:%=src/$1/tests/%) .PHONY: $1-test $1-it bin/status/$1.tests: @@ -60,7 +62,7 @@ bin/status/$1.tests: --add-reads $1=$(junit5_module),ALL-UNNAMED \ --module-source-path 'src/*/tests' \ -d bin/tests \ - $$($1_TEST_JAVA) + $$($1_TEST_JAVA:%=src/$1/tests/%) touch $$@ $1-test: bin/status/$1.tests -- 2.39.5