1111use 5.32.0;
1212use strict;
1313use warnings;
14- use Test::More tests => 6 ;
14+ use Test::More tests => 8 ;
1515
1616# Test Getopt::Long functionality that was broken by the regression
1717BEGIN {
@@ -23,20 +23,31 @@ can_ok('main', 'GetOptions');
2323
2424# Test 2: Simple option parsing without arguments
2525my $simple_flag = 0;
26- my @ARGV = (' --simple' );
26+ # Save original @ARGV
27+ my @original_argv = @ARGV ;
28+ # Set @ARGV to simulate command line arguments
29+ @ARGV = (' --simple' );
2730ok(GetOptions(' simple' => \$simple_flag ), ' Simple flag parsing works' );
2831is($simple_flag , 1, ' Simple flag was set correctly' );
32+ # Restore original @ARGV
33+ @ARGV = @original_argv ;
2934
3035# Test 3: Option with value
3136my $with_value = ' ' ;
37+ # Save original @ARGV
38+ my @original_argv3 = @ARGV ;
3239@ARGV = (' --value=test123' );
3340ok(GetOptions(' value=s' => \$with_value ), ' Option with value parsing works' );
3441is($with_value , ' test123' , ' Value option was set correctly' );
42+ # Restore original @ARGV
43+ @ARGV = @original_argv3 ;
3544
3645# Test 4: Multiple options
3746my $width = 10;
3847my $height = 5;
3948my $generations = 1;
49+ # Save original @ARGV
50+ my @original_argv4 = @ARGV ;
4051@ARGV = (' --width=10' , ' --height=5' , ' --generations=1' );
4152ok(GetOptions(
4253 ' width=i' => \$width ,
@@ -46,3 +57,5 @@ ok(GetOptions(
4657
4758is_deeply([$width , $height , $generations ], [10, 5, 1],
4859 ' Multiple options were set correctly' );
60+ # Restore original @ARGV
61+ @ARGV = @original_argv4 ;
0 commit comments