diff options
| author | Berke Güzel <wenekar1@gmail.com> | 2026-10-15 12:38:58 +0300 |
|---|---|---|
| committer | Berke Güzel <wenekar1@gmail.com> | 2026-10-15 12:38:58 +0300 |
| commit | 22345caf457e8d9a4bdb56b696cc5f3694812276 (patch) | |
| tree | 801bd4f17569fa875e81bc2297a46ecf5176cbc7 /tests/header_test.sh | |
| parent | 6ee9eb37d8e616a972fb29b3fbdbc33991aa844f (diff) | |
| parent | 212f1cc9109aa0deb9e5d990bb2dba2b167618fb (diff) | |
Merge branch 'wt/namespace' into api-hardening
Diffstat (limited to 'tests/header_test.sh')
| -rw-r--r-- | tests/header_test.sh | 75 |
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 |
