Skip to content

Commit 5649159

Browse files
committed
tests: import the "xmllint" test
1 parent 3f3accc commit 5649159

File tree

6 files changed

+189
-6
lines changed

6 files changed

+189
-6
lines changed

project.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ dist=COPYING,README.md,Makefile,config.sh
99
#targets
1010
[tests]
1111
type=command
12-
command=cd tests && (if [ -n "$(OBJDIR)" ]; then $(MAKE) OBJDIR="$(OBJDIR)tests/" "$(OBJDIR)tests/clint.log" "$(OBJDIR)tests/fixme.log" "$(OBJDIR)tests/pclint.log" "$(OBJDIR)tests/pkgconfig.log" "$(OBJDIR)tests/tests.log"; else $(MAKE) clint.log fixme.log pclint.log pkgconfig.log tests.log; fi)
12+
command=cd tests && (if [ -n "$(OBJDIR)" ]; then $(MAKE) OBJDIR="$(OBJDIR)tests/" "$(OBJDIR)tests/clint.log" "$(OBJDIR)tests/fixme.log" "$(OBJDIR)tests/pclint.log" "$(OBJDIR)tests/pkgconfig.log" "$(OBJDIR)tests/tests.log" "$(OBJDIR)tests/xmllint.log"; else $(MAKE) clint.log fixme.log pclint.log pkgconfig.log tests.log xmllint.log; fi)
1313
depends=all
1414
enabled=0
1515
phony=1

tests/project.conf

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
targets=clint.log,fixme.log,pclint.log,pkgconfig.log,tests.log
1+
targets=clint.log,fixme.log,pclint.log,pkgconfig.log,tests.log,xmllint.log
22
cppflags_force=-I ../include
33
cflags_force=`pkg-config --cflags libSystem` -fPIE
44
cflags=-W -Wall -g -O2 -fPIE -D_FORTIFY_SOURCE=2 -fstack-protector
55
ldflags_force=`pkg-config --libs libSystem` -L$(OBJDIR)../src -Wl,-rpath,$(PREFIX)/lib -Wl,-rpath,$(OBJDIR)../src -lParser
66
ldflags=-pie -Wl,-z,relro -Wl,-z,now
7-
dist=Makefile,clint.sh,fixme.sh,pclint.sh,pkgconfig.sh,tests.sh,xml-afl-000000.xml
7+
dist=Makefile,clint.sh,fixme.sh,pclint.sh,pkgconfig.sh,tests.sh,xml-afl-000000.xmltest,xmllint.sh
88

99
#targets
1010
[clint.log]
@@ -34,5 +34,15 @@ enabled=0
3434
[tests.log]
3535
type=script
3636
script=./tests.sh
37-
depends=$(OBJDIR)../tools/xml$(EXEEXT),tests.sh,xml-afl-000000.xml
37+
depends=$(OBJDIR)xml$(EXEEXT),tests.sh,xml-afl-000000.xmltest
38+
enabled=0
39+
40+
[xml]
41+
type=binary
42+
sources=xml.c
43+
44+
[xmllint.log]
45+
type=script
46+
script=./xmllint.sh
47+
depends=xmllint.sh,$(OBJDIR)../src/libParser.a
3848
enabled=0

tests/tests.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ target="$1"
129129
_date > "$target"
130130
FAILED=
131131
echo "Performing tests:" 1>&2
132-
[ -z "$PKG_CONFIG_SYSROOT_DIR" ] && _test "../tools/xml$EXEEXT" \
133-
"xml-afl-000000.xml"
132+
[ -z "$PKG_CONFIG_SYSROOT_DIR" ] && _test "./xml$EXEEXT" \
133+
"xml-afl-000000.xmltest"
134134
echo "Expected failures:" 1>&2
135135
if [ -n "$FAILED" ]; then
136136
echo "Failed tests:$FAILED" 1>&2

tests/xml.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* $Id$ */
2+
/* Copyright (c) 2022 Pierre Pronchery <[email protected]> */
3+
/* This file is part of DeforaOS System libParser */
4+
/* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, version 3 of the License.
7+
*
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* GNU General Public License for more details.
12+
*
13+
* You should have received a copy of the GNU General Public License
14+
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
15+
16+
17+
18+
#include "../tools/xml.c"

tests/xmllint.sh

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
#!/bin/sh
2+
#$Id$
3+
#Copyright (c) 2014-2021 Pierre Pronchery <[email protected]>
4+
#
5+
#Redistribution and use in source and binary forms, with or without
6+
#modification, are permitted provided that the following conditions are met:
7+
#
8+
# * Redistributions of source code must retain the above copyright notice, this
9+
# list of conditions and the following disclaimer.
10+
# * Redistributions in binary form must reproduce the above copyright notice,
11+
# this list of conditions and the following disclaimer in the documentation
12+
# and/or other materials provided with the distribution.
13+
#
14+
#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15+
#AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16+
#IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17+
#DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
18+
#FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19+
#DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20+
#SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21+
#CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22+
#OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23+
#OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24+
25+
26+
27+
#variables
28+
CONFIGSH="${0%/xmllint.sh}/../config.sh"
29+
DEVNULL="/dev/null"
30+
PROGNAME="xmllint.sh"
31+
PROJECTCONF="../project.conf"
32+
#executables
33+
DATE="date"
34+
DEBUG="_debug"
35+
ECHO="/bin/echo"
36+
FIND="find"
37+
MKDIR="mkdir -p"
38+
SORT="sort -n"
39+
TR="tr"
40+
XMLLINT="xmllint --nonet --xinclude"
41+
42+
[ -f "$CONFIGSH" ] && . "$CONFIGSH"
43+
44+
45+
#functions
46+
#xmllint
47+
_xmllint()
48+
{
49+
res=0
50+
subdirs=
51+
52+
$DATE
53+
while read line; do
54+
case "$line" in
55+
"["*)
56+
break
57+
;;
58+
"subdirs="*)
59+
subdirs=${line#subdirs=}
60+
subdirs=$(echo "$subdirs" | $TR ',' ' ')
61+
;;
62+
esac
63+
done < "$PROJECTCONF"
64+
if [ ! -n "$subdirs" ]; then
65+
_error "Could not locate directories to analyze"
66+
return $?
67+
fi
68+
for subdir in $subdirs; do
69+
[ -d "../$subdir" ] || continue
70+
while read filename; do
71+
[ -n "$filename" ] || continue
72+
echo
73+
$ECHO -n "$filename:"
74+
$DEBUG $XMLLINT "$filename" 2>&1 > "$DEVNULL"
75+
if [ $? -eq 0 ]; then
76+
echo " OK"
77+
echo "$PROGNAME: $filename: OK" 1>&2
78+
else
79+
echo "FAIL"
80+
echo "$PROGNAME: $filename: FAIL" 1>&2
81+
res=2
82+
fi
83+
done << EOF
84+
$($FIND "../$subdir" -type f -a \( -iname '*.xml' -o -iname '*.xsl' \) | $SORT)
85+
EOF
86+
done
87+
return $res
88+
}
89+
90+
91+
#debug
92+
_debug()
93+
{
94+
echo "$@" 1>&3
95+
"$@"
96+
}
97+
98+
99+
#error
100+
_error()
101+
{
102+
echo "$PROGNAME: $@" 1>&2
103+
return 2
104+
}
105+
106+
107+
#usage
108+
_usage()
109+
{
110+
echo "Usage: $PROGNAME [-c] target..." 1>&2
111+
return 1
112+
}
113+
114+
115+
#main
116+
clean=0
117+
while getopts "cO:P:" name; do
118+
case "$name" in
119+
c)
120+
clean=1
121+
;;
122+
O)
123+
export "${OPTARG%%=*}"="${OPTARG#*=}"
124+
;;
125+
P)
126+
#XXX ignored for compatibility
127+
;;
128+
?)
129+
_usage
130+
exit $?
131+
;;
132+
esac
133+
done
134+
shift $((OPTIND - 1))
135+
if [ $# -lt 1 ]; then
136+
_usage
137+
exit $?
138+
fi
139+
140+
#clean
141+
[ $clean -ne 0 ] && exit 0
142+
143+
exec 3>&1
144+
ret=0
145+
while [ $# -gt 0 ]; do
146+
target="$1"
147+
dirname="${target%/*}"
148+
shift
149+
150+
if [ -n "$dirname" -a "$dirname" != "$target" ]; then
151+
$MKDIR -- "$dirname" || ret=$?
152+
fi
153+
_xmllint > "$target" || ret=$?
154+
done
155+
exit $ret

0 commit comments

Comments
 (0)