summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Pipping <sebastian@pipping.org>2024-02-26 21:41:30 +0100
committerGitHub <noreply@github.com>2024-02-26 21:41:30 +0100
commit9dcb74f552d5f1604c8574665b2b37c8bc52ad2a (patch)
treee37bb31cc8106f74a7d57fa6a021d87db390d653
parent5b940f4a650bd1d1d04dd1280d6e920547f0c580 (diff)
parent7e2a0da9ba6581c073484ff400a98fd4037b5c73 (diff)
downloadexpat-9dcb74f552d5f1604c8574665b2b37c8bc52ad2a.tar.gz
Merge pull request #829 from libexpat/hide-test-only-code-behind-new-macro
Hide test-only code behind new (internal) macro `XML_TESTING` (alternative to #826)
-rw-r--r--expat/CMakeLists.txt2
-rwxr-xr-xexpat/apply-clang-tidy.sh1
-rw-r--r--expat/lib/Makefile.am17
-rw-r--r--expat/lib/internal.h10
-rw-r--r--expat/lib/xmlparse.c12
-rw-r--r--expat/tests/Makefile.am6
6 files changed, 33 insertions, 15 deletions
diff --git a/expat/CMakeLists.txt b/expat/CMakeLists.txt
index dd793188..6649d769 100644
--- a/expat/CMakeLists.txt
+++ b/expat/CMakeLists.txt
@@ -676,6 +676,8 @@ if(EXPAT_BUILD_TESTS)
)
foreach(_target ${_EXPAT_TEST_TARGETS})
+ target_compile_definitions(${_target} PRIVATE -DXML_TESTING)
+
set_property(TARGET ${_target} PROPERTY RUNTIME_OUTPUT_DIRECTORY tests)
expat_add_test(${_target} $<TARGET_FILE:${_target}>)
diff --git a/expat/apply-clang-tidy.sh b/expat/apply-clang-tidy.sh
index 2e520bd0..17015f6c 100755
--- a/expat/apply-clang-tidy.sh
+++ b/expat/apply-clang-tidy.sh
@@ -68,6 +68,7 @@ flags=(
-DXML_DTD
-DXML_GE
-DXML_NS
+ -DXML_TESTING
)
if [[ $# -gt 0 ]]; then
diff --git a/expat/lib/Makefile.am b/expat/lib/Makefile.am
index 0e0185b5..f32430ab 100644
--- a/expat/lib/Makefile.am
+++ b/expat/lib/Makefile.am
@@ -36,7 +36,9 @@ include_HEADERS = \
expat_external.h
lib_LTLIBRARIES = libexpat.la
-noinst_LTLIBRARIES = libexpatinternal.la
+if WITH_TESTS
+noinst_LTLIBRARIES = libtestpat.la
+endif
libexpat_la_LDFLAGS = \
@AM_LDFLAGS@ \
@@ -44,17 +46,16 @@ libexpat_la_LDFLAGS = \
-no-undefined \
-version-info @LIBCURRENT@:@LIBREVISION@:@LIBAGE@
-libexpat_la_SOURCES =
-
-# This layer of indirection allows
-# the test suite to access internal symbols
-# despite compiling with -fvisibility=hidden
-libexpatinternal_la_SOURCES = \
+libexpat_la_SOURCES = \
xmlparse.c \
xmltok.c \
xmlrole.c
-libexpat_la_LIBADD = libexpatinternal.la
+if WITH_TESTS
+libtestpat_la_CPPFLAGS = -DXML_TESTING
+
+libtestpat_la_SOURCES = $(libexpat_la_SOURCES)
+endif
doc_DATA = \
../AUTHORS \
diff --git a/expat/lib/internal.h b/expat/lib/internal.h
index cdbd3609..81db8955 100644
--- a/expat/lib/internal.h
+++ b/expat/lib/internal.h
@@ -161,8 +161,14 @@ unsigned long long testingAccountingGetCountBytesIndirect(XML_Parser parser);
const char *unsignedCharToPrintable(unsigned char c);
#endif
-extern XML_Bool g_reparseDeferralEnabledDefault; // written ONLY in runtests.c
-extern unsigned int g_bytesScanned; // used for testing only
+extern
+#if ! defined(XML_TESTING)
+ const
+#endif
+ XML_Bool g_reparseDeferralEnabledDefault; // written ONLY in runtests.c
+#if defined(XML_TESTING)
+extern unsigned int g_bytesScanned; // used for testing only
+#endif
#ifdef __cplusplus
}
diff --git a/expat/lib/xmlparse.c b/expat/lib/xmlparse.c
index 63fcaa92..0451e693 100644
--- a/expat/lib/xmlparse.c
+++ b/expat/lib/xmlparse.c
@@ -629,8 +629,14 @@ static unsigned long getDebugLevel(const char *variableName,
? 0 \
: ((*((pool)->ptr)++ = c), 1))
-XML_Bool g_reparseDeferralEnabledDefault = XML_TRUE; // write ONLY in runtests.c
-unsigned int g_bytesScanned = 0; // used for testing only
+#if ! defined(XML_TESTING)
+const
+#endif
+ XML_Bool g_reparseDeferralEnabledDefault
+ = XML_TRUE; // write ONLY in runtests.c
+#if defined(XML_TESTING)
+unsigned int g_bytesScanned = 0; // used for testing only
+#endif
struct XML_ParserStruct {
/* The first member must be m_userData so that the XML_GetUserData
@@ -1017,7 +1023,9 @@ callProcessor(XML_Parser parser, const char *start, const char *end,
return XML_ERROR_NONE;
}
}
+#if defined(XML_TESTING)
g_bytesScanned += (unsigned)have_now;
+#endif
const enum XML_Error ret = parser->m_processor(parser, start, end, endPtr);
if (ret == XML_ERROR_NONE) {
// if we consumed nothing, remember what we had on this parse attempt.
diff --git a/expat/tests/Makefile.am b/expat/tests/Makefile.am
index f949fe7f..e1ab9f8c 100644
--- a/expat/tests/Makefile.am
+++ b/expat/tests/Makefile.am
@@ -32,7 +32,7 @@
SUBDIRS = . benchmark
-AM_CPPFLAGS = @AM_CPPFLAGS@ -I$(srcdir)/../lib
+AM_CPPFLAGS = @AM_CPPFLAGS@ -I$(srcdir)/../lib -DXML_TESTING
check_PROGRAMS = runtests runtests_cxx
TESTS = runtests runtests_cxx
@@ -72,8 +72,8 @@ runtests_cxx_SOURCES = \
runtests_cxx.cpp \
structdata_cxx.cpp
-runtests_LDADD = ../lib/libexpatinternal.la
-runtests_cxx_LDADD = ../lib/libexpatinternal.la
+runtests_LDADD = ../lib/libtestpat.la
+runtests_cxx_LDADD = ../lib/libtestpat.la
runtests_LDFLAGS = @AM_LDFLAGS@ @LIBM@
runtests_cxx_LDFLAGS = @AM_LDFLAGS@ @LIBM@