From eb43019406ceaa5becec1f1f6b80d363afbea28a Mon Sep 17 00:00:00 2001 From: Davide Madrisan Date: Sun, 20 May 2012 17:10:03 +0200 Subject: [PATCH] test00_specsyntax: new module and translation files Signed-off-by: Davide Madrisan --- po/it/test00_specsyntax.po | 76 +++++++++ tests/test00_specsyntax.in | 310 +++++++++++++++++++++++++++++++++++++ 2 files changed, 386 insertions(+) create mode 100644 po/it/test00_specsyntax.po create mode 100644 tests/test00_specsyntax.in diff --git a/po/it/test00_specsyntax.po b/po/it/test00_specsyntax.po new file mode 100644 index 0000000..5444b69 --- /dev/null +++ b/po/it/test00_specsyntax.po @@ -0,0 +1,76 @@ +# translation of it.po to Italiana +# Copyright (C) 2012 Davide Madrisan +# Davide Madrisan + +msgid "" +msgstr "" +"Project-Id-Version: it\n" +"POT-Creation-Date: 2012-05-19 22:14+0200\n" +"PO-Revision-Date: 2012-05-19 22:14+0200\n" +"Last-Translator: Davide Madrisan \n" +"Language-Team: Italiana \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +# lib/libtest + +msgid "check the specfile for common mistakes" +msgstr "controllo dello specfile alla ricerca di comuni errori" + +msgid "missing mandatory arg" +msgstr "parametro mancante" + +msgid "checking" +msgstr "sto controllando" + +msgid "running test" +msgstr "esecuzione test" + +msgid "does not point to a valid internet address" +msgstr "non fa riferimento ad un indirizzo internet" + +msgid "not a standard structure (see config file)" +msgstr "nome con struttura non standard (vedi configurazione)" + +msgid "found \\`-D' and/or \\`-T' option(s) in the \\`%setup' directive" +msgstr "sospetta opzione \\`-D' e/o \\`-T' nella direttiva \\`%setup'" + +msgid "missing at least one \\`%defattr' directive" +msgstr "manca almeno una direttiva \\`%defattr'" + +msgid "use rpm macros if possible:" +msgstr "utilizzare le macro rpm quando possibile:" + +msgid "localization files must be packaged via \\`%find_lang'" +msgstr "trovati file di localizzazione non gestiti da \\`%find_lang'" + +msgid "Hint" +msgstr "Suggerimento" + +msgid "info pages" +msgstr "pagine info" + +msgid "info pages are not installed/uninstalled in the correct way" +msgstr "le pagine info non vengono installate/disinstallate correttamente" + +msgid "package Groups" +msgstr "campi Group dei pacchetti" + +msgid "invalid \\`Group'" +msgstr "\\`Group' non valido" + +msgid "see configuration files" +msgstr "guarda nei file di configurazione" + +msgid "or enter the command" +msgstr "oppure esegui il comando" + +msgid "approved License" +msgstr "Licenza valida" + +msgid "not approved \\`License'" +msgstr "\\`License' non approvata" + +msgid "Specfile checks: ${WARN}$total_issues${NOTE} warning(s)." +msgstr "Controllo dello specfile: problemi riscontrati: ${WARN}$total_issues${NOTE}" diff --git a/tests/test00_specsyntax.in b/tests/test00_specsyntax.in new file mode 100644 index 0000000..06114ed --- /dev/null +++ b/tests/test00_specsyntax.in @@ -0,0 +1,310 @@ +#!/bin/bash +# test00_specsyntax -- @package@ test (syntax checks of a specfile) +# Copyright (C) 2012 Davide Madrisan + +[ -z "$BASH" ] || [ ${BASH_VERSION:0:1} -lt 2 ] && + echo $"this script requires bash version 2 or better" >&2 && exit 1 + +[ -r @libdir@/libmsgmng.lib ] || + { echo "$me: "$"library not found"": @libdir@/libmsgmng.lib" 1>&2 + exit 1; } + +. @libdir@/libmsgmng.lib + +if [[ -z "$LANG" && -r /etc/sysconfig/i18n ]]; then + . /etc/sysconfig/i18n + [ "$LANG" ] && export LANG +fi +TEXTDOMAIN="test00_specsyntax"; export TEXTDOMAIN + +# function specfile.checksyntax() +# 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.checksyntax() { + local i rpmvar specfile="$1" + + [[ "$specfile" ]] || notify.error $"\ +(bug)"" -- $FUNCNAME: "$"missing mandatory arg"" (#1)" + notify.debug "$FUNCNAME: specfile = \"$specfile\"" + + notify.note " * $specfile" + + local total_issues=0 + + # 1. checking if 'Source[0]' is a valid internet address + # (skip this test if no '%setup' section has been found) + test.skip $test_number || { + grep -q "^%setup[ \t]*$\|^%setup[ \t]\+" $specfile + if [ $? -eq 0 ]; then + notify.note "$(test.num2str). ${NOTE}"\ +"source0""${NORM}..." + 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" + let "total_issues += 1"; } + fi + fi + fi; } + test_number=$(($test_number + 1)) + + # 2. check if the patches have standard names + # (see the 'patch_name_structure' var in the configure file) + test.skip $test_number || { + notify.note "$(test.num2str). ${NOTE}"\ +$"patch""${NORM}..." + + 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)"; + let "total_issues += 1"; } + done; } + test_number=$(($test_number + 1)) + + # 3. check if `%setup' have `-D' and/or `-T' options + test.skip $test_number || { + notify.note "$(test.num2str). ${NOTE}"\ +$"%setup""${NORM}..." + + [[ "$(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" + let "total_issues += 1"; } + } + test_number=$(($test_number + 1)) + + # 4. check if all the `%files' blocks have a `%defattr' line + # note: skip commented out blocks + test.skip $test_number || { + notify.note "$(test.num2str). ${NOTE}"\ +$"%defattr""${NORM}..." + [[ "$(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" + let "total_issues += 1"; } + } + test_number=$(($test_number + 1)) + + # 5. check if the rpm macros %configure, %make are used + # - look in the block : `%build' to `%install' + test.skip $test_number || { + notify.note "$(test.num2str). ${NOTE}"\ +$"%build, %install""${NORM}..." + + 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'" + let "total_issues += 1"; } + ;; + make) + [[ "$rpm_macro_make" ]] && + { notify.warning \ +$"use rpm macros if possible:""${NORM} + $token --> $rpm_macro_make" + let "total_issues += 1"; } + ;; + esac + done + done + + # do check between`%install' and `%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:""${NORM} +$([[ "$rpm_macro_makeinstall" ]] && + echo " make install -> $rpm_macro_makeinstall" + [[ "$rpm_macro_makeoldinstall" ]] && + echo " make install -> $rpm_macro_makeoldinstall" )" + } ;; + esac + done + done; } + test_number=$(($test_number + 1)) + + # 6. check if '%find_lang' is used when localization files are detected + test.skip $test_number || { + notify.note "$(test.num2str). ${NOTE}"\ +$"%find_lang""${NORM}..." + + # FIXME : the test should perhaps be improved... + grep -q "^[ ]*[^# ]*/share/locale/" $specfile && + { notify.error $"\ +"$"localization files must be packaged via \`%find_lang'""${NORM} +--------------------------------------- +${NOTE}"$"Hint"":${NORM} +%install +... +%find_lang %{name} + +%files -f %{name}.lang +--------------------------------------- +" + let "total_issues += 1"; } + } + test_number=$(($test_number + 1)) + + # 7. check if the install/uninstall code is present + test.skip $test_number || { + notify.note "$(test.num2str). ${NOTE}"\ +$"info pages""${NORM}..." + + local infopages errors + # FIXME: non LSB compliant systems are unsupported + infopages="$(\ +grep "/share/info/\|^[ ]*%_infodir\|^[ ]*%{_infodir}" $specfile | \ +grep -v "^[ ]*#\|^[a-zA-Z]")" + + if [[ "$infopages" ]]; then + 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 [] +$([[ "$rpm_macro_installinfo" ]] && + echo "$rpm_macro_installinfo %{name}.info" || + echo "${path_installinfo:-/sbin/install-info} %{name}.info") + +%preun [] +$([[ "$rpm_macro_uninstallinfo" ]] && + echo "$rpm_macro_uninstallinfo %{name}.info" || + echo "${path_installinfo:-/sbin/install-info} --delete %{name}.info") +exit 0 +--------------------------------------- +" + let "total_issues += $errors"; } + fi; } + test_number=$(($test_number + 1)) + + # 8. check for illegal 'Group's (see configuration file) + test.skip $test_number || { + if [ "${#rpm_allowed_groups[*]}" = 0 ]; then + # 'rpm_allowed_groups' unset in the configuration files + notify.note "$(test.num2str). ${NOTE}"\ +$"package Groups""${NORM}..."" "$"skipped" + else + notify.note "$(test.num2str). ${NOTE}"\ +$"package Groups""${NORM}..." + + 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} +--------------------------------------- +" + let "total_issues += 1"; } + done + fi; } + test_number=$(($test_number + 1)) + + # 9. check for no approved 'License's (see configuration file) + test.skip $test_number || { + if [ "${#rpm_approved_licenses[*]}" = 0 ]; then + # 'rpm_approved_licenses' unset in the configuration files + notify.note "$(test.num2str). ${NOTE}"\ +$"approved License""${NORM}..."" "$"skipped" + else + notify.note "$(test.num2str). ${NOTE}"\ +$"approved License""${NORM}..." + 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} +--------------------------------------- +" + let "total_issues += 1"; } + done + fi; } + test_number=$(($test_number + 1)) + + notify.note " + --> ${NOTE}"$"Specfile checks: ${WARN}$total_issues${NOTE} warning(s).""\ +${NORM}"" +" + return $total_issues +}