Clean up scratchpad files in mock tool testsuite
authorJacob Bachmeyer <jcb@gnu.org>
Mon, 19 Sep 2022 23:38:56 +0000 (18:38 -0500)
committerJacob Bachmeyer <jcb@gnu.org>
Mon, 19 Sep 2022 23:38:56 +0000 (18:38 -0500)
testsuite/lib/mock.exp
testsuite/mock.gpgv/sign.exp

index da212089a59597757d0dd1f43ee1fdfd7feebfd5..9248d4520fb66190be2e7dcad7fd11b561605080 100644 (file)
@@ -1,6 +1,6 @@
 # DejaGnu tool init file for testing gpgv mock tests
 
-# Copyright (C) 2021 Jacob Bachmeyer
+# Copyright (C) 2021, 2022 Jacob Bachmeyer
 #
 # This file is part of a testsuite for the GNU FTP upload system.
 #
@@ -21,9 +21,10 @@ set MINLOGD  [testsuite file -source -top lib exec minlogd.pl]
 set MINSMTPD [testsuite file -source -top lib exec minsmtpd.tcl]
 
 set MOCKGPGV [testsuite file -source -top lib exec mockgpgv]
-set ::env(GNUPGHOME) [file join \
-                         [file dirname [testsuite file -object -top]] \
-                         test.tmp gpgv]
+set GNUPGHOME [file join \
+                  [file dirname [testsuite file -object -top]] \
+                  test.tmp gpgv]
+set ::env(GNUPGHOME) $GNUPGHOME
 
 load_lib mockgpg.exp
 
@@ -33,7 +34,11 @@ proc put_file { file string } {
     close $chan
 }
 
-proc mock_exit {} {}
+proc mock_exit {} {
+    catch {file delete [file join \
+                           [file dirname [testsuite file -object -top]] \
+                           test.tmp]}
+}
 proc mock_version {} {}
 # The mock tools do not have independent versions.
 
index 5f8208f1ae60dc47bc0c7842fcde13990543c8f1..4e5f1cb8f09deea06d7442a848afeda03c91f781 100644 (file)
@@ -1,6 +1,6 @@
 # Signature "verification" tests for GPG mock
 
-# Copyright (C) 2021 Jacob Bachmeyer
+# Copyright (C) 2021, 2022 Jacob Bachmeyer
 #
 # This file is part of a testsuite for the GNU FTP upload system.
 #
@@ -17,9 +17,9 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-file mkdir $::env(GNUPGHOME)
+file mkdir $GNUPGHOME
 
-write_test_keyring [file join $::env(GNUPGHOME) dg1.gpg] {
+write_test_keyring [file join $GNUPGHOME dg1.gpg] {
     { id 1001 name {test 1-1} }
     { id 1002 name {test 1-2} }
     { id 1003 name {test 1-3} expires {+5 minutes} }
@@ -29,7 +29,7 @@ write_test_keyring [file join $::env(GNUPGHOME) dg1.gpg] {
        is revoked expired {5 minutes ago} }
 }
 
-write_test_keyring [file join $::env(GNUPGHOME) dg2.gpg] {
+write_test_keyring [file join $GNUPGHOME dg2.gpg] {
     { id 1011 name {test 2-1 (primary)} }
     { id 1012 name {test 2-2 (subkey)} subkey-of 1011 }
     { id 1013 name {test 2-3 (subkey)} subkey-of 1011 expires {+5 minutes} }
@@ -58,6 +58,16 @@ proc spawn_gpgv { keyrings args } {
     eval $cmd $args
 }
 
+# invoked by DejaGnu framework when a failure is recorded
+proc gpgv_count_failures {args } {
+    global gpgv_total_failure_count gpgv_local_failure_count
+    incr gpgv_total_failure_count
+    incr gpgv_local_failure_count
+}
+set local_record_procs(fail) gpgv_count_failures
+set gpgv_total_failure_count 0
+set gpgv_local_failure_count 0
+
 # InitialCapital variable names may be used in the $expect block.
 # The "test_dir" variable is also set for the $init block.
 proc run_gpgv_test { Name stem keyrings exitCode init phases assess expect } {
@@ -65,6 +75,9 @@ proc run_gpgv_test { Name stem keyrings exitCode init phases assess expect } {
                      [file dirname [testsuite file -object -top]] test.tmp]
     file mkdir $test_dir
 
+    global gpgv_local_failure_count
+    set gpgv_local_failure_count 0
+
     eval $init
 
     array set A {}
@@ -114,6 +127,12 @@ proc run_gpgv_test { Name stem keyrings exitCode init phases assess expect } {
            }
        }
     }
+
+    if { $gpgv_local_failure_count == 0 } {
+       foreach scratchfile [list "${stem}" "${stem}.asc" "${stem}.sig"] {
+           file delete -- [file join $test_dir $scratchfile]
+       }
+    }
 }
 proc do_gpgv_test { Name stem keyrings exitCode signature assess expect } {
     run_gpgv_test $Name $stem $keyrings $exitCode \
@@ -739,3 +758,11 @@ do_gpgv_test "expired signature from expired subkey" t9b {dg2.gpg} 0 \
            exp_continue
        }
     }
+
+#
+
+if { $gpgv_total_failure_count == 0 } {
+    file delete -force $GNUPGHOME
+}
+
+#EOF