From: Alan T. DeKok Date: Mon, 18 Aug 2025 18:59:13 +0000 (-0400) Subject: fix test X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4da3d46ae777975f90f011d6406d75e2db52f318;p=thirdparty%2Ffreeradius-server.git fix test so it actually loads the "good" test dictionary. add "bad" test dictionaries. Only one for now. --- diff --git a/src/tests/dict/all.mk b/src/tests/dict/all.mk index 9b1f3dcd930..9213663743b 100644 --- a/src/tests/dict/all.mk +++ b/src/tests/dict/all.mk @@ -6,7 +6,7 @@ TEST := test.dict # # Input files. # -FILES := base.dict +FILES := $(subst $(DIR)/,,$(wildcard $(DIR)/*.dict) $(wildcard $(DIR)/*.error)) $(eval $(call TEST_BOOTSTRAP)) @@ -15,13 +15,60 @@ $(eval $(call TEST_BOOTSTRAP)) # The parser expects to read "foo/dictionary", so we make a # "foo_dir" directory, and copy "foo" into "foo_dir/dictionary" # -$(OUTPUT)/%: $(DIR)/% $(TEST_BIN_DIR)/unit_test_attribute +$(OUTPUT)/%.dict: $(DIR)/%.dict $(TEST_BIN_DIR)/unit_test_attribute @echo "DICT-TEST $(notdir $@)" - ${Q}mkdir -p $@_dir - ${Q}cp $< $@_dir/dictionary - ${Q}if ! $(TEST_BIN)/unit_test_attribute -D $(top_srcdir)/share/dictionary -d "$@_dir" -r "$@" -xxx "$(dir $<)/empty.txt" > "$@.log" 2>&1 || ! test -f "$@"; then \ - echo "$(TEST_BIN)/unit_test_attribute -D $(top_srcdir)/share/dictionary -d \"$@_dir\" -r \"$@\" \"$(dir $<)/empty.txt\""; \ + @cp $< $@ + @cp src/tests/dict/base.txt $@.txt + @echo "load-dictionary $(top_srcdir)/$<" >> $@.txt + ${Q}if ! $(TEST_BIN)/unit_test_attribute -D $(top_srcdir)/share/dictionary -r "$@" "$@.txt" > "$@.log" 2>&1 || ! test -f "$@"; then \ + rm -f $@; \ cat "$@.log"; \ - rm -f $(BUILD_DIR)/tests/test.dict; \ + echo "# $@.log"; \ + echo "$(TEST_BIN)/unit_test_attribute -D $(top_srcdir)/share/dictionary -r "$@" -xx '$@.txt'"; \ exit 1; \ fi + +# And the actual script to run each test. +# +# The parser expects to read "foo/dictionary", so we make a +# "foo_dir" directory, and copy "foo" into "foo_dir/dictionary" +# +$(OUTPUT)/%.dict: $(DIR)/%.dict $(TEST_BIN_DIR)/unit_test_attribute + @echo "DICT-TEST $(notdir $@)" + @cp $< $@ + @cp src/tests/dict/base.txt $@.txt + @echo "load-dictionary $(top_srcdir)/$<" >> $@.txt + ${Q}if ! $(TEST_BIN)/unit_test_attribute -D $(top_srcdir)/share/dictionary -r "$@" "$@.txt" > "$@.log" 2>&1 || ! test -f "$@"; then \ + rm -f $@; \ + cat "$@.log"; \ + echo "# $@.log"; \ + echo "$(TEST_BIN)/unit_test_attribute -D $(top_srcdir)/share/dictionary -r "$@" -xx '$@.txt'"; \ + exit 1; \ + fi + +# +# Tests which are supposed to fail. +# +# Run the test. If it passes, that's a problem. +# +# Fix the output to remove the full pathname. +# +# See if the current output and the expected output are the same. +# +$(OUTPUT)/%.error: $(DIR)/%.error $(TEST_BIN_DIR)/unit_test_attribute + @echo "DICT-TEST $(notdir $@)" + @cp $< $@ + @cp src/tests/dict/base.txt $@.txt + @echo "load-dictionary $(top_srcdir)/$<" >> $@.txt + ${Q}if $(TEST_BIN)/unit_test_attribute -D $(top_srcdir)/share/dictionary "$@.txt" > "$@.log" 2>&1 ; then \ + rm -f $@; \ + cat "$@.log"; \ + echo "# $@.log"; \ + echo "$(TEST_BIN)/unit_test_attribute -D $(top_srcdir)/share/dictionary -xx '$@.txt'"; \ + exit 1; \ + fi + ${Q}sed 's,${top_srcdir}/,,g' < "$@.log" > "$@.out" + ${Q}if ! diff "$@.out" "$(subst .error,,$<).out" ; then \ + echo "diff $@.out $(subst .error,,$<).out"; \ + echo "FAILED"; \ + fi diff --git a/src/tests/dict/base.txt b/src/tests/dict/base.txt new file mode 100644 index 00000000000..96b293b6df1 --- /dev/null +++ b/src/tests/dict/base.txt @@ -0,0 +1,2 @@ +proto radius +proto-dictionary radius diff --git a/src/tests/dict/begin-no-end.error b/src/tests/dict/begin-no-end.error new file mode 100644 index 00000000000..b87fbe6b308 --- /dev/null +++ b/src/tests/dict/begin-no-end.error @@ -0,0 +1,4 @@ +# +# BEGIN without END +# +BEGIN-VENDOR Cisco diff --git a/src/tests/dict/begin-no-end.out b/src/tests/dict/begin-no-end.out new file mode 100644 index 00000000000..8f8745310f8 --- /dev/null +++ b/src/tests/dict/begin-no-end.out @@ -0,0 +1,2 @@ +build/tests/dict/begin-no-end.error.txt[3]: BEGIN-VENDOR at src/tests/dict/begin-no-end.error[4] is missing END-VENDOR +Failed parsing dictionary at src/tests/dict/begin-no-end.error[4] diff --git a/src/tests/dict/empty.txt b/src/tests/dict/empty.txt deleted file mode 100644 index 6ddc2cf220e..00000000000 --- a/src/tests/dict/empty.txt +++ /dev/null @@ -1,3 +0,0 @@ -# -# An empty file to keep unit_test_attribute happy -#