diff mbox series

[v3,2/7] docparse: Add tests

Message ID 20211103120233.20728-3-chrubis@suse.cz
State Accepted
Headers show
Series docparse improvements | expand

Commit Message

Cyril Hrubis Nov. 3, 2021, 12:02 p.m. UTC
This add a simple tests for the docparse parser.

Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
Reviewed-by: Richard Palethorpe <rpalethorpe@suse.com>
---
 docparse/tests/Makefile               |  4 ++++
 docparse/tests/empty_struct.c         |  2 ++
 docparse/tests/empty_struct.c.json    |  3 +++
 docparse/tests/expand_flags.c         |  3 +++
 docparse/tests/expand_flags.c.json    |  6 ++++++
 docparse/tests/include.c              |  5 +++++
 docparse/tests/include.c.json         |  4 ++++
 docparse/tests/include.h              |  1 +
 docparse/tests/macro.c                |  5 +++++
 docparse/tests/macro.c.json           |  4 ++++
 docparse/tests/macro_str.c            |  5 +++++
 docparse/tests/macro_str.c.json       |  4 ++++
 docparse/tests/multiline_macro.c      |  6 ++++++
 docparse/tests/multiline_macro.c.json |  4 ++++
 docparse/tests/tags.c                 |  7 +++++++
 docparse/tests/tags.c.json            | 13 +++++++++++++
 docparse/tests/test.sh                | 18 ++++++++++++++++++
 17 files changed, 94 insertions(+)
 create mode 100644 docparse/tests/Makefile
 create mode 100644 docparse/tests/empty_struct.c
 create mode 100644 docparse/tests/empty_struct.c.json
 create mode 100644 docparse/tests/expand_flags.c
 create mode 100644 docparse/tests/expand_flags.c.json
 create mode 100644 docparse/tests/include.c
 create mode 100644 docparse/tests/include.c.json
 create mode 100644 docparse/tests/include.h
 create mode 100644 docparse/tests/macro.c
 create mode 100644 docparse/tests/macro.c.json
 create mode 100644 docparse/tests/macro_str.c
 create mode 100644 docparse/tests/macro_str.c.json
 create mode 100644 docparse/tests/multiline_macro.c
 create mode 100644 docparse/tests/multiline_macro.c.json
 create mode 100644 docparse/tests/tags.c
 create mode 100644 docparse/tests/tags.c.json
 create mode 100755 docparse/tests/test.sh

Comments

Petr Vorel Nov. 4, 2021, 4:06 p.m. UTC | #1
Hi Cyril,

Reviewed-by: Petr Vorel <pvorel@suse.cz>

> diff --git a/docparse/tests/Makefile b/docparse/tests/Makefile
> new file mode 100644
> index 000000000..b5c8c4668
> --- /dev/null
> +++ b/docparse/tests/Makefile
> @@ -0,0 +1,4 @@
> +all:
> +
> +test:
> +	@./test.sh
How about
1) Run test as default (all: test)?
2) Propagate test target into docparse/Makefile
3) Run docparse testing as part of make test
4) Be more verbose about running docparse tests

These are in patch below.

Also part of lib/newlib_tests/runtest.sh could be put into separate file, which
could be reused in docparse/tests/test.sh (color etc), but that should be postponed
to later to not blocking this patchset.

Kind regards,
Petr

diff --git Makefile Makefile
index 4e37362f9..9ead7b205 100644
--- Makefile
+++ Makefile
@@ -210,6 +210,7 @@ ifneq ($(build),$(host))
 	$(error running tests on cross-compile build not supported)
 endif
 	$(call _test)
+	$(MAKE) test-docparse
 
 test-c: lib-all
 ifneq ($(build),$(host))
@@ -223,6 +224,9 @@ ifneq ($(build),$(host))
 endif
 	$(call _test,-s)
 
+test-docparse:
+	$(MAKE) -C docparse/tests test
+
 ## Help
 .PHONY: help
 help:
diff --git docparse/Makefile docparse/Makefile
index e2defad38..7764d1dc1 100644
--- docparse/Makefile
+++ docparse/Makefile
@@ -74,4 +74,9 @@ metadata.pdf: txt
 	$(METADATA_GENERATOR_CMD) $(METADATA_GENERATOR_PARAMS) $(METADATA_GENERATOR_PARAMS_PDF)
 endif
 
+.PHONY: test
+
+test: metadata.json
+	$(MAKE) -C tests $@
+
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git docparse/tests/Makefile docparse/tests/Makefile
index b5c8c4668..69131ffad 100644
--- docparse/tests/Makefile
+++ docparse/tests/Makefile
@@ -1,4 +1,5 @@
-all:
+all: test
 
 test:
+	$(info Testing docparse)
 	@./test.sh
Cyril Hrubis Nov. 5, 2021, 10:40 a.m. UTC | #2
Hi!
> How about
> 1) Run test as default (all: test)?
> 2) Propagate test target into docparse/Makefile
> 3) Run docparse testing as part of make test
> 4) Be more verbose about running docparse tests
> 
> These are in patch below.
> 
> Also part of lib/newlib_tests/runtest.sh could be put into separate file, which
> could be reused in docparse/tests/test.sh (color etc), but that should be postponed
> to later to not blocking this patchset.
> 
> Kind regards,
> Petr
> 
> diff --git Makefile Makefile
> index 4e37362f9..9ead7b205 100644
> --- Makefile
> +++ Makefile
> @@ -210,6 +210,7 @@ ifneq ($(build),$(host))
>  	$(error running tests on cross-compile build not supported)
>  endif
>  	$(call _test)
> +	$(MAKE) test-docparse
>  
>  test-c: lib-all
>  ifneq ($(build),$(host))
> @@ -223,6 +224,9 @@ ifneq ($(build),$(host))
>  endif
>  	$(call _test,-s)
>  
> +test-docparse:
> +	$(MAKE) -C docparse/tests test

That's have been moved to metadata/tests/ in the last patch of the
series.

Other than that the rest looks good. Feel free to push this on the top
of my patchset with my Reviewed-by:
diff mbox series

Patch

diff --git a/docparse/tests/Makefile b/docparse/tests/Makefile
new file mode 100644
index 000000000..b5c8c4668
--- /dev/null
+++ b/docparse/tests/Makefile
@@ -0,0 +1,4 @@ 
+all:
+
+test:
+	@./test.sh
diff --git a/docparse/tests/empty_struct.c b/docparse/tests/empty_struct.c
new file mode 100644
index 000000000..e5d986413
--- /dev/null
+++ b/docparse/tests/empty_struct.c
@@ -0,0 +1,2 @@ 
+static struct tst_test test = {
+};
diff --git a/docparse/tests/empty_struct.c.json b/docparse/tests/empty_struct.c.json
new file mode 100644
index 000000000..9f49f5332
--- /dev/null
+++ b/docparse/tests/empty_struct.c.json
@@ -0,0 +1,3 @@ 
+  "empty_struct": {
+   "fname": "empty_struct.c"
+  }
\ No newline at end of file
diff --git a/docparse/tests/expand_flags.c b/docparse/tests/expand_flags.c
new file mode 100644
index 000000000..64f6da64e
--- /dev/null
+++ b/docparse/tests/expand_flags.c
@@ -0,0 +1,3 @@ 
+static struct tst_test test = {
+	.all_filesystems = 1,
+};
diff --git a/docparse/tests/expand_flags.c.json b/docparse/tests/expand_flags.c.json
new file mode 100644
index 000000000..cd79dd296
--- /dev/null
+++ b/docparse/tests/expand_flags.c.json
@@ -0,0 +1,6 @@ 
+  "expand_flags": {
+   "all_filesystems": "1",
+   "needs_device": "1",
+   "needs_tmpdir": "1",
+   "fname": "expand_flags.c"
+  }
\ No newline at end of file
diff --git a/docparse/tests/include.c b/docparse/tests/include.c
new file mode 100644
index 000000000..15377e339
--- /dev/null
+++ b/docparse/tests/include.c
@@ -0,0 +1,5 @@ 
+# include "include.h"
+
+static struct tst_test test = {
+	.test_variants = TEST_VARIANTS,
+};
diff --git a/docparse/tests/include.c.json b/docparse/tests/include.c.json
new file mode 100644
index 000000000..b4ef1ccda
--- /dev/null
+++ b/docparse/tests/include.c.json
@@ -0,0 +1,4 @@ 
+  "include": {
+   "test_variants": "10",
+   "fname": "include.c"
+  }
\ No newline at end of file
diff --git a/docparse/tests/include.h b/docparse/tests/include.h
new file mode 100644
index 000000000..efa11d24f
--- /dev/null
+++ b/docparse/tests/include.h
@@ -0,0 +1 @@ 
+#define TEST_VARIANTS 10
diff --git a/docparse/tests/macro.c b/docparse/tests/macro.c
new file mode 100644
index 000000000..296da12f5
--- /dev/null
+++ b/docparse/tests/macro.c
@@ -0,0 +1,5 @@ 
+#define TEST_VARIANTS 10
+
+static struct tst_test test = {
+	.test_variants = TEST_VARIANTS,
+};
diff --git a/docparse/tests/macro.c.json b/docparse/tests/macro.c.json
new file mode 100644
index 000000000..0dc73d8ec
--- /dev/null
+++ b/docparse/tests/macro.c.json
@@ -0,0 +1,4 @@ 
+  "macro": {
+   "test_variants": "10",
+   "fname": "macro.c"
+  }
\ No newline at end of file
diff --git a/docparse/tests/macro_str.c b/docparse/tests/macro_str.c
new file mode 100644
index 000000000..9e5f22489
--- /dev/null
+++ b/docparse/tests/macro_str.c
@@ -0,0 +1,5 @@ 
+#define SYSCALL		"syscall(\"foo\")"
+
+static struct tst_test test = {
+	.syscall = SYSCALL,
+};
diff --git a/docparse/tests/macro_str.c.json b/docparse/tests/macro_str.c.json
new file mode 100644
index 000000000..b16228316
--- /dev/null
+++ b/docparse/tests/macro_str.c.json
@@ -0,0 +1,4 @@ 
+  "macro_str": {
+   "syscall": "syscall(\"foo\")",
+   "fname": "macro_str.c"
+  }
\ No newline at end of file
diff --git a/docparse/tests/multiline_macro.c b/docparse/tests/multiline_macro.c
new file mode 100644
index 000000000..2de58112b
--- /dev/null
+++ b/docparse/tests/multiline_macro.c
@@ -0,0 +1,6 @@ 
+#define TEST_VARIANTS \
+	10
+
+static struct tst_test test = {
+	.test_variants = TEST_VARIANTS,
+};
diff --git a/docparse/tests/multiline_macro.c.json b/docparse/tests/multiline_macro.c.json
new file mode 100644
index 000000000..bafd037da
--- /dev/null
+++ b/docparse/tests/multiline_macro.c.json
@@ -0,0 +1,4 @@ 
+  "multiline_macro": {
+   "test_variants": "10",
+   "fname": "multiline_macro.c"
+  }
\ No newline at end of file
diff --git a/docparse/tests/tags.c b/docparse/tests/tags.c
new file mode 100644
index 000000000..ade3974ff
--- /dev/null
+++ b/docparse/tests/tags.c
@@ -0,0 +1,7 @@ 
+static struct tst_test test = {
+	.tags = (const struct tst_tag[]) {
+		{"tag-name-1", "tag-value-1"},
+		{"tag-name-2", "tag-value-2"},
+		{}
+	}
+};
diff --git a/docparse/tests/tags.c.json b/docparse/tests/tags.c.json
new file mode 100644
index 000000000..14cc14f1c
--- /dev/null
+++ b/docparse/tests/tags.c.json
@@ -0,0 +1,13 @@ 
+  "tags": {
+   "tags": [
+     [
+      "tag-name-1",
+      "tag-value-1"
+     ],
+     [
+      "tag-name-2",
+      "tag-value-2"
+     ]
+    ],
+   "fname": "tags.c"
+  }
\ No newline at end of file
diff --git a/docparse/tests/test.sh b/docparse/tests/test.sh
new file mode 100755
index 000000000..767cc464c
--- /dev/null
+++ b/docparse/tests/test.sh
@@ -0,0 +1,18 @@ 
+#!/bin/sh
+
+fail=0
+
+for i in *.c; do
+	../docparse $i > tmp.json
+	if ! diff tmp.json $i.json &> /dev/null; then
+		echo "***"
+		echo "$i output differs!"
+		diff -u tmp.json $i.json
+		echo "***"
+		fail=1
+	fi
+done
+
+rm -f tmp.json
+
+exit $fail