From: Ben Crocker <bcroc...@redhat.com>

Makefile:

Create new dist-self-test target and hook up the BATS
self tests.  Check for the presence of /usr/bin/bats
(via 'test -x') and complain if it is not installed.

1005-dist-dump-variables.bats:

In prologue, need to unset environment variables that may
have been inherited from a supra-make.

Collect the actual testing code into a new checkversion() function;
add line breaks and indentation in both prologue() and checkversion()
for better readability.

Signed-off-by: Ben Crocker <bcroc...@redhat.com>
---
 redhat/Makefile                               |  7 ++++
 .../self-test/1005-dist-dump-variables.bats   | 41 ++++++++++---------
 2 files changed, 29 insertions(+), 19 deletions(-)

diff --git a/redhat/Makefile b/redhat/Makefile
index fd10ac8f145d..84950bf876af 100644
--- a/redhat/Makefile
+++ b/redhat/Makefile
@@ -392,6 +392,13 @@ dist-dump-variables:
        chmod +x $(REDHAT)/dist-dump-variables.sh
        @$(REDHAT)/dist-dump-variables.sh
 
+dist-self-test:
+       @if test -x /usr/bin/bats; then \
+               bats $(REDHAT)/self-test/*.bats ; \
+       else \
+               echo "dist-self-test: The bats package is not installed" ; \
+       fi
+
 dist-help:
        @echo  'Cleaning targets:'
        @echo  '  dist-clean          - Clean redhat/configs/ and redhat/rpm/ 
directories.'
diff --git a/redhat/self-test/1005-dist-dump-variables.bats 
b/redhat/self-test/1005-dist-dump-variables.bats
index bff950e6643a..9251ca4636d5 100644
--- a/redhat/self-test/1005-dist-dump-variables.bats
+++ b/redhat/self-test/1005-dist-dump-variables.bats
@@ -4,49 +4,52 @@ function prologue()
 {
     tag=$1
     ofile=$BATS_TMPDIR/$tag.out
+    # Have to unset environment variables that may be inherited from 
supra-make:
+    grep "^[   ]*[a-zA-Z_][a-zA-Z_0-9]*[       ]*[:?]*=" \
+         $BATS_TEST_DIRNAME/../Makefile.common | \
+        sed -e 's/[    ]*\([a-zA-Z_][a-zA-Z_0-9]*\).*/unset \1/' | \
+        sort | uniq > $BATS_TMPDIR/unset-vars.sh
+    source $BATS_TMPDIR/unset-vars.sh
     GIT=$BATS_TEST_DIRNAME/egit.sh HEAD=$tag EGIT_OVERRIDE_DESCRIBE=$tag 
DIST=.fc33 make dist-dump-variables > $ofile
 }
 
-@test "dist-dump-variables v5.8" {
-    tag=v5.8
-    prologue $tag
+function checkversion()
+{
     status=1
-    if grep -x "_TAG=$tag" $ofile && grep -x "RPMKVERSION=5" $ofile && grep -x 
"RPMKPATCHLEVEL=8" $ofile && grep -x "RPMKSUBLEVEL=0" $ofile && grep -x 
"RPMKEXTRAVERSION=" $ofile && grep -x "KEXTRAVERSION=" $ofile && grep -x 
"SNAPSHOT=0" $ofile
+    if grep -x "_TAG=$1" $ofile && \
+            grep -x "RPMKVERSION=$2" $ofile && grep -x "RPMKPATCHLEVEL=$3" 
$ofile && \
+            grep -x "RPMKSUBLEVEL=$4" $ofile && grep -x "RPMKEXTRAVERSION=$5" 
$ofile && \
+            grep -x "KEXTRAVERSION=$6" $ofile && \
+            grep -x "SNAPSHOT=$7" $ofile
     then
         status=$?
     fi
+}
+
+@test "dist-dump-variables v5.8" {
+    tag=v5.8
+    prologue $tag
+    checkversion $tag "5" "8" "0" "" "" "0"
     [ "$status" = 0 ]
 }
 
 @test "dist-dump-variables v5.8-rc7" {
     tag=v5.8-rc7
     prologue $tag
-    status=1
-    if grep -x "_TAG=$tag" $ofile && grep -x "RPMKVERSION=5" $ofile && grep -x 
"RPMKPATCHLEVEL=8" $ofile && grep -x "RPMKSUBLEVEL=0" $ofile && grep -x 
"RPMKEXTRAVERSION=-rc7" $ofile && grep -x "KEXTRAVERSION=.rc7" $ofile && grep 
-x "SNAPSHOT=0" $ofile
-    then
-        status=$?
-    fi
+    checkversion $tag "5" "8" "0" "-rc7" ".rc7" "0"
     [ "$status" = 0 ]
 }
 
 @test "dist-dump-variables v5.8-9-g565674d613d7" {
     tag=v5.8-9-g565674d613d7
     prologue $tag
-    status=1
-    if grep -x "_TAG=$tag" $ofile && grep -x "RPMKVERSION=5" $ofile && grep -x 
"RPMKPATCHLEVEL=9" $ofile && grep -x "RPMKSUBLEVEL=0" $ofile && grep -x 
"RPMKEXTRAVERSION=" $ofile && grep -x "KEXTRAVERSION=.rc0" $ofile && grep -x 
"SNAPSHOT=1" $ofile
-    then
-        status=$?
-    fi
+    checkversion $tag "5" "9" "0" "" ".rc0" "1"
     [ "$status" = 0 ]
 }
 
 @test "dist-dump-variables v5.8-rc5-99-g25ccd24ffd91" {
     tag=v5.8-rc5-99-g25ccd24ffd91
     prologue $tag
-    status=1
-    if grep -x "_TAG=$tag" $ofile && grep -x "RPMKVERSION=5" $ofile && grep -x 
"RPMKPATCHLEVEL=8" $ofile && grep -x "RPMKSUBLEVEL=0" $ofile && grep -x 
"RPMKEXTRAVERSION=-rc5" $ofile && grep -x "KEXTRAVERSION=.rc5" $ofile && grep 
-x "SNAPSHOT=1" $ofile
-    then
-        status=$?
-    fi
+    checkversion $tag "5" "8" "0" "-rc5" ".rc5" "1"
     [ "$status" = 0 ]
 }
-- 
GitLab
_______________________________________________
kernel mailing list -- kernel@lists.fedoraproject.org
To unsubscribe send an email to kernel-le...@lists.fedoraproject.org
Fedora Code of Conduct: 
https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedoraproject.org/archives/list/kernel@lists.fedoraproject.org

Reply via email to