This is an automated email from the git hooks/post-receive script.

guillem pushed a commit to branch main
in repository dpkg.

View the commit online:
https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=b46e860fa360f17a3646bf1babc8ca6ec9062069

commit b46e860fa360f17a3646bf1babc8ca6ec9062069
Author: Guillem Jover <[email protected]>
AuthorDate: Sat Mar 9 00:12:23 2024 +0100

    test: Refactor OpenPGP backend and commands list
    
    Instead of having two places to keep up-to-date, unify this in the
    Test::Dpkg module into a single hash, and add a getter so that we can
    keep one place to track this data.
---
 scripts/Test/Dpkg.pm     | 43 ++++++++++++++++++++++++++++++++-----------
 scripts/t/Dpkg_OpenPGP.t | 12 ++----------
 2 files changed, 34 insertions(+), 21 deletions(-)

diff --git a/scripts/Test/Dpkg.pm b/scripts/Test/Dpkg.pm
index 1632ad861..ce98be223 100644
--- a/scripts/Test/Dpkg.pm
+++ b/scripts/Test/Dpkg.pm
@@ -47,6 +47,7 @@ our @EXPORT_OK = qw(
     test_needs_openpgp_backend
     test_needs_srcdir_switch
     test_neutralize_checksums
+    test_get_openpgp_backend
 );
 our %EXPORT_TAGS = (
     needs => [ qw(
@@ -197,21 +198,41 @@ sub test_needs_command
     }
 }
 
+my %openpgp_command = (
+    'gpg-sq' => {
+        backend => 'gpg',
+    },
+    'gpg' => {
+        backend => 'gpg',
+    },
+    'sq' => {
+        backend => 'sq',
+    },
+    'sqop' => {
+        backend => 'sop',
+    },
+    'pgpainless-cli' => {
+        backend => 'sop',
+    },
+);
+
 sub test_needs_openpgp_backend
 {
-    my @backends = qw(
-        gpg-sq
-        gpg
-        sq
-        sqop
-        pgpainless-cli
-    );
-    my @cmds = grep { can_run($_) } @backends;
-    if (@cmds == 0) {
-        plan skip_all => "requires >= 1 openpgp command: @backends";
+    my @cmds = sort keys %openpgp_command;
+    my @have_cmds = grep { can_run($_) } @cmds;
+    if (@have_cmds == 0) {
+        plan skip_all => "requires >= 1 openpgp command: @cmds";
     }
 
-    return @cmds;
+    return @have_cmds;
+}
+
+sub test_get_openpgp_backend
+{
+    my $cmd = shift;
+
+    return 'auto' if $cmd eq 'auto';
+    return $openpgp_command{$cmd}{backend};
 }
 
 sub test_needs_srcdir_switch
diff --git a/scripts/t/Dpkg_OpenPGP.t b/scripts/t/Dpkg_OpenPGP.t
index d4090829e..d0184ea05 100644
--- a/scripts/t/Dpkg_OpenPGP.t
+++ b/scripts/t/Dpkg_OpenPGP.t
@@ -17,7 +17,7 @@ use strict;
 use warnings;
 
 use Test::More;
-use Test::Dpkg qw(:paths :needs);
+use Test::Dpkg qw(:paths :needs test_get_openpgp_backend);
 
 use File::Compare;
 
@@ -25,14 +25,6 @@ use Dpkg::ErrorHandling;
 use Dpkg::Path qw(find_command);
 use Dpkg::OpenPGP::KeyHandle;
 
-my %backend_cmd = (
-    auto => 'auto',
-    'gpg-sq' => 'gpg',
-    gpg => 'gpg',
-    sq => 'sq',
-    sqop => 'sop',
-    'pgpainless-cli' => 'sop',
-);
 my @cmds = test_needs_openpgp_backend();
 unshift @cmds, 'auto';
 
@@ -58,7 +50,7 @@ foreach my $cmd (@cmds) {
     my $datadir = test_get_data_path();
     my $tempdir = test_get_temp_path();
 
-    my $backend = $backend_cmd{$cmd};
+    my $backend = test_get_openpgp_backend($cmd);
     my $openpgp = Dpkg::OpenPGP->new(
         backend => $backend,
         cmd => $cmd,

-- 
Dpkg.Org's dpkg

Reply via email to