]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
fix test
authorAlan T. DeKok <aland@freeradius.org>
Mon, 18 Aug 2025 18:59:13 +0000 (14:59 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 18 Aug 2025 20:49:19 +0000 (16:49 -0400)
so it actually loads the "good" test dictionary.

add "bad" test dictionaries.  Only one for now.

src/tests/dict/all.mk
src/tests/dict/base.txt [new file with mode: 0644]
src/tests/dict/begin-no-end.error [new file with mode: 0644]
src/tests/dict/begin-no-end.out [new file with mode: 0644]
src/tests/dict/empty.txt [deleted file]

index 9b1f3dcd930344b7489114920a0e0dd9b26c43a2..9213663743bdd44d69f6f22f148a3975f0a0df9b 100644 (file)
@@ -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 (file)
index 0000000..96b293b
--- /dev/null
@@ -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 (file)
index 0000000..b87fbe6
--- /dev/null
@@ -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 (file)
index 0000000..8f87453
--- /dev/null
@@ -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 (file)
index 6ddc2cf..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-#
-#  An empty file to keep unit_test_attribute happy
-#