simplify: all 3 mock-ups are strings that get eval'd, so do this properly.
authorespie <espie@openbsd.org>
Mon, 9 Oct 2023 07:03:49 +0000 (07:03 +0000)
committerespie <espie@openbsd.org>
Mon, 9 Oct 2023 07:03:49 +0000 (07:03 +0000)
usr.sbin/pkg_add/OpenBSD/AddCreateDelete.pm

index 8c285ea..d22740c 100644 (file)
@@ -1,5 +1,5 @@
 # ex:ts=8 sw=4:
-# $OpenBSD: AddCreateDelete.pm,v 1.55 2023/10/08 12:44:58 espie Exp $
+# $OpenBSD: AddCreateDelete.pm,v 1.56 2023/10/09 07:03:49 espie Exp $
 #
 # Copyright (c) 2007-2014 Marc Espie <espie@openbsd.org>
 #
@@ -56,30 +56,24 @@ sub add_interactive_options($self)
 }
 
 my $setup = {
-       nowantlib => sub() {
-           eval '
+       nowantlib => q'
                use OpenBSD::Dependencies::SolverBase;
                no warnings qw(redefine);
                package OpenBSD::Dependencies::SolverBase;
                sub solve_wantlibs($, $) { 1 }
-           ';
-       },
-       nosystemwantlib => sub() {
-           eval '
+           ',
+       nosystemwantlib => q'
                use OpenBSD::LibSpec;
                package OpenBSD::Library::System;
                sub no_match_dispatch($library, $spec, $base)
                {
                        return $spec->no_match_name($library, $base);
                }
-           ';
-       },
-       norun => sub() {
-           eval '
+           ',
+       norun => q'
                package OpenBSD::State;
                sub _system(@) { 0 }
-           ';
-       },
+           ',
 };
                
 
@@ -110,7 +104,12 @@ sub handle_options($state, $opt_string, @usage)
                for my $i (split(',', $state->defines('REGRESSION_TESTING'))) {
                        $state->{regression}{$i} = 1;
                        if (defined $setup->{$i}) {
-                               &{$setup->{$i}}();
+                               eval "$setup->{$i}";
+                               if ($@) {
+                                       $state->fatal(
+                                           "Regression testing #1: #2", 
+                                           $i, $@);
+                               }
                        }
                }
        }