From: Alan T. DeKok Date: Mon, 11 Mar 2019 19:39:24 +0000 (-0400) Subject: move to new test template X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b2f6e8bb7e18039441b3335ff6ba2b664ef92c68;p=thirdparty%2Ffreeradius-server.git move to new test template --- diff --git a/src/tests/xlat/all.mk b/src/tests/xlat/all.mk index f0b8e74d749..cecd4e7144c 100644 --- a/src/tests/xlat/all.mk +++ b/src/tests/xlat/all.mk @@ -2,52 +2,69 @@ # Unit tests for dynamic xlat expansions # + +# +# Test name +# +TEST := tests.xlat + # # The test files are files without extensions. # The list is unordered. The order is added in the next step by looking # at precursors. # -XLAT_FILES := $(subst $(DIR)/,,$(wildcard $(DIR)/*.txt)) +FILES := $(subst $(DIR)/,,$(wildcard $(DIR)/*.txt)) + +OUTPUT := $(subst $(top_srcdir)/src,$(BUILD_DIR),$(dir $(abspath $(lastword $(MAKEFILE_LIST))))) # # Create the output directory # -.PHONY: $(BUILD_DIR)/tests/xlat -$(BUILD_DIR)/tests/xlat: +.PHONY: $(OUTPUT) +$(OUTPUT): ${Q}mkdir -p $@ # -# Files in the output dir depend on the unit tests +# All of the output files depend on the input files # -# src/tests/keywords/FOO unlang for the test -# src/tests/keywords/FOO.attrs input RADIUS and output filter -# build/tests/keywords/FOO updated if the test succeeds -# build/tests/keywords/FOO.log debug output for the test +FILES.$(TEST) := $(addprefix $(OUTPUT),$(notdir $(FILES))) + # -# If the test fails, then look for ERROR in the input. No error -# means it's unexpected, so we die. +# The output files also depend on the directory +# and on the previous test. # -# Otherwise, check the log file for a parse error which matches the -# ERROR line in the input. +$(FILES.$(TEST)): $(BUILD_DIR)/tests/tests.unit | $(OUTPUT) + # -$(BUILD_DIR)/tests/xlat/%: $(DIR)/% $(TESTBINDIR)/unit_test_module | $(BUILD_DIR)/tests/xlat build.raddb - ${Q}echo XLAT-TEST $(notdir $@) - ${Q}if ! $(TESTBIN)/unit_test_module -D share/dictionary -d src/tests/xlat/ -r "$@" -i "$<" -xx -O xlat_only > "$@.log" 2>&1 || ! test -f "$@"; then \ - cat $@.log; \ - echo "./$(TESTBIN)/unit_test_module -D share/dictionary -d src/tests/xlat/ -r \"$@\" -i \"$<\" -xx -O xlat_only"; \ - exit 1; \ - fi +# We have a real file that's created if all of the tests pass. +# +$(BUILD_DIR)/tests/$(TEST): $(FILES.$(TEST)) + ${Q}touch $@ # -# Get all of the unit test output files +# For simplicity, we create a phony target so that the poor developer +# doesn't need to remember path names # -TESTS.XLAT_FILES := $(addprefix $(BUILD_DIR)/tests/xlat/,$(XLAT_FILES)) +$(TEST): $(BUILD_DIR)/tests/$(TEST) # -# Depend on the output files, and create the directory first. +# Clean the ouput directory and files. +# +# Note that we have to specify the actual filenames here, because +# of stupidities with GNU Make. # -tests.xlat: $(TESTS.XLAT_FILES) +.PHONY: clean.$(TEST) +clean.$(TEST): + ${Q}rm -rf $(BUILD_DIR)/src/tests/xlat $(BUILD_DIR)/tests/tests.xlat -.PHONY: clean.tests.xlat -clean.tests.xlat: - ${Q}rm -rf $(BUILD_DIR)/tests/xlat/ +# +# And the actual script to run each test. +# +$(BUILD_DIR)/tests/xlat/%: $(DIR)/% $(TESTBINDIR)/unit_test_module | build.raddb + ${Q}echo XLAT-TEST $(notdir $@) + ${Q}if ! $(TESTBIN)/unit_test_module -D share/dictionary -d src/tests/xlat/ -r "$@" -i "$<" -xx -O xlat_only > "$@.log" 2>&1 || ! test -f "$@"; then \ + cat $@.log; \ + echo "./$(TESTBIN)/unit_test_module -D share/dictionary -d src/tests/xlat/ -r \"$@\" -i \"$<\" -xx -O xlat_only"; \ + rm -f $(BUILD_DIR)/tests/tests.xlat; \ + exit 1; \ + fi