summaryrefslogtreecommitdiff
path: root/tests/header_test.sh
blob: 299a9502867cb7f98c7ffe8702d882f2814460cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env bash
# A host includes <wsap_vtcore/wsap_vtcore.h> and nothing else. The package puts only the
# parent of wsap_vtcore/ 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

# 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 wsap_vtcore.h <<'EOF'
#include <wsap_vtcore/wsap_vtcore.h>
EOF

# Apple headers define wide before a host includes the Unicode API.
check "unicode/width.h: conflicts with host types" <<'EOF'
typedef struct wide { int value; } wide;
#include <wsap_vtcore/unicode/width.h>
EOF

# A host that uses the names the Unicode API had before the wsap_vtcore_ and
# WSAP_VTCORE_ 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 <wsap_vtcore/unicode/utf8.h>
#include <wsap_vtcore/unicode/width.h>
#include <wsap_vtcore/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 <wsap_vtcore/unicode/utf8.h>
#include <wsap_vtcore/unicode/width.h>
#include <wsap_vtcore/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