From e7f69c626ab79c450d430c003b7e427f1c5c885b Mon Sep 17 00:00:00 2001 From: Not Zed Date: Sun, 26 Jan 2020 08:06:45 +1030 Subject: [PATCH] Add test driver --- Makefile | 98 +++++++++++++++++++++++++++++++++++++++++++++++++- config.make.in | 1 + 2 files changed, 98 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 45703c9..0a8b38f 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ include java.make # Work in progress idea for java.make extension to create execution templates notzed.zcl.demo_DEMOS=au.notzed.zcl.tools.clinfo -notzed.zcl.fxdemo_DEMOS=fxdemo.fract.Mandelbrot +notzed.zcl.fxdemo_DEMOS=fxdemo.fract.Mandelbrot fxdemo.fract.Test DEMOFLAGS=--add-exports jdk.incubator.foreign/jdk.incubator.foreign.unsafe=notzed.zcl @@ -35,3 +35,99 @@ run-$(3): $1 -m $1/$2 $(ARGV) endef $(foreach module,$(java_MODULES),$(foreach demo,$($(module)_DEMOS),$(eval $(call java_demo,$(module),$(demo),$(lastword $(subst ., ,$(demo))))))) + +# ###################################################################### +# Work in progress idea for java.make extension to download maven jars + +# server=url, then define server_JARS=publisher:artifact:version +maven_HOSTS=central=https://repo1.maven.org/maven2 + +central_JARS=junit:junit:4.12 \ + org.hamcrest:hamcrest-core:1.3 + +# owner package version host +define maven_func= +.lib/$2-$3.jar: + mkdir -p .lib + wget -O $$@ $(4)/$(subst .,/,$1)/$2/$3/$2-$3.jar +.lib/$2-$3.jar.asc: .lib/$2-$3.jar + wget -O $$@ $(4)/$(subst .,/,$1)/$2/$3/$2-$3.jar.asc + gpg --batch --verify $$@ $$< || ( rm $$@ ; echo "GPG verification failed, you may need to import the public key." ; exit 1 ) +setup: .lib/$2-$3.jar.asc +endef + +$(foreach host,$(maven_HOSTS),\ + $(foreach nver,$($(firstword $(subst =, ,$(host)))_JARS),\ + $(eval $(call maven_func,$(word 1,$(subst :, ,$(nver))),$(word 2,$(subst :, ,$(nver))),$(word 3,$(subst :, ,$(nver))),$(lastword $(subst =, ,$(host))))))) + +# ###################################################################### +# Work in progress idea for java.make extension to run junit + +# TODO: module deps? +# TODO: JAVAFLAGS / DEMOFLAGS / TESTFLAGS? + +TESTFLAGS=--add-exports jdk.incubator.foreign/jdk.incubator.foreign.unsafe=notzed.zcl + +#central_JARS+=junit:junit:4.12 \ +# org.hamcrest:hamcrest-core:1.3 + +junit_JARS=.lib/junit-4.12.jar .lib/hamcrest-core-1.3.jar + +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)_TESTIT := $$(subst /,.,$$(basename $$(shell find src/$(1)/tests -type f -name '*IT.java' -printf '%P\n'))) +endif + +test: $(1)-test +test-it: $(1)-it +check: $(1)-test $(1)-it +bin/status/$(1).tests: $$($(1)_TEST_JAVA) +bin/status/$(1).tests: bin/status/$(1).classes +endef + +.PHONY: test test-it check + +$(foreach module,$(java_MODULES),$(if $(wildcard src/$(module)/tests),$(eval $(call java_tests,$(module))))) +#$(foreach module,$(java_MODULES),$(if $(wildcard src/$(module)/tests),$(info $(call java_tests,$(module))))) + +# ###################################################################### + +# maven format: $(foreach u,$(junit_JARS),.lib/$(word 2,$(subst :, ,$(u)))-$(word 3,$(subst :, ,$(u))).jar) +bin/status/%.tests: $(junit_JARS) + @install -d $(@D) + $(JAVAC) \ + --patch-module $*=src/$*/tests \ + --add-modules junit \ + --add-reads $*=ALL-UNNAMED \ + $(JAVACFLAGS) $($*_JAVACFLAGS) \ + --module-source-path 'src/*/tests' \ + --module-path $(subst $(S),:,.lib bin/modules $(JAVAMODPATH) $($*_JAVAMODPATH)) \ + -d bin/tests \ + $($*_TEST_JAVA) + touch $@ + +%-test: bin/status/%.tests + $(JAVA) \ + --patch-module $*=bin/tests/$* \ + --add-modules $* \ + --add-modules junit \ + --add-reads $*=junit \ + --add-reads $*=ALL-UNNAMED \ + $(TESTFLAGS) $($*_TESTLAGS) \ + --module-path $(subst $(S),:,.lib bin/modules bin/tests $(JAVAMODPATH) $($*_JAVAMODPATH)) \ + org.junit.runner.JUnitCore \ + $($*_TEST) + +%-it: bin/status/%.tests + $(JAVA) \ + --patch-module $*=bin/tests/$* \ + --add-modules $* \ + --add-modules junit \ + --add-reads $*=junit \ + --add-reads $*=ALL-UNNAMED \ + $(TESTFLAGS) $($*_TESTFLAGS) \ + --module-path $(subst $(S),:,.lib bin/modules bin/tests $(JAVAMODPATH) $($*_JAVAMODPATH)) \ + org.junit.runner.JUnitCore \ + $($*_TESTIT) diff --git a/config.make.in b/config.make.in index 9c4401b..64bf34f 100644 --- a/config.make.in +++ b/config.make.in @@ -7,6 +7,7 @@ JAVAFX_HOME ?= /home/notzed/src/jfx/build/sdk JAVACFLAGS += -source 13 JAVACFLAGS += --add-exports jdk.incubator.foreign/jdk.incubator.foreign.unsafe=notzed.zcl +JAVA ?= $(JAVA_HOME)/bin/java JAVAC ?= $(JAVA_HOME)/bin/javac JAR ?= $(JAVA_HOME)/bin/jar JMOD ?= $(JAVA_HOME)/bin/jmod -- 2.39.5