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=0284e2a346c13ea7912af9549f061fbdcc285a0c

commit 0284e2a346c13ea7912af9549f061fbdcc285a0c
Author: Guillem Jover <[email protected]>
AuthorDate: Thu Feb 6 10:36:05 2025 +0100

    test: Rework OpenPGP backend selection to prepare for cmdv support
    
    Unify all backend information into a single list, and use that to select
    the various variants of the backends.
---
 scripts/Test/Dpkg.pm     | 59 +++++++++++++++++++++++++++++++-----------------
 scripts/t/Dpkg_OpenPGP.t | 23 +++++++++++--------
 2 files changed, 51 insertions(+), 31 deletions(-)

diff --git a/scripts/Test/Dpkg.pm b/scripts/Test/Dpkg.pm
index 7e8d34cfb..470bb3025 100644
--- a/scripts/Test/Dpkg.pm
+++ b/scripts/Test/Dpkg.pm
@@ -47,7 +47,6 @@ our @EXPORT_OK = qw(
     test_needs_openpgp_backend
     test_needs_srcdir_switch
     test_neutralize_checksums
-    test_get_openpgp_backend
 );
 our %EXPORT_TAGS = (
     needs => [ qw(
@@ -198,47 +197,65 @@ sub test_needs_command
     }
 }
 
-my %openpgp_command = (
-    'gpg-sq' => {
+my @openpgp_backends = (
+    {
         backend => 'gpg',
+        cmd => 'gpg-sq',
     },
-    'gpg' => {
+    {
         backend => 'gpg',
+        cmd => 'gpg',
     },
-    'sq' => {
+    {
         backend => 'sq',
+        cmd => 'sq',
     },
-    'sqop' => {
+    {
         backend => 'sop',
+        cmd => 'sqop',
     },
-    'rsop' => {
+    {
         backend => 'sop',
+        cmd => 'rsop',
     },
-    'gosop' => {
+    {
         backend => 'sop',
+        cmd => 'gosop',
     },
-    'pgpainless-cli' => {
+    {
         backend => 'sop',
+        cmd => 'pgpainless-cli',
     },
 );
 
 sub test_needs_openpgp_backend
 {
-    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";
-    }
+    my @have_backends;
+    foreach my $backend (@openpgp_backends) {
+        my $name = $backend->{backend};
+        my $cmd = $backend->{cmd};
 
-    return @have_cmds;
-}
+        my $have_cmd = $cmd eq 'none' ? 0 : can_run($cmd);
 
-sub test_get_openpgp_backend
-{
-    my $cmd = shift;
+        next unless $have_cmd;
+
+        my $have_backend = {
+            backend => $name,
+        };
+        $have_backend->{cmd} = $cmd if $have_cmd;
+
+        push @have_backends, $have_backend;
+    }
+    if (@have_backends == 0) {
+        my @cmds = grep {
+            defined
+        } map {
+            $_->{cmd}
+        } @openpgp_backends;
+        plan skip_all => "requires >= 1 openpgp command: @cmds";
+    }
 
-    return 'auto' if $cmd eq 'auto';
-    return $openpgp_command{$cmd}{backend};
+    return @have_backends;
 }
 
 sub test_needs_srcdir_switch
diff --git a/scripts/t/Dpkg_OpenPGP.t b/scripts/t/Dpkg_OpenPGP.t
index 97cde7c51..506984ee0 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 test_get_openpgp_backend);
+use Test::Dpkg qw(:paths :needs);
 
 use File::Compare;
 
@@ -25,10 +25,13 @@ use Dpkg::ErrorHandling;
 use Dpkg::Path qw(find_command);
 use Dpkg::OpenPGP::KeyHandle;
 
-my @cmds = test_needs_openpgp_backend();
-unshift @cmds, 'auto';
+my @backends = test_needs_openpgp_backend();
+unshift @backends, {
+    backend => 'auto',
+    cmd => 'auto',
+};
 
-plan tests => 2 + 15 * scalar @cmds;
+plan tests => 2 + 15 * scalar @backends;
 
 use_ok('Dpkg::OpenPGP');
 use_ok('Dpkg::OpenPGP::ErrorCodes');
@@ -46,19 +49,19 @@ sub test_diff
     ok($res == 0, "$desc ($exp_file vs $gen_file)");
 }
 
-foreach my $cmd (@cmds) {
+foreach my $backend_opts (@backends) {
     my $datadir = test_get_data_path();
     my $tempdir = test_get_temp_path();
 
-    my $backend = test_get_openpgp_backend($cmd);
-    my $openpgp = Dpkg::OpenPGP->new(
-        backend => $backend,
-        cmd => $cmd,
-    );
+    my $backend = $backend_opts->{backend};
+    my $cmd = $backend_opts->{cmd} || 'none';
+    my $openpgp = Dpkg::OpenPGP->new(%{$backend_opts});
 
     my $certfile = "$datadir/dpkg-test-pub.asc";
     my $keyfile  = "$datadir/dpkg-test-sec.asc";
 
+    note("openpgp backend=$backend cmd=$cmd");
+
     SKIP: {
         skip 'missing backend command', 9
             unless $openpgp->{backend}->has_backend_cmd();

-- 
Dpkg.Org's dpkg

Reply via email to