pck-update, test00_specsyntax: move code from pck-update (action 4) to a new test file test00_specsyntax

Signed-off-by: Davide Madrisan <davide.madrisan@gmail.com>
This commit is contained in:
Davide Madrisan 2012-05-19 23:10:12 +02:00
parent 8bb763e34b
commit 7a68b819d4
4 changed files with 33 additions and 334 deletions

View File

@ -84,6 +84,11 @@ Changes in version 1.12.0
* BUGS - Davide Madrisan:
The option '--ignore-test' works again. Remove the corresponding line.
+ update
* New test file 'test00_specsyntax'.
Move code to check specfiles from 'pck-update' (action 4) to the test file
'test00_specsyntax'.
-------------------------------------------------------------------------------
Changes in version 1.10.0

View File

@ -119,19 +119,25 @@ function test.num2str() {
function test.runall() {
local ARGS
ARGS=`LC_ALL=C getopt \
-o d: --long testdir: \
-o s:p --long specfile:,packages \
-n "$FUNCNAME" -- "$@"`
[ $? = 0 ] || notify.error $"(bug)"" -- $FUNCNAME: "$"\`getopt' error"
local testdir
local specfile
local test_specfile=0
local test_packages=0
eval set -- "$ARGS"
while :; do
case "$1" in
-d|--testdir)
testdir="$2"
-s|--specfile)
test_specfile=1
specfile="$2"
shift
;;
-p|--packages)
test_packages=1
;;
--) shift; break ;;
*) notify.error $"\
(bug)"" -- $FUNCNAME: "$"\`getopt' error: bad command \`$1'" ;;
@ -147,7 +153,15 @@ function test.runall() {
local test_number=1
local fname
for fname in $testdir/*; do
[ $test_specfile -gt 0 ] &&
for fname in $testdir/test*_spec*; do
notify.debug "$FUNCNAME: running test: \`$fname'"
. $fname
specfile.checksyntax "$specfile"
done
[ $test_packages -gt 0 ] &&
for fname in $testdir/test*_pkg*; do
notify.debug "$FUNCNAME: running test: \`$fname'"
. $fname
alltests --infofile "$tmpextractdir/rpmpkg.info" \

View File

@ -625,325 +625,6 @@ $"release number: unsupported format"": \"$SPEC_RELEASE\""
fi ) || { echo "$SPEC_RELEASE"; return 1; }
}
# function specfile.checksintax()
# do some syntax checks in the specfile of the building package
# args:
# $1 : specfile name
# $2, ... : execute these check numbers (optional, default = all checks)
function specfile.checksintax() {
local i rpmvar specfile="$1"; shift
[[ "$specfile" ]] || notify.error $"\
(bug)"" -- $FUNCNAME: "$"missing mandatory arg"" (#1)"
notify.debug "$FUNCNAME: specfile = \"$specfile\""
local arg args="${@:-"`seq -s" " 1 9`"}" # default: all checks
notify.debug "$FUNCNAME: args = \"$args\""
local token ignore_test_list_value
ignore_test_list_value=()
OIFS="$IFS"; IFS=','
for token in $ignore_test_list; do
IFS='='; set -- $token
ignore_test_list_value[${#ignore_test_list_value[*]}]="$1";
IFS=','
done
IFS="$OIFS"
notify.debug "$FUNCNAME: \
ignore_test_list_value = (${ignore_test_list_value[*]})"
function skip_test() {
local test n found
test="$1"
let "found = 0"
for n in ${ignore_test_list_value[*]}; do
[ "$n" = "$test" ] && let "found = 1"
done
return $found
}
notify.note $"checking"" \`${NOTE}$specfile${NORM}'..."
for arg in $args; do
notify.debug "$FUNCNAME: arg = \"$arg\""
case "$arg" in
1) # 1. checking if 'Source[0]' is a valid internet address
# (skip this test if no '%setup' section has been found)
skip_test $arg ||
{ notify.note "\
* "$"running test"" $arg (source0)..."" "$"skipped"
continue; }
grep -q "^%setup[ \t]*$\|^%setup[ \t]\+" $specfile
if [ $? -eq 0 ]; then
notify.note " * "$"running test"" $arg (source0)..."
if [[ "$source0_name_structure" ]]; then
specfile.getvars -s $specfile --verbatim SPEC_SOURCE0
if [[ "$SPEC_SOURCE0_VERBATIM" ]]; then
[[ "$(echo "$SPEC_SOURCE0_VERBATIM" | \
grep -e "$source0_name_structure")" ]] || notify.warning "\
\`Source[0]': "$"does not point to a valid internet address"
fi
fi
else
notify.note "\
* "$"running test"" $arg (source0)..."" "$"skipped"
fi
;;
2) # 2. check if the patches have standard names
# (see the 'patch_name_structure' var in the configure file)
skip_test $arg ||
{ notify.note "\
* "$"running test"" $arg (patch)..."" "$"skipped"
continue; }
notify.note " * "$"running test"" $arg (patch)..."
specfile.getvars -s $specfile --verbatim SPEC_PATCH
echo "${SPEC_PATCH_VERBATIM[@]}" | \
for i in `seq 1 1 ${#SPEC_PATCH_VERBATIM[@]}`; do
[[ "${SPEC_PATCH_VERBATIM[$i-1]}" =~ \
$patch_name_structure ]] ||
{ notify.warning "\
patch $i (\`${NOTE}${SPEC_PATCH_VERBATIM[$i-1]}${NORM}') "
notify.warning $"\
not a standard structure (see config file)"; }
done
;;
3) # 3. check if `%setup' have `-D' and/or `-T' options
skip_test $arg ||
{ notify.note "\
* "$"running test"" $arg (%setup)..."" "$"skipped"
continue; }
notify.note " * "$"running test"" $arg (%setup)..."
[[ "$(cat $specfile | \
sed -n "/%setup/{/-D /p;/-T /p;/-D$/p;/-T$/p}")" ]] &&
notify.warning $"\
found \`-D' and/or \`-T' option(s) in the \`%setup' directive"
;;
4) # 4. check if all the `%files' blocks have a `%defattr' line
# note: skip commented out blocks
skip_test $arg ||
{ notify.note "\
* "$"running test"" $arg (%defattr)..."" "$"skipped"
continue; }
notify.note " * "$"running test"" $arg (%defattr)..."
[[ "$(sed -e '
# print paragraph if it contains "%files" and "%defattr"
/./{H;$!d;}' -e 'x;/%files/!d;/%defattr/!d' $specfile | \
grep "^[[:space:]]*%files")" != \
"$(grep "^[[:space:]]*%files" $specfile)" ]] &&
notify.error $"\
missing at least one \`%defattr' directive"
;;
5) # 5. check if the rpm macros %configure, %make are used
# - look in the block : `%build' to `%install'
skip_test $arg ||
{ notify.note "\
* "$"running test"" $arg (%build, %install)..."" "$"skipped"
continue; }
notify.note " * "$"running test"" $arg (%build, %install)..."
local token tokens
sed -n '/%build/,/%install/p' $specfile | \
while read -a tokens; do
# ignore comments
[[ "${tokens[0]}" =~ ^\# ]] && continue
for token in ${tokens[*]}; do
case "$token" in
configure|./configure)
[[ "$rpm_macro_configure" ]] && notify.warning $"\
use rpm macros if possible:"" \`$token' --> \`$rpm_macro_configure'" ;;
make)
[[ "$rpm_macro_make" ]] && notify.warning $"\
use rpm macros if possible:"" \`$token' --> \`$rpm_macro_make'" ;;
esac
done
done
# - look in the block : `%install' to `%changelog'
sed -n '/%install/,/%changelog/p' $specfile | \
while read -a tokens; do
# ignore comments
[[ "${tokens[0]}" =~ ^\# ]] && continue
for token in ${tokens[*]}; do
case "$token" in
make)
[[ "$rpm_macro_make" ]] && notify.warning $"\
use rpm macros if possible:"" $(
[[ "$rpm_macro_makeinstall" ]] &&
echo -en "\n * \`make install' -> \`$rpm_macro_makeinstall'"
[[ "$rpm_macro_makeoldinstall" ]] &&
echo -en "\n * \`make install' -> \`$rpm_macro_makeoldinstall'" )" ;;
esac
done
done
;;
6) # 6. check if '%find_lang' is used when localization files
# are detected
skip_test $arg ||
{ notify.note "\
* "$"running test"" $arg (%find_lang)..."" "$"skipped"
continue; }
notify.note " * "$"running test"" $arg (%find_lang)..."
# FIXME : the test should perhaps be improved...
grep -q "^[ ]*[^# ]*/share/locale/" $specfile || continue
notify.error $"\
"$"localization files must be packaged via \`%find_lang'""${NORM}
---------------------------------------
${NOTE}"$"Hint"":${NORM}
%install
...
%find_lang %{name}
%files -f %{name}.lang
---------------------------------------
"
;;
7) # 7. check if the install/uninstall code is present
skip_test $arg ||
{ notify.note "\
* "$"running test"" $arg ("$"info pages"")..."" "$"skipped"
continue; }
notify.note " * "$"running test"" $arg ("$"info pages"")..."
local infopages errors
# FIXME: non LSB compliant systems are unsupported
infopages="$(\
grep "/share/info/\|^[ ]*%_infodir\|^[ ]*%{_infodir}" $specfile | \
grep -v "^[ ]*#\|^[a-zA-Z]")"
[[ "$infopages" ]] || continue
let "errors = 0"
if [ "$rpm_macro_installinfo" ]; then
grep -q "$rpm_macro_installinfo" $specfile ||
{ let "errors += 1"
notify.debug "rpm_macro_installinfo check failed"; }
fi
if [ "$rpm_macro_uninstallinfo" ]; then
grep -q "$rpm_macro_uninstallinfoo" $specfile ||
{ let "errors += 1"
notify.debug "rpm_macro_uninstallinfo check failed"; }
fi
if [ "$rpm_macro_installinfo_binary" ]; then
grep -q "\
Requires(post)[ \t]*:[ \t]*${rpm_macro_installinfo_binary}" $specfile ||
{ let "errors += 1"
notify.debug "rpm_macro_installinfo_binary check failed"; }
fi
[ "$errors" = "0" ] || notify.error "\
"$"info pages are not installed/uninstalled in the correct way""${NORM}
---------------------------------------
${NOTE}"$"Hint"":${NORM}
$([[ "$rpm_macro_installinfo_binary" ]] &&
echo "Requires(post): $rpm_macro_installinfo_binary" ||
echo "Requires(post): ${path_installinfo:-/sbin/install-info}")
%post [<subpackage>]
$([[ "$rpm_macro_installinfo" ]] &&
echo "$rpm_macro_installinfo %{name}.info" ||
echo "${path_installinfo:-/sbin/install-info} %{name}.info")
%preun [<subpackage>]
$([[ "$rpm_macro_uninstallinfo" ]] &&
echo "$rpm_macro_uninstallinfo %{name}.info" ||
echo "${path_installinfo:-/sbin/install-info} --delete %{name}.info")
exit 0
---------------------------------------
"
;;
8) # 8. check for illegal 'Group's (see configuration file)
skip_test $arg ||
{ notify.note "\
* "$"running test"" $arg ("$"package Groups"")..."" "$"skipped"
continue; }
if [ "${#rpm_allowed_groups[*]}" = 0 ]; then
# 'rpm_allowed_groups' unset in the configuration files
notify.note "\
* "$"running test"" $arg ("$"package Groups"")..."" "$"skipped"
continue
fi
notify.note "\
* "$"running test"" $arg ("$"package Groups"")..."
local i j match
for j in `seq 1 1 ${#SPEC_GROUP[*]}`; do
notify.debug "\
$FUNCNAME: checking if \"${SPEC_GROUP[$j-1]}\" is a known group ..."
let "match = 0"
for i in `seq 1 1 ${#rpm_allowed_groups[*]}`; do
notify.debug "\
$FUNCNAME: current group: \"${rpm_allowed_groups[$i-1]}\""
[ "${rpm_allowed_groups[$i-1]}" = \
"${SPEC_GROUP[$j-1]}" ] &&
{ let "match = 1"; break; }
done
[ "$match" = 1 ] || notify.error "\
"$"invalid \`Group'"" \"${SPEC_GROUP[$j-1]}\"""${NORM}
---------------------------------------
${NOTE}"$"Hint"":${NORM}""
"$"see configuration files"" (\`${NOTE}rpm_allowed_groups${NORM}')
"$"or enter the command"":
${NOTE}@package@ --eval=rpm_allowed_groups${NORM}
---------------------------------------
"
done
;;
9) # 9. check for no approved 'License's (see configuration file)
skip_test $arg ||
{ notify.note "\
* "$"running test"" $arg ("$"approved License"")..."" "$"skipped"
continue; }
if [ "${#rpm_approved_licenses[*]}" = 0 ]; then
# 'rpm_approved_licenses' unset in the configuration files
notify.note "\
* "$"running test"" $arg ("$"approved License"")..."" "$"skipped"
continue
fi
notify.note "\
* "$"running test"" $arg ("$"approved License"")..."
local i j match
for j in `seq 1 1 ${#SPEC_LICENSE[*]}`; do
notify.debug "\
$FUNCNAME: checking if \"${SPEC_LICENSE[$j-1]}\" is an approved license ..."
let "match = 0"
for i in `seq 1 1 ${#rpm_approved_licenses[*]}`; do
notify.debug "\
$FUNCNAME: current license: \"${rpm_approved_licenses[$i-1]}\""
[ "${rpm_approved_licenses[$i-1]}" = \
"${SPEC_LICENSE[$j-1]}" ] &&
{ let "match = 1"; break; }
done
[ "$match" = 1 ] || notify.warning "\
"$"not approved \`License'"" \"${NOTE}${SPEC_LICENSE[$j-1]}${NORM}\"""
---------------------------------------
${NOTE}"$"Hint"":${NORM}""
"$"see configuration files"" (\`${NOTE}rpm_approved_licenses${NORM}')
"$"or enter the command"":
${NOTE}@package@ --eval=rpm_approved_licenses${NORM}
---------------------------------------
"
done
;;
*) # if code reach this point, there is a bug
notify.error $"\
(bug)"" -- $FUNCNAME: "$"illegal value for arg"" (#2): \"$2\"" ;;
esac
done
return 0
}
# function specfile.rotate_bck()
# create a backup copy of the current specfile and rotate the
# last '$spec_backup_numbers' (default = 5) saved specfiles
@ -1466,13 +1147,12 @@ update and check the specfile""${NORM}"
# check in the specfile for some (common) problems
notify.note "\
${NOTE}"$"check the specfile for common mistakes""${NORM}"
specfile.checksintax $SRPM_SPECFILE_WITH_PATH || exit 1
[ -r @libdir@/libtest.lib ] ||
{ echo "$me: "$"library not found"": @libdir@/libtest.lib" 1>&2
exit 1; }
. @libdir@/libtest.lib
# [[ "$rebuild" = 0 && ${#SPEC_PATCH[@]} -gt 0 ]] &&
# notify.warning $"\
#found ${#SPEC_PATCH[@]} patch(es) in the specfile"
test.runall --specfile="$SRPM_SPECFILE_WITH_PATH" # || exit 1
# create a backup copy for the specfile
# specfile.rotate_bck $SRPM_SPECFILE_WITH_PATH
@ -2355,7 +2035,7 @@ $SRPM_SPECFILE_WITH_PATH $USER_RPMDEFINE_OPTS 2>&1"
if [ $rpmbuild_retcode -eq 0 ]; then
notify.note "\n${NOTE}"$"\
It seems good but do not forget to run quality and security tests"\
" (-a8)"${NORM}""
" (-a8)${NORM}""
"
else
local tmpunpackfiles=$(mktemp -q -t $me.XXXXXXXX)
@ -2687,7 +2367,7 @@ $pck-$pck_rpmversion-$pck_rpmrelease$DISTRO_rpm.$target_cpu.rpm"
--tmpdir "$tmpextractdir" || exit 1
# execute all the available tests...
test.runall --testdir "$testdir"
test.runall --packages
# temporary files cleanup
rm -fr $tmpextractdir

View File

@ -1,5 +1,5 @@
# Makefile for autospec
# Copyright (C) 2008 by Davide Madrisan <davide.madrisan@gmail.com>
# Copyright (C) 2008,2012 by Davide Madrisan <davide.madrisan@gmail.com>
# This program is free software; you can redistribute it and/or modify it under
# the terms of version 2 of the GNU General Public License as published by the
@ -18,7 +18,7 @@ srcdir = ..
include $(srcdir)/Makefile.env
pck_tests := test01_pkgquality test02_pkgsecurity
pck_tests := test00_specsyntax test01_pkgquality test02_pkgsecurity
pck_tests_infiles := $(wildcard *.in)
all: