From 61fd3be0b0fb9df04ea6ac47d552ceaff0a75aa6 Mon Sep 17 00:00:00 2001 From: Piotr Pawel Stefaniak Date: Fri, 10 Feb 2017 09:31:39 +0000 Subject: [PATCH] indent(1): add regression test cases These examples show expected behavior of indent(1). They are meant to be used together with a regression test mechanism, either Kyua, a Makefile or perhaps something else. The mechanism should in essence do this: indent -P${test}.pro < ${test}.0 > ${test}.0.run and compare ${test}.0.stdout to ${test}.0.run. If the files differ or the exit status isn't 0, the test failed. * ${test}.pro is an indent(1) profile: a list of options passed through a file. The program doesn't complain if the file doesn't exist. * ${test}.0 is a C source file which acts as input for indent(1). It doesn't have to have any particular formatting, since it's the output that matters. * ${test}.0.stdout contains expected output. It doesn't have to be formatted in Kernel Normal Form as the point of the tests is to check for regressions in the program and not to check that it always produces KNF. Reviewed by: ngie Approved by: pfg (mentor) Differential Revision: https://reviews.freebsd.org/D9007 --- usr.bin/indent/tests/comments.0 | 25 +++++++++++++++ usr.bin/indent/tests/comments.0.stdout | 32 +++++++++++++++++++ usr.bin/indent/tests/declarations.0 | 21 ++++++++++++ usr.bin/indent/tests/declarations.0.stdout | 15 +++++++++ usr.bin/indent/tests/elsecomment.0 | 18 +++++++++++ usr.bin/indent/tests/elsecomment.0.stdout | 22 +++++++++++++ usr.bin/indent/tests/elsecomment.pro | 2 ++ usr.bin/indent/tests/float.0 | 6 ++++ usr.bin/indent/tests/float.0.stdout | 8 +++++ usr.bin/indent/tests/label.0 | 13 ++++++++ usr.bin/indent/tests/label.0.stdout | 14 ++++++++ usr.bin/indent/tests/label.pro | 2 ++ usr.bin/indent/tests/list_head.0 | 16 ++++++++++ usr.bin/indent/tests/list_head.0.stdout | 14 ++++++++ usr.bin/indent/tests/nsac.0 | 4 +++ usr.bin/indent/tests/nsac.0.stdout | 6 ++++ usr.bin/indent/tests/nsac.pro | 2 ++ usr.bin/indent/tests/offsetof.0 | 5 +++ usr.bin/indent/tests/offsetof.0.stdout | 7 ++++ usr.bin/indent/tests/sac.0 | 4 +++ usr.bin/indent/tests/sac.0.stdout | 6 ++++ usr.bin/indent/tests/sac.pro | 2 ++ usr.bin/indent/tests/struct.0 | 13 ++++++++ usr.bin/indent/tests/struct.0.stdout | 13 ++++++++ usr.bin/indent/tests/surplusbad.0 | 9 ++++++ usr.bin/indent/tests/surplusbad.0.stdout | 9 ++++++ usr.bin/indent/tests/surplusbad.pro | 2 ++ usr.bin/indent/tests/types_from_file.0 | 3 ++ usr.bin/indent/tests/types_from_file.0.stdout | 3 ++ usr.bin/indent/tests/types_from_file.list | 2 ++ usr.bin/indent/tests/types_from_file.pro | 2 ++ usr.bin/indent/tests/wchar.0 | 6 ++++ usr.bin/indent/tests/wchar.0.stdout | 6 ++++ 33 files changed, 312 insertions(+) create mode 100644 usr.bin/indent/tests/comments.0 create mode 100644 usr.bin/indent/tests/comments.0.stdout create mode 100644 usr.bin/indent/tests/declarations.0 create mode 100644 usr.bin/indent/tests/declarations.0.stdout create mode 100644 usr.bin/indent/tests/elsecomment.0 create mode 100644 usr.bin/indent/tests/elsecomment.0.stdout create mode 100644 usr.bin/indent/tests/elsecomment.pro create mode 100644 usr.bin/indent/tests/float.0 create mode 100644 usr.bin/indent/tests/float.0.stdout create mode 100644 usr.bin/indent/tests/label.0 create mode 100644 usr.bin/indent/tests/label.0.stdout create mode 100644 usr.bin/indent/tests/label.pro create mode 100644 usr.bin/indent/tests/list_head.0 create mode 100644 usr.bin/indent/tests/list_head.0.stdout create mode 100644 usr.bin/indent/tests/nsac.0 create mode 100644 usr.bin/indent/tests/nsac.0.stdout create mode 100644 usr.bin/indent/tests/nsac.pro create mode 100644 usr.bin/indent/tests/offsetof.0 create mode 100644 usr.bin/indent/tests/offsetof.0.stdout create mode 100644 usr.bin/indent/tests/sac.0 create mode 100644 usr.bin/indent/tests/sac.0.stdout create mode 100644 usr.bin/indent/tests/sac.pro create mode 100644 usr.bin/indent/tests/struct.0 create mode 100644 usr.bin/indent/tests/struct.0.stdout create mode 100644 usr.bin/indent/tests/surplusbad.0 create mode 100644 usr.bin/indent/tests/surplusbad.0.stdout create mode 100644 usr.bin/indent/tests/surplusbad.pro create mode 100644 usr.bin/indent/tests/types_from_file.0 create mode 100644 usr.bin/indent/tests/types_from_file.0.stdout create mode 100644 usr.bin/indent/tests/types_from_file.list create mode 100644 usr.bin/indent/tests/types_from_file.pro create mode 100644 usr.bin/indent/tests/wchar.0 create mode 100644 usr.bin/indent/tests/wchar.0.stdout diff --git a/usr.bin/indent/tests/comments.0 b/usr.bin/indent/tests/comments.0 new file mode 100644 index 00000000000..e642bccab42 --- /dev/null +++ b/usr.bin/indent/tests/comments.0 @@ -0,0 +1,25 @@ +/* $FreeBSD$ */ +/* See r303597, r303598, r309219, and r309343 */ +void t(void) { + /* + * Old indent wrapped the URL near where this sentence ends. + * + * https://www.freebsd.org/cgi/man.cgi?query=indent&apropos=0&sektion=0&manpath=FreeBSD+12-current&arch=default&format=html + */ + + /* + * Old indent did not wrap to column 78 + * + * aaaaaa bbbbbb cccccc dddddd eeeeee ffffff ggggg hhhhh iiiii jjjj kk + */ + + /* + * Old indent unnecessarily removed the star comment continuation on the next line. + * + * *test* + */ + + /* r309219 Go through linked list, freeing from the malloced (t[-1]) address. */ + + /* r309343 */ +} diff --git a/usr.bin/indent/tests/comments.0.stdout b/usr.bin/indent/tests/comments.0.stdout new file mode 100644 index 00000000000..62417bd5e99 --- /dev/null +++ b/usr.bin/indent/tests/comments.0.stdout @@ -0,0 +1,32 @@ +/* $FreeBSD$ */ +/* See r303597, r303598, r309219, and r309343 */ +void +t(void) +{ + /* + * Old indent wrapped the URL near where this sentence ends. + * + * https://www.freebsd.org/cgi/man.cgi?query=indent&apropos=0&sektion=0&manpath=FreeBSD+12-current&arch=default&format=html + */ + + /* + * Old indent did not wrap to column 78 + * + * aaaaaa bbbbbb cccccc dddddd eeeeee ffffff ggggg hhhhh iiiii jjjj + * kk + */ + + /* + * Old indent unnecessarily removed the star comment continuation on + * the next line. + * + * *test* + */ + + /* + * r309219 Go through linked list, freeing from the malloced (t[-1]) + * address. + */ + + /* r309343 */ +} diff --git a/usr.bin/indent/tests/declarations.0 b/usr.bin/indent/tests/declarations.0 new file mode 100644 index 00000000000..31183ac255b --- /dev/null +++ b/usr.bin/indent/tests/declarations.0 @@ -0,0 +1,21 @@ +/* $FreeBSD$ */ +/* See r303570 */ +void t(void) { + int a, + b, + c; + int + *d, + *e, + *f; + int (*g)(), + (*h)(), + (*i)(); + int j, + k, + l; + int m + ,n + ,o + ; +} diff --git a/usr.bin/indent/tests/declarations.0.stdout b/usr.bin/indent/tests/declarations.0.stdout new file mode 100644 index 00000000000..972dd3806dc --- /dev/null +++ b/usr.bin/indent/tests/declarations.0.stdout @@ -0,0 +1,15 @@ +/* $FreeBSD$ */ +/* See r303570 */ +void +t(void) +{ + int a, b, c; + int + *d, *e, *f; + int (*g) (), (*h) (), (*i) (); + int j, k, l; + int m + ,n + ,o + ; +} diff --git a/usr.bin/indent/tests/elsecomment.0 b/usr.bin/indent/tests/elsecomment.0 new file mode 100644 index 00000000000..6744e19e077 --- /dev/null +++ b/usr.bin/indent/tests/elsecomment.0 @@ -0,0 +1,18 @@ +/* $FreeBSD$ */ +/* See r303484 and r309342 */ +void t(void) { + if (0) { + + } /* Old indent would remove the following blank line */ + + /* + * test + */ + + if (1) + ; + else /* Old indent would get very confused here */ + { + + } +} diff --git a/usr.bin/indent/tests/elsecomment.0.stdout b/usr.bin/indent/tests/elsecomment.0.stdout new file mode 100644 index 00000000000..ce78e1701e4 --- /dev/null +++ b/usr.bin/indent/tests/elsecomment.0.stdout @@ -0,0 +1,22 @@ +/* $FreeBSD$ */ +/* See r303484 and r309342 */ +void +t(void) +{ + if (0) + { + + } /* Old indent would remove the following + * blank line */ + + /* + * test + */ + + if (1) + ; + else /* Old indent would get very confused here */ + { + + } +} diff --git a/usr.bin/indent/tests/elsecomment.pro b/usr.bin/indent/tests/elsecomment.pro new file mode 100644 index 00000000000..892386ffbf4 --- /dev/null +++ b/usr.bin/indent/tests/elsecomment.pro @@ -0,0 +1,2 @@ +/* $FreeBSD$ */ +-bl diff --git a/usr.bin/indent/tests/float.0 b/usr.bin/indent/tests/float.0 new file mode 100644 index 00000000000..91f017fc1ce --- /dev/null +++ b/usr.bin/indent/tests/float.0 @@ -0,0 +1,6 @@ +/* $FreeBSD$ */ +/* See r303499 */ +void t(void) { + unsigned long x = 314UL; + float y = 3.14f; +} diff --git a/usr.bin/indent/tests/float.0.stdout b/usr.bin/indent/tests/float.0.stdout new file mode 100644 index 00000000000..03d92c316de --- /dev/null +++ b/usr.bin/indent/tests/float.0.stdout @@ -0,0 +1,8 @@ +/* $FreeBSD$ */ +/* See r303499 */ +void +t(void) +{ + unsigned long x = 314UL; + float y = 3.14f; +} diff --git a/usr.bin/indent/tests/label.0 b/usr.bin/indent/tests/label.0 new file mode 100644 index 00000000000..7798a4d5c24 --- /dev/null +++ b/usr.bin/indent/tests/label.0 @@ -0,0 +1,13 @@ +/* $FreeBSD$ */ +/* See r303489 */ +void t(void) { + switch (1) + { + case 1: /* test */ + case 2: /* test */ + } +CLEANUP: + ; +V: ; +U: ; +} diff --git a/usr.bin/indent/tests/label.0.stdout b/usr.bin/indent/tests/label.0.stdout new file mode 100644 index 00000000000..99314f2aeda --- /dev/null +++ b/usr.bin/indent/tests/label.0.stdout @@ -0,0 +1,14 @@ +/* $FreeBSD$ */ +/* See r303489 */ +void +t(void) +{ + switch (1) { + case 1: /* test */ + case 2: /* test */ + } +CLEANUP: + ; +V: ; +U: ; +} diff --git a/usr.bin/indent/tests/label.pro b/usr.bin/indent/tests/label.pro new file mode 100644 index 00000000000..b5afc20b7c0 --- /dev/null +++ b/usr.bin/indent/tests/label.pro @@ -0,0 +1,2 @@ +/* $FreeBSD$ */ +-nut diff --git a/usr.bin/indent/tests/list_head.0 b/usr.bin/indent/tests/list_head.0 new file mode 100644 index 00000000000..3a186ca33e0 --- /dev/null +++ b/usr.bin/indent/tests/list_head.0 @@ -0,0 +1,16 @@ +/* $FreeBSD$ */ +/* See r309380 */ +static int +do_execve(td, args, mac_p) + struct thread *td; + struct image_args *args; + struct mac *mac_p; +{ + +} + +static LIST_HEAD(, alq) ald_active; +static int ald_shuttingdown = 0; +struct thread *ald_thread; + + diff --git a/usr.bin/indent/tests/list_head.0.stdout b/usr.bin/indent/tests/list_head.0.stdout new file mode 100644 index 00000000000..b6f076241a0 --- /dev/null +++ b/usr.bin/indent/tests/list_head.0.stdout @@ -0,0 +1,14 @@ +/* $FreeBSD$ */ +/* See r309380 */ +static int +do_execve(td, args, mac_p) + struct thread *td; + struct image_args *args; + struct mac *mac_p; +{ + +} + +static LIST_HEAD(, alq) ald_active; +static int ald_shuttingdown = 0; +struct thread *ald_thread; diff --git a/usr.bin/indent/tests/nsac.0 b/usr.bin/indent/tests/nsac.0 new file mode 100644 index 00000000000..449eadf3ae0 --- /dev/null +++ b/usr.bin/indent/tests/nsac.0 @@ -0,0 +1,4 @@ +/* $FreeBSD$ */ +void t(void) { + int a = (double) 8; +} diff --git a/usr.bin/indent/tests/nsac.0.stdout b/usr.bin/indent/tests/nsac.0.stdout new file mode 100644 index 00000000000..16209319c47 --- /dev/null +++ b/usr.bin/indent/tests/nsac.0.stdout @@ -0,0 +1,6 @@ +/* $FreeBSD$ */ +void +t(void) +{ + int a = (double)8; +} diff --git a/usr.bin/indent/tests/nsac.pro b/usr.bin/indent/tests/nsac.pro new file mode 100644 index 00000000000..ce2e4fe29be --- /dev/null +++ b/usr.bin/indent/tests/nsac.pro @@ -0,0 +1,2 @@ +/* $FreeBSD$ */ +-nsac diff --git a/usr.bin/indent/tests/offsetof.0 b/usr.bin/indent/tests/offsetof.0 new file mode 100644 index 00000000000..078db19c291 --- /dev/null +++ b/usr.bin/indent/tests/offsetof.0 @@ -0,0 +1,5 @@ +/* $FreeBSD$ */ +/* See r303718 */ +void t(void) { + int n = malloc(offsetof(struct s, f) + 1); +} diff --git a/usr.bin/indent/tests/offsetof.0.stdout b/usr.bin/indent/tests/offsetof.0.stdout new file mode 100644 index 00000000000..d9f16d93e1d --- /dev/null +++ b/usr.bin/indent/tests/offsetof.0.stdout @@ -0,0 +1,7 @@ +/* $FreeBSD$ */ +/* See r303718 */ +void +t(void) +{ + int n = malloc(offsetof(struct s, f) + 1); +} diff --git a/usr.bin/indent/tests/sac.0 b/usr.bin/indent/tests/sac.0 new file mode 100644 index 00000000000..449eadf3ae0 --- /dev/null +++ b/usr.bin/indent/tests/sac.0 @@ -0,0 +1,4 @@ +/* $FreeBSD$ */ +void t(void) { + int a = (double) 8; +} diff --git a/usr.bin/indent/tests/sac.0.stdout b/usr.bin/indent/tests/sac.0.stdout new file mode 100644 index 00000000000..a0e2e71362c --- /dev/null +++ b/usr.bin/indent/tests/sac.0.stdout @@ -0,0 +1,6 @@ +/* $FreeBSD$ */ +void +t(void) +{ + int a = (double) 8; +} diff --git a/usr.bin/indent/tests/sac.pro b/usr.bin/indent/tests/sac.pro new file mode 100644 index 00000000000..ad5cf1a8093 --- /dev/null +++ b/usr.bin/indent/tests/sac.pro @@ -0,0 +1,2 @@ +/* $FreeBSD$ */ +-sac diff --git a/usr.bin/indent/tests/struct.0 b/usr.bin/indent/tests/struct.0 new file mode 100644 index 00000000000..9dfc31de9a0 --- /dev/null +++ b/usr.bin/indent/tests/struct.0 @@ -0,0 +1,13 @@ +/* $FreeBSD$ */ +/* See r303485 */ +void +t(void) +{ + static const struct { + int a; + int b; + } c[] = { + { D, E }, + { F, G } + }; +} diff --git a/usr.bin/indent/tests/struct.0.stdout b/usr.bin/indent/tests/struct.0.stdout new file mode 100644 index 00000000000..ef62a12e8f8 --- /dev/null +++ b/usr.bin/indent/tests/struct.0.stdout @@ -0,0 +1,13 @@ +/* $FreeBSD$ */ +/* See r303485 */ +void +t(void) +{ + static const struct { + int a; + int b; + } c[] = { + {D, E}, + {F, G} + }; +} diff --git a/usr.bin/indent/tests/surplusbad.0 b/usr.bin/indent/tests/surplusbad.0 new file mode 100644 index 00000000000..07d07026db0 --- /dev/null +++ b/usr.bin/indent/tests/surplusbad.0 @@ -0,0 +1,9 @@ +/* $FreeBSD$ */ +/* See r303599 */ +#if defined(__i386__) +int a; +#elif defined(__amd64__) +int b; +#else +#error "Port me" +#endif diff --git a/usr.bin/indent/tests/surplusbad.0.stdout b/usr.bin/indent/tests/surplusbad.0.stdout new file mode 100644 index 00000000000..b288970fb93 --- /dev/null +++ b/usr.bin/indent/tests/surplusbad.0.stdout @@ -0,0 +1,9 @@ +/* $FreeBSD$ */ +/* See r303599 */ +#if defined(__i386__) +int a; +#elif defined(__amd64__) +int b; +#else +#error "Port me" +#endif diff --git a/usr.bin/indent/tests/surplusbad.pro b/usr.bin/indent/tests/surplusbad.pro new file mode 100644 index 00000000000..77c3a28ceb0 --- /dev/null +++ b/usr.bin/indent/tests/surplusbad.pro @@ -0,0 +1,2 @@ +/* $FreeBSD$ */ +-bad diff --git a/usr.bin/indent/tests/types_from_file.0 b/usr.bin/indent/tests/types_from_file.0 new file mode 100644 index 00000000000..6efca24fe1b --- /dev/null +++ b/usr.bin/indent/tests/types_from_file.0 @@ -0,0 +1,3 @@ +/* $FreeBSD$ */ +/* See r303735 */ +void t(a *x, b *y, c *z); diff --git a/usr.bin/indent/tests/types_from_file.0.stdout b/usr.bin/indent/tests/types_from_file.0.stdout new file mode 100644 index 00000000000..8776ca6ba88 --- /dev/null +++ b/usr.bin/indent/tests/types_from_file.0.stdout @@ -0,0 +1,3 @@ +/* $FreeBSD$ */ +/* See r303735 */ +void t(a *x, b *y, c * z); diff --git a/usr.bin/indent/tests/types_from_file.list b/usr.bin/indent/tests/types_from_file.list new file mode 100644 index 00000000000..5f733616b1b --- /dev/null +++ b/usr.bin/indent/tests/types_from_file.list @@ -0,0 +1,2 @@ +b +a \ No newline at end of file diff --git a/usr.bin/indent/tests/types_from_file.pro b/usr.bin/indent/tests/types_from_file.pro new file mode 100644 index 00000000000..571b673697d --- /dev/null +++ b/usr.bin/indent/tests/types_from_file.pro @@ -0,0 +1,2 @@ +/* $FreeBSD$ */ +-Utypes_from_file.list diff --git a/usr.bin/indent/tests/wchar.0 b/usr.bin/indent/tests/wchar.0 new file mode 100644 index 00000000000..9910e77857f --- /dev/null +++ b/usr.bin/indent/tests/wchar.0 @@ -0,0 +1,6 @@ +/* $FreeBSD$ */ +/* See r309220 */ +#include + +wchar_t *x = L"test"; +wchar_t y = L't'; diff --git a/usr.bin/indent/tests/wchar.0.stdout b/usr.bin/indent/tests/wchar.0.stdout new file mode 100644 index 00000000000..92774abfdd3 --- /dev/null +++ b/usr.bin/indent/tests/wchar.0.stdout @@ -0,0 +1,6 @@ +/* $FreeBSD$ */ +/* See r309220 */ +#include + +wchar_t *x = L"test"; +wchar_t y = L't';