From 2739fa06479f62bcd657a6f9d1a3097441ad8b8e Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Sun, 26 Feb 2012 17:13:53 -0500 Subject: [PATCH] Add a test case to verify symbol prefixes. Our very first automated test case! --- .gitignore | 1 + Makefile.am | 15 +++++++--- tests/.gitignore | 1 + tests/libcdecl-static-symbols.sh | 48 ++++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 tests/.gitignore create mode 100755 tests/libcdecl-static-symbols.sh diff --git a/.gitignore b/.gitignore index dbb2be5..e3e7561 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,4 @@ Makefile.in /ABOUT-NLS /exported.sh /snippet +/test-suite.log diff --git a/Makefile.am b/Makefile.am index f12bc0a..e11d380 100644 --- a/Makefile.am +++ b/Makefile.am @@ -4,6 +4,7 @@ # This is free software: you are free to do what the fuck you want to. # There is NO WARRANTY, to the extent permitted by law. +AUTOMAKE_OPTIONS = parallel-tests color-tests ACLOCAL_AMFLAGS = -I m4 # For Gnulib @@ -49,6 +50,9 @@ libcdecl_la_LIBADD = libgnu.la $(LTLIBINTL) $(LTLIBTHREAD) $(libcdecl_la_OBJECTS): $(gnulib_headers) bin_PROGRAMS = cdecl99 +cdecl99_SOURCES = src/cdecl99.c +cdecl99_LDADD = libcdecl.la libgnu.la $(LTLIBINTL) $(LTLIBREADLINE) +$(cdecl99_OBJECTS): $(gnulib_headers) check_PROGRAMS = check_LTLIBRARIES = libtest.la @@ -61,13 +65,16 @@ libtest_la_SOURCES += test/declgen.c check_PROGRAMS += test/randomdecl endif -cdecl99_SOURCES = src/cdecl99.c -cdecl99_LDADD = libcdecl.la libgnu.la $(LTLIBINTL) $(LTLIBREADLINE) -$(cdecl99_OBJECTS): $(gnulib_headers) - test_randomdecl_LDADD = libcdecl.la libtest.la libgnu.la $(test_randomdecl_OBJECTS): $(gnulib_headers) +TESTS_ENVIRONMENT = SHELL='$(SHELL)' LIBTOOL='$(LIBTOOL)' +TEST_EXTENSIONS = .sh +SH_LOG_COMPILER = $(SHELL) + +TESTS = tests/libcdecl-static-symbols.sh +EXTRA_DIST += $(TESTS) + src/parse.lo: src/scan.h src/scan.lo: src/parse.h src/parse-decl.lo: src/scan.h src/parse.h diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 0000000..397b4a7 --- /dev/null +++ b/tests/.gitignore @@ -0,0 +1 @@ +*.log diff --git a/tests/libcdecl-static-symbols.sh b/tests/libcdecl-static-symbols.sh new file mode 100755 index 0000000..66fca23 --- /dev/null +++ b/tests/libcdecl-static-symbols.sh @@ -0,0 +1,48 @@ +#!/bin/sh +# +# Copyright © 2012 Nick Bowler +# +# Verify that a static library does not export any unprefixed symbols. +# +# License WTFPL2: Do What The Fuck You Want To Public License, version 2. +# This is free software: you are free to do what the fuck you want to. +# There is NO WARRANTY, to the extent permitted by law. + +ltlib=libcdecl.la +sym_prefix=cdecl_ + +eval `$LIBTOOL --config | sed -n \ + -e '/^objdir=/p' \ + -e '/^build_old_libs=/p'` || exit 1 +eval `< $ltlib sed -ne '/^old_library=/p'` || exit 1 + +if test x"$build_old_libs" = x"no"; then + # Not building static libs. + exit 77 +fi + +lib=`expr "$ltlib" : '\(.*\)/'` +lib="$lib${lib:+/}$objdir/$old_library" + +found_sym=no +bad_sym=no + +for i in `$SHELL exported.sh "$lib"` +do + if expr "$i" : "$sym_prefix" >/dev/null; then + # Record that we found at least one exported symbol. + found_sym=yes + else + printf 'unprefixed global symbol: %s\n' "$i" 1>&2 + bad_sym=yes + fi +done + +test x"$bad_sym" = x"yes" && exit 1 + +if test x"$found_sym" = x"no"; then + printf 'no exported symbols found\n' 1>&2 + exit 1 +fi + +exit 0 -- 2.43.2