From 094c357d91c1fd7c5a7ea165381b00601fe21257 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Tue, 21 Nov 2023 20:25:04 -0500 Subject: [PATCH] Add a basic "make installcheck" function. Add a very simple post-install test which simply attempts to compile, link and run a test program against the installed header and library. --- Makefile.am | 18 ++++++++++++++++++ t/.gitignore | 1 + t/installcheck.c | 38 ++++++++++++++++++++++++++++++++++++++ t/installcheck.exp | 1 + 4 files changed, 58 insertions(+) create mode 100644 t/installcheck.c create mode 100644 t/installcheck.exp diff --git a/Makefile.am b/Makefile.am index 336e443..220280c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -335,6 +335,24 @@ atlocal: config.status check_DATA = atlocal CLEANFILES += atlocal +# Note: to reliably test linking against the installed library we directly +# refer to the just-installed .la file, rather than more typical library flags +# (-Lfoo -lfoo). Otherwise libtool can pick up libcdecl.la from the current +# working directory which defeats the point of an install check. +EXTRA_PROGRAMS = t/installcheck +t_installcheck_CPPFLAGS = -I$(DESTDIR)$(includedir) +t_installcheck_LDADD = $(DESTDIR)$(libdir)/libcdecl.la +t_installcheck_CFLAGS = +t_installcheck_SHORTNAME = x + +installcheck-local: + rm -f t/installcheck$(EXEEXT) + $(MAKE) $(AM_MAKEFLAGS) t/installcheck$(EXEEXT) + t/installcheck$(EXEEXT) | diff - $(srcdir)/t/installcheck.exp +.PHONY: installcheck-local +EXTRA_DIST += t/installcheck.c t/installcheck.exp +CLEANFILES += t/installcheck$(EXEEXT) + include $(top_srcdir)/lib/gnulib.mk include $(top_srcdir)/common/snippet/glconfig.mk include $(top_srcdir)/common/snippet/autotest.mk diff --git a/t/.gitignore b/t/.gitignore index f6bb37d..58a948e 100644 --- a/t/.gitignore +++ b/t/.gitignore @@ -1,5 +1,6 @@ /cdeclerr /crossparse +/installcheck /normalize /randomdecl /rendertest diff --git a/t/installcheck.c b/t/installcheck.c new file mode 100644 index 0000000..1765671 --- /dev/null +++ b/t/installcheck.c @@ -0,0 +1,38 @@ +/* + * Post-installation sanity check for libcdecl. + * + * Copyright © 2023 Nick Bowler + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include + +int main(void) +{ + extern int puts(const char *); + + struct cdecl_declarator decl_array, decl_null = {0}; + struct cdecl_declspec spec = {0, CDECL_TYPE_INT}; + struct cdecl decl = {0, &spec, &decl_array}; + char buf[100]; + + decl_array.child = &decl_null; + decl_array.type = CDECL_DECL_ARRAY; + decl_array.u.array.length = 1234567890; + decl_array.u.array.vla = NULL; + + cdecl_explain(buf, sizeof buf, &decl); + puts(buf); +} diff --git a/t/installcheck.exp b/t/installcheck.exp new file mode 100644 index 0000000..d62e183 --- /dev/null +++ b/t/installcheck.exp @@ -0,0 +1 @@ +type array 1234567890 of int -- 2.43.2