Skip to content

Commit 67bc6c8

Browse files
committed
tests: import a test for pkg-config files
1 parent ccb2d95 commit 67bc6c8

File tree

3 files changed

+185
-3
lines changed

3 files changed

+185
-3
lines changed

project.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ title=Release
1616
#targets
1717
[tests]
1818
type=command
19-
command=cd tests && (if [ -n "$(OBJDIR)" ]; then $(MAKE) OBJDIR="$(OBJDIR)tests/" "$(OBJDIR)tests/clint.log" "$(OBJDIR)tests/fixme.log" "$(OBJDIR)tests/pkgconfig.log" "$(OBJDIR)tests/pylint.log" "$(OBJDIR)tests/tests.log"; else $(MAKE) clint.log fixme.log pkgconfig.log pylint.log tests.log; fi)
19+
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/pylint.log" "$(OBJDIR)tests/tests.log"; else $(MAKE) clint.log fixme.log pclint.log pkgconfig.log pylint.log tests.log; fi)
2020
depends=all
2121
enabled=0
2222
phony=1

tests/pclint.sh

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
#!/bin/sh
2+
#$Id$
3+
#Copyright (c) 2014-2025 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%/pclint.sh}/../config.sh"
29+
PROGNAME="pclint.sh"
30+
PROJECTCONF="../project.conf"
31+
#executables
32+
DATE="date"
33+
DEBUG="_debug"
34+
ECHO="/bin/echo"
35+
FIND="find"
36+
MKDIR="mkdir -p"
37+
PCLINT="pkgconf --validate"
38+
SORT="sort -n"
39+
TR="tr"
40+
41+
[ -f "$CONFIGSH" ] && . "$CONFIGSH"
42+
43+
44+
#functions
45+
#pclint
46+
_pclint()
47+
{
48+
res=0
49+
subdirs=
50+
51+
$DATE
52+
while read line; do
53+
case "$line" in
54+
"["*)
55+
break
56+
;;
57+
"subdirs="*)
58+
subdirs=${line#subdirs=}
59+
subdirs=$(echo "$subdirs" | $TR ',' ' ')
60+
;;
61+
esac
62+
done < "$PROJECTCONF"
63+
if [ ! -n "$subdirs" ]; then
64+
_error "Could not locate directories to analyze"
65+
return $?
66+
fi
67+
for subdir in $subdirs; do
68+
[ -d "../$subdir" ] || continue
69+
while read filename; do
70+
[ -n "$filename" ] || continue
71+
echo
72+
$ECHO -n "$filename:"
73+
_pclint_file "$filename"
74+
if [ $? -eq 0 ]; then
75+
echo " OK"
76+
echo "$PROGNAME: $filename: OK" 1>&2
77+
else
78+
echo "FAIL"
79+
echo "$PROGNAME: $filename: FAIL" 1>&2
80+
res=2
81+
fi
82+
done << EOF
83+
$($FIND "../$subdir" -type f -a -iname '*.pc' | $SORT)
84+
EOF
85+
done
86+
return $res
87+
}
88+
89+
_pclint_file()
90+
{
91+
$DEBUG $PCLINT "$filename" 2>&1 || return 2
92+
#try to detect invalid use of return
93+
#XXX this test is not accurate (therefore a warning)
94+
warn=0
95+
while read line; do
96+
case "$line" in
97+
*return*)
98+
warn=1
99+
;;
100+
*)
101+
warn=0
102+
;;
103+
esac
104+
done < "$filename"
105+
if [ $warn -ne 0 ]; then
106+
_error "$filename: return instead of exit in the global scope"
107+
fi
108+
return 0
109+
}
110+
111+
112+
#debug
113+
_debug()
114+
{
115+
echo "$@" 1>&3
116+
"$@"
117+
}
118+
119+
120+
#error
121+
_error()
122+
{
123+
echo "$PROGNAME: $@" 1>&2
124+
return 2
125+
}
126+
127+
128+
#usage
129+
_usage()
130+
{
131+
echo "Usage: $PROGNAME [-c] target..." 1>&2
132+
return 1
133+
}
134+
135+
136+
#main
137+
clean=0
138+
while getopts "cO:P:" name; do
139+
case "$name" in
140+
c)
141+
clean=1
142+
;;
143+
O)
144+
export "${OPTARG%%=*}"="${OPTARG#*=}"
145+
;;
146+
P)
147+
#XXX ignored for compatibility
148+
;;
149+
?)
150+
_usage
151+
exit $?
152+
;;
153+
esac
154+
done
155+
shift $((OPTIND - 1))
156+
if [ $# -lt 1 ]; then
157+
_usage
158+
exit $?
159+
fi
160+
161+
#clean
162+
[ $clean -ne 0 ] && exit 0
163+
164+
exec 3>&1
165+
ret=0
166+
while [ $# -gt 0 ]; do
167+
target="$1"
168+
dirname="${target%/*}"
169+
shift
170+
171+
if [ -n "$dirname" -a "$dirname" != "$target" ]; then
172+
$MKDIR -- "$dirname" || ret=$?
173+
fi
174+
_pclint > "$target" || ret=$?
175+
done
176+
exit $ret

tests/project.conf

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
targets=array,buffer,clint.log,config,coverage.log,error,event,fixme.log,includes,parser,pkgconfig.log,pylint.log,string,variable,tests.log
1+
targets=array,buffer,clint.log,config,coverage.log,error,event,fixme.log,includes,parser,pclint.log,pkgconfig.log,pylint.log,string,variable,tests.log
22
cppflags_force=-I ../include
33
cflags=-W -Wall -g -O2 -fPIE -D_FORTIFY_SOURCE=2 -fstack-protector
44
ldflags_force=-L$(OBJDIR)../src -L$(OBJDIR)../src/.libs -Wl,-rpath,$(OBJDIR)../src -lSystem `../tools/platform.sh -O DESTDIR="$(DESTDIR)" -l dl` `../tools/platform.sh -O DESTDIR="$(DESTDIR)" -l m`
55
ldflags=-pie -Wl,-z,relro -Wl,-z,now
6-
dist=Makefile,clint.sh,config.conf,config-empty.conf,config-noeol.conf,coverage.sh,fixme.sh,pkgconfig.sh,pylint.sh,python.sh,tests.sh
6+
dist=Makefile,clint.sh,config.conf,config-empty.conf,config-noeol.conf,coverage.sh,fixme.sh,pclint.sh,pkgconfig.sh,pylint.sh,python.sh,tests.sh
77

88
#modes
99
[mode::debug]
@@ -56,6 +56,12 @@ sources=includes.c
5656
type=binary
5757
sources=parser.c
5858

59+
[pclint.log]
60+
type=script
61+
script=./pclint.sh
62+
enabled=0
63+
depends=$(OBJDIR)../data/libSystem.pc,pclint.sh
64+
5965
[pkgconfig.log]
6066
type=script
6167
script=./pkgconfig.sh

0 commit comments

Comments
 (0)