Debian Codegraph @

support/getc-tap-harness

raw
1 #!/bin/sh
2
3 ## Synchronize INN files maintained in c-tap-harness with upstream.
4 ##
5 ## Initial version written in September 2014 by Julien ÉLIE.
6 ##
7 ## Various bug fixes, code and documentation improvements since then
8 ## in 2014-2016, 2018, 2021, 2022, 2024-2026.
9 ##
10 ## This script downloads the latest version of the files maintained
11 ## in the C TAP Harness package that INN uses for its test driver suite.
12 ## These files are available at
13 ## <https://www.eyrie.org/~eagle/software/c-tap-harness/>.
14 ##
15 ## Running this script permits keeping up-to-date the INN test driver suite
16 ## by automatically fetching the latest version of the upstream files, and
17 ## putting them in the expected location in the INN source code.
18 ## The name of the files that have been modified since the last run of the
19 ## script are written to standard output. Have a look at the changes and,
20 ## if all looks right, commit the changes.
21
22 ## URL where the files can be downloaded.
23 URL_START="https://raw.githubusercontent.com/rra/c-tap-harness/refs/heads/main/"
24
25 ## This function downloads the files and copies them to the expected
26 ## location in the INN source code, after having performed a few minimal
27 ## changes to integrate them in the INN build system.
28 ## If a file is not found in upstream or has been modified since the last
29 ## run of the script, write it on standard output.
30 ##
31 ## This function expects the following arguments:
32 ## $1 - full path of the file to download in the upstream package
33 ## $2 - directory where the file should be copied in INN source code
34 ## $3 - name of the file in INN source code
35 download() {
36 TEMP=$3.tmp
37
38 rm -f ${TEMP}
39 wget -q "${URL_START}$1" -O ${TEMP}
40
41 if [ ! -s "${TEMP}" ]; then
42 echo "File $1 does not exist in upstream package"
43 else
44 if [ "$2" = "tests" ] || [ "$2" = "tests/docs" ] || [ "$2" = "tests/tap" ]; then
45 # Update the path of included C header files.
46 # Changes in shell, Perl and C files are not the same.
47 # Also, do not modify the README file.
48 if [ "$3" != "README" ]; then
49 sed -i -e 's/^#include <tests\/tap\//#include <tap\//g' \
50 ${TEMP}
51 fi
52 fi
53
54 # Specific additions to a few files.
55 if [ "$3" = "basic.c" ]; then
56 sed -i -e '57 i \
57 /* Specific to the integration of C TAP Harness in INN. */\
58 #ifndef LIBTEST_NEW_FORMAT\
59 # include "inn/libinn.h"\
60 \
61 void\
62 test_init(int count)\
63 {\
64 plan(count);\
65 }\
66 \
67 void\
68 ok(int n UNUSED, int success)\
69 {\
70 new_ok(success, NULL);\
71 }\
72 \
73 void\
74 skip(int n UNUSED, const char *reason)\
75 {\
76 # if __GNUC__ > 4 || defined(__llvm__) || defined(__clang__)\
77 # pragma GCC diagnostic ignored "-Wformat-nonliteral"\
78 # endif\
79 new_skip(reason, NULL);\
80 # if __GNUC__ > 4 || defined(__llvm__) || defined(__clang__)\
81 # pragma GCC diagnostic warning "-Wformat-nonliteral"\
82 # endif\
83 }\
84 \
85 void\
86 ok_block(int n UNUSED, int count, int success)\
87 {\
88 new_ok_block(count, success, NULL);\
89 }\
90 \
91 void\
92 skip_block(int n UNUSED, int count, const char *reason)\
93 {\
94 # if __GNUC__ > 4 || defined(__llvm__) || defined(__clang__)\
95 # pragma GCC diagnostic ignored "-Wformat-nonliteral"\
96 # endif\
97 new_skip_block(count, reason, NULL);\
98 # if __GNUC__ > 4 || defined(__llvm__) || defined(__clang__)\
99 # pragma GCC diagnostic warning "-Wformat-nonliteral"\
100 # endif\
101 }\
102 \
103 void\
104 ok_int(int n UNUSED, int wanted, int seen)\
105 {\
106 is_int(wanted, seen, NULL);\
107 }\
108 \
109 void\
110 ok_string(int n UNUSED, const char *wanted, const char *seen)\
111 {\
112 is_string(wanted, seen, NULL);\
113 }\
114 #endif\
115 ' \
116 -e '153 i \
117 #ifndef INN_LIBINN_H' \
118 -e '187 i \
119 #endif' \
120 -e 's/^ok.int /new_ok(int /g' \
121 -e 's/^skip.const /new_skip(const /g' \
122 -e 's/^ok_block.unsigned /new_ok_block(unsigned /g' \
123 -e 's/^skip_block.unsigned /new_skip_block(unsigned /g' \
124 ${TEMP}
125 fi
126
127 if [ "$3" = "basic.h" ]; then
128 sed -i -e '77 i \
129 #ifndef LIBTEST_NEW_FORMAT\
130 /* Specific to the integration of C TAP Harness in INN. */\
131 void ok(int n, int success);\
132 int new_ok(int success, const char *format, ...)\
133 __attribute__((__format__(printf, 2, 3)));\
134 void ok_int(int n, int wanted, int seen);\
135 void ok_string(int n, const char *wanted, const char *seen);\
136 int okv(int success, const char *format, va_list args)\
137 __attribute__((__format__(printf, 2, 0)));\
138 void skip(int n, const char *reason);\
139 void new_skip(const char *reason, ...)\
140 __attribute__((__format__(printf, 1, 2)));\
141 void ok_block(int n, int count, int success);\
142 int new_ok_block(unsigned long count, int success, const char *format, ...)\
143 __attribute__((__format__(printf, 3, 4)));\
144 void skip_block(int n, int count, const char *reason);\
145 void new_skip_block(unsigned long count, const char *reason, ...)\
146 __attribute__((__format__(printf, 2, 3)));\
147 \
148 void test_init(int count);\
149 #else\
150 # define ok new_ok\
151 # define skip new_skip\
152 # define ok_block new_ok_block\
153 # define skip_block new_skip_block' \
154 -e '92 i \
155 #endif' \
156 ${TEMP}
157 fi
158
159 if [ "$3" = "float.c" ]; then
160 sed -i -e '50 i \
161 #ifndef LIBTEST_NEW_FORMAT\
162 /* Specific to the integration of C TAP Harness in INN. */\
163 void\
164 ok_double(int n UNUSED, double wanted, double seen)\
165 {\
166 is_double(wanted, seen, 0.01, NULL);\
167 }\
168 #endif\
169 ' \
170 ${TEMP}
171 fi
172
173 if [ "$3" = "float.h" ]; then
174 sed -i -e '38 i \
175 #ifndef LIBTEST_NEW_FORMAT\
176 /* Specific to the integration of C TAP Harness in INN. */\
177 void ok_double(int n, double wanted, double seen);\
178 #endif' \
179 ${TEMP}
180 fi
181
182 mv -f ${TEMP} ../$2/$3
183
184 case "$3" in
185 *.c | *.h)
186 # Remove values in header guards (for clang-format recognition).
187 sed -i -e 's/^\(#define .*_H\) 1/\1/' ../$2/$3
188 clang-format --style=file -i ../$2/$3
189 ;;
190 *.sh)
191 shfmt -i 4 -w -bn -ln=posix ../$2/$3
192 ;;
193 esac
194
195 git status --short ../$2/$3
196 fi
197 }
198
199 ## Synchronize the test driver suite from upstream.
200 download tests/runtests.c tests runtests.c
201 download tests/tap/basic.c tests/tap basic.c
202 download tests/tap/basic.h tests/tap basic.h
203 download tests/tap/float.c tests/tap float.c
204 download tests/tap/float.h tests/tap float.h
205 download tests/tap/libtap.sh tests/tap libtap.sh
206 download tests/tap/macros.h tests/tap macros.h
207
208 ## Synchronize the README file from upstream.
209 download docs/writing-tests tests README