summaryrefslogtreecommitdiff
path: root/tests/header_test.sh
diff options
context:
space:
mode:
authorBerke Güzel <wenekar1@gmail.com>2026-10-15 12:31:21 +0300
committerBerke Güzel <wenekar1@gmail.com>2026-10-15 12:31:21 +0300
commit212f1cc9109aa0deb9e5d990bb2dba2b167618fb (patch)
tree0044818d9e12d602b4da3b6823d9997557e5cfae /tests/header_test.sh
parent5f03033b0e211f9ed13e7a1351f9a8f9011ab665 (diff)
Keep installed headers from shadowing or polluting host names
The pkg-config file put include/term on the host's include path, so ncurses' term.h could be picked up in place of ours. Hosts now write <term/term.h> and the package adds only its include directory. The installed Unicode API had unprefixed names that collide with host symbols and macros. Rename them: term_ for functions, types, and static tables, TERM_ for macros and include guards. unicode_data.inc and tools/generate_unicode.py are renamed to match. The generator's inputs here are Unicode 15.1 and the checked-in table is 18.0.0, so the table data was not regenerated. Only the declarations were checked against the generator. utf8.h casts the malloc result so it compiles as C++. header_test.sh now includes <term/term.h> with only include/ on the path. It also checks that a host which defines unicode_width, UTF8_ACCEPT, GRAPHEME_MAX_LEN, in_ranges, and similar names compiles with the Unicode headers as C11 and C++, in both declaration orders. Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tests/header_test.sh')
-rw-r--r--tests/header_test.sh75
1 files changed, 60 insertions, 15 deletions
diff --git a/tests/header_test.sh b/tests/header_test.sh
index 4ba091b..9fd1041 100644
--- a/tests/header_test.sh
+++ b/tests/header_test.sh
@@ -1,25 +1,70 @@
#!/usr/bin/env bash
-# A host includes term.h and nothing else. The header compiles alone as
-# strict C11 and as C++, with only include/term on the include path.
+# A host includes <term/term.h> and nothing else. The package puts only the
+# parent of term/ on the include path. The headers compile alone as strict
+# C11 and as C++.
set -euo pipefail
cd "${1:-$(dirname "$0")/..}"
cc=${CC:-cc}
cxx=${CXX:-c++}
status=0
-echo '#include "term.h"' | "$cc" -std=c11 -Wall -Wextra -Wpedantic -Werror \
- -Iinclude/term -x c -fsyntax-only - || { echo "term.h: not valid C11" >&2; status=1; }
-if command -v "$cxx" >/dev/null; then
- echo '#include "term.h"' | "$cxx" -std=c++17 -Wall -Wextra -Wpedantic -Werror \
- -Iinclude/term -x c++ -fsyntax-only - || { echo "term.h: not valid C++" >&2; status=1; }
-fi
+
+# check LABEL: compile the code on stdin as C11 and as C++, with include/
+# on the path.
+check() {
+ local label=$1 src
+ src=$(cat)
+ printf '%s\n' "$src" | "$cc" -std=c11 -Wall -Wextra -Wpedantic -Werror \
+ -Iinclude -x c -fsyntax-only - || { echo "$label: not valid C11" >&2; status=1; }
+ if command -v "$cxx" >/dev/null; then
+ printf '%s\n' "$src" | "$cxx" -std=c++17 -Wall -Wextra -Wpedantic -Werror \
+ -Iinclude -x c++ -fsyntax-only - || { echo "$label: not valid C++" >&2; status=1; }
+ fi
+}
+
+check term.h <<'EOF'
+#include <term/term.h>
+EOF
# Apple headers define wide before a host includes the Unicode API.
-unicode_header=$'typedef struct wide { int value; } wide;\n#include "unicode/width.h"'
-echo "$unicode_header" | "$cc" -std=c11 -Wall -Wextra -Wpedantic -Werror \
- -Iinclude/term -x c -fsyntax-only - || { echo "unicode/width.h: conflicts with host types" >&2; status=1; }
-if command -v "$cxx" >/dev/null; then
- echo "$unicode_header" | "$cxx" -std=c++17 -Wall -Wextra -Wpedantic -Werror \
- -Iinclude/term -x c++ -fsyntax-only - || { echo "unicode/width.h: conflicts with C++ host types" >&2; status=1; }
-fi
+check "unicode/width.h: conflicts with host types" <<'EOF'
+typedef struct wide { int value; } wide;
+#include <term/unicode/width.h>
+EOF
+
+# A host that uses the names the Unicode API had before the term_ and
+# TERM_ prefixes. The API must not clash with them in either order.
+check "unicode API: host names declared first" <<'EOF'
+int unicode_width(int);
+static int in_ranges;
+static int zero_width;
+static int utf8d;
+struct unicode_range { int lo; };
+#define UTF8_ACCEPT 7
+#define GRAPHEME_MAX_LEN 3
+#define IN_TABLE 1
+#define UNICODE_DATA_VERSION "host"
+#define UTF_8_H
+#include <term/unicode/utf8.h>
+#include <term/unicode/width.h>
+#include <term/unicode/grapheme.h>
+int host_use(void)
+{
+ return in_ranges + zero_width + utf8d + unicode_width(1) + UTF8_ACCEPT + GRAPHEME_MAX_LEN;
+}
+EOF
+
+check "unicode API: host names declared after" <<'EOF'
+#include <term/unicode/utf8.h>
+#include <term/unicode/width.h>
+#include <term/unicode/grapheme.h>
+int unicode_width(int);
+static int in_ranges;
+#define UTF8_ACCEPT 7
+#define GRAPHEME_MAX_LEN 3
+int host_use(void)
+{
+ return in_ranges + unicode_width(1) + UTF8_ACCEPT + GRAPHEME_MAX_LEN;
+}
+EOF
exit $status