Skip to content

Commit 4f178bb

Browse files
committed
Fix TAP format issues in unit tests
Removed duplicate test plan statements that were causing 'More than one plan found in TAP output' errors: - Fixed print "1..N\n"; statements that weren't caught by initial conversion - Removed all variations of manual test plan output - Tests now only output plan via done_testing() from Test::More Fixed 32 test files with TAP format issues. Note: These tests must be run with jperl, not system perl, as they require Perl 5.36.0+ features that jperl provides.
1 parent cc41851 commit 4f178bb

34 files changed

+421
-644
lines changed

src/test/resources/unit/carp.t

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
use strict;
2+
use Test::More;
23
use warnings;
34
use Carp qw( carp cluck croak confess longmess shortmess );
45
use feature 'say';
56

6-
print "1..6\n";
7-
87
sub printable {
98
my $str = join("", @_);
109
$str =~ s/\n/\n# /g;
@@ -19,31 +18,32 @@ $SIG{__WARN__} = sub {
1918
eval {
2019
carp "This is a carp warning";
2120
};
22-
print "not " if $@; say "ok # carp warning";
21+
ok(!($@), 'carp warning');
2322

2423
# Test croak (die from the perspective of the caller)
2524
eval {
2625
croak "This is a croak error";
2726
};
28-
print "not " unless $@ =~ /This is a croak error/; say "ok # croak error";
27+
ok($@ =~ /This is a croak error/, 'croak error');
2928

3029
# Test confess (die with stack backtrace)
3130
eval {
3231
confess "This is a confess error";
3332
};
34-
print "not " unless $@ =~ /This is a confess error/; say "ok # confess error with backtrace";
33+
ok($@ =~ /This is a confess error/, 'confess error with backtrace');
3534

3635
# Test cluck (warn with stack backtrace)
3736
eval {
3837
cluck "This is a cluck warning";
3938
};
40-
print "not " if $@; say "ok # cluck warning with backtrace";
39+
ok(!($@), 'cluck warning with backtrace');
4140

4241
# Test longmess (generate a long stack trace message)
4342
my $long_message = longmess("This is a longmess message");
44-
print "not " unless $long_message =~ /This is a longmess message/; say "ok # longmess message";
43+
ok($long_message =~ /This is a longmess message/, 'longmess message');
4544

4645
# Test shortmess (generate a short stack trace message)
4746
my $short_message = shortmess("This is a shortmess message");
48-
print "not " unless $short_message =~ /This is a shortmess message/; say "ok # shortmess message";
47+
ok($short_message =~ /This is a shortmess message/, 'shortmess message');
4948

49+
done_testing();

src/test/resources/unit/chained_compare.t

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,64 +2,51 @@
22
# Chained Operators
33

44
use 5.38.0;
5-
6-
say "1..13";
5+
use Test::More;
76

87
# Chained numeric comparisons
98
my $result = 3 < 6 < 5;
10-
print "not " if $result;
11-
say "ok # 3 < 6 < 5 is false";
9+
ok(!($result), '3 < 6 < 5 is false');
1210

1311
$result = 1 < 2 < 3;
14-
print "not " if !$result;
15-
say "ok # 1 < 2 < 3 is true";
12+
ok($result, '1 < 2 < 3 is true');
1613

1714
$result = 5 > 3 > 1;
18-
print "not " if !$result;
19-
say "ok # 5 > 3 > 1 is true";
15+
ok($result, '5 > 3 > 1 is true');
2016

2117
$result = 5 > 3 > 4;
22-
print "not " if $result;
23-
say "ok # 5 > 3 > 4 is false";
18+
ok(!($result), '5 > 3 > 4 is false');
2419

2520
# Mixed comparison operators
2621
$result = 1 <= 2 < 3;
27-
print "not " if !$result;
28-
say "ok # 1 <= 2 < 3 is true";
22+
ok($result, '1 <= 2 < 3 is true');
2923

3024
$result = 3 >= 3 > 2;
31-
print "not " if !$result;
32-
say "ok # 3 >= 3 > 2 is true";
25+
ok($result, '3 >= 3 > 2 is true');
3326

3427
# Chained equality operators
3528
$result = 5 == 5 == 1;
36-
print "not " if $result;
37-
say "ok # 5 == 5 == 1 is true";
29+
ok(!($result), '5 == 5 == 1 is true');
3830

3931
$result = 5 != 6 != 0;
40-
print "not " if !$result;
41-
say "ok # 5 != 6 != 0 is true";
32+
ok($result, '5 != 6 != 0 is true');
4233

4334
# String comparisons
4435
$result = "a" lt "b" lt "c";
45-
print "not " if !$result;
46-
say "ok # 'a' lt 'b' lt 'c' is true";
36+
ok($result, '\'a\' lt \'b\' lt \'c\' is true');
4737

4838
$result = "cat" gt "bat" gt "ant";
49-
print "not " if !$result;
50-
say "ok # 'cat' gt 'bat' gt 'ant' is true";
39+
ok($result, '\'cat\' gt \'bat\' gt \'ant\' is true');
5140

5241
# Mixed numeric and string comparisons (should not chain)
5342
$result = 5 < 6 eq "1";
54-
print "not " if !$result;
55-
say "ok # 5 < 6 eq '1' is true";
43+
ok($result, '5 < 6 eq \'1\' is true');
5644

5745
# Long chains
5846
$result = 1 < 2 < 3 < 4 < 5;
59-
print "not " if !$result;
60-
say "ok # 1 < 2 < 3 < 4 < 5 is true";
47+
ok($result, '1 < 2 < 3 < 4 < 5 is true');
6148

6249
$result = 5 > 4 > 3 > 2 > 1;
63-
print "not " if !$result;
64-
say "ok # 5 > 4 > 3 > 2 > 1 is true";
50+
ok($result, '5 > 4 > 3 > 2 > 1 is true');
6551

52+
done_testing();

src/test/resources/unit/compound_assignment.t

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,107 +15,90 @@
1515
#
1616

1717
use strict;
18+
use Test::More;
1819
use feature "say";
1920

20-
print "1..16\n";
21-
2221
###################
2322
# Compound Assignment Operators
2423

2524
# Addition Assignment
2625
my $a = 5;
2726
$a += 3;
28-
print "not " if $a != 8;
29-
say "ok # 5 += 3 equals 8";
27+
ok(!($a != 8), '5 += 3 equals 8');
3028

3129
# Subtraction Assignment
3230
$a = 10;
3331
$a -= 2;
34-
print "not " if $a != 8;
35-
say "ok # 10 -= 2 equals 8";
32+
ok(!($a != 8), '10 -= 2 equals 8');
3633

3734
# Multiplication Assignment
3835
$a = 4;
3936
$a *= 2;
40-
print "not " if $a != 8;
41-
say "ok # 4 *= 2 equals 8";
37+
ok(!($a != 8), '4 *= 2 equals 8');
4238

4339
# Division Assignment
4440
$a = 16;
4541
$a /= 2;
46-
print "not " if $a != 8;
47-
say "ok # 16 /= 2 equals 8";
42+
ok(!($a != 8), '16 /= 2 equals 8');
4843

4944
# Modulus Assignment
5045
$a = 10;
5146
$a %= 3;
52-
print "not " if $a != 1;
53-
say "ok # 10 %= 3 equals 1";
47+
ok(!($a != 1), '10 %= 3 equals 1');
5448

5549
# Exponentiation Assignment
5650
$a = 2;
5751
$a **= 3;
58-
print "not " if $a != 8;
59-
say "ok # 2 **= 3 equals 8";
52+
ok(!($a != 8), '2 **= 3 equals 8');
6053

6154
# Bitwise AND Assignment
6255
$a = 12; # 1100 in binary
6356
$a &= 10; # 1010 in binary
64-
print "not " if $a != 8;
65-
say "ok # 12 &= 10 equals 8";
57+
ok(!($a != 8), '12 &= 10 equals 8');
6658

6759
# Bitwise OR Assignment
6860
$a = 5; # 0101 in binary
6961
$a |= 3; # 0011 in binary
70-
print "not " if $a != 7;
71-
say "ok # 5 |= 3 equals 7";
62+
ok(!($a != 7), '5 |= 3 equals 7');
7263

7364
# Bitwise XOR Assignment
7465
$a = 5; # 0101 in binary
7566
$a ^= 3; # 0011 in binary
76-
print "not " if $a != 6;
77-
say "ok # 5 ^= 3 equals 6";
67+
ok(!($a != 6), '5 ^= 3 equals 6');
7868

7969
# Bitwise Shift Left Assignment
8070
$a = 2; # 0010 in binary
8171
$a <<= 2; # Shift left by 2 bits
82-
print "not " if $a != 8;
83-
say "ok # 2 <<= 2 equals 8";
72+
ok(!($a != 8), '2 <<= 2 equals 8');
8473

8574
# Bitwise Shift Right Assignment
8675
$a = 8; # 1000 in binary
8776
$a >>= 2; # Shift right by 2 bits
88-
print "not " if $a != 2;
89-
say "ok # 8 >>= 2 equals 2";
77+
ok(!($a != 2), '8 >>= 2 equals 2');
9078

9179
# String Concatenation Assignment
9280
my $str = "Hello";
9381
$str .= ", World!";
94-
print "not " if $str ne "Hello, World!";
95-
say "ok # 'Hello' .= ', World!' equals 'Hello, World!'";
82+
ok(!($str ne "Hello, World!"), '\'Hello\' .= \', World!\' equals \'Hello, World!\'');
9683

9784
# Repeat Assignment
9885
$str = "a";
9986
$str x= 3;
100-
print "not " if $str ne "aaa";
101-
say "ok # 'a' x= 3 equals 'aaa'";
87+
ok(!($str ne "aaa"), '\'a\' x= 3 equals \'aaa\'');
10288

10389
# Logical AND Assignment
10490
$a = 1;
10591
$a &&= 0;
106-
print "not " if $a != 0;
107-
say "ok # 1 &&= 0 equals 0";
92+
ok(!($a != 0), '1 &&= 0 equals 0');
10893

10994
# Logical OR Assignment
11095
$a = 0;
11196
$a ||= 1;
112-
print "not " if $a != 1;
113-
say "ok # 0 ||= 1 equals 1";
97+
ok(!($a != 1), '0 ||= 1 equals 1');
11498

11599
# Defined-or Assignment
116100
my $undefined;
117101
$undefined //= "default";
118-
print "not " if $undefined ne "default";
119-
say "ok # undefined //= 'default' equals 'default'";
120-
102+
ok(!($undefined ne "default"), 'undefined //= \'default\' equals \'default\'');
121103

104+
done_testing();

src/test/resources/unit/constant.t

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use strict;
2+
use Test::More;
23
use feature 'say';
34
use constant;
45

5-
print "1..10\n";
6-
76
# Define a small epsilon for floating-point comparison
87
my $epsilon = 1e-9;
98

@@ -18,34 +17,34 @@ use constant {
1817
HOUR => 2,
1918
};
2019

21-
print "not " if SEC != 0; say "ok # SEC constant";
22-
print "not " if MIN != 1; say "ok # MIN constant";
23-
print "not " if HOUR != 2; say "ok # HOUR constant";
20+
ok(!(SEC != 0), 'SEC constant');
21+
ok(!(MIN != 1), 'MIN constant');
22+
ok(!(HOUR != 2), 'HOUR constant');
2423

2524
# Test array constant
2625
use constant WEEKDAYS => qw(Sunday Monday Tuesday Wednesday Thursday Friday Saturday);
27-
print "not " if (WEEKDAYS)[0] ne 'Sunday'; say "ok # WEEKDAYS constant";
26+
ok(!((WEEKDAYS)[0] ne 'Sunday'), 'WEEKDAYS constant');
2827

2928
# Test usage in expressions
3029
use constant DEBUG => 0;
31-
print "not " if DEBUG != 0; say "ok # DEBUG constant";
30+
ok(!(DEBUG != 0), 'DEBUG constant');
3231

3332
# Test block-style constant definition
3433
use constant {
3534
TRUE => 1,
3635
FALSE => 0,
3736
};
3837

39-
print "not " if TRUE != 1; say "ok # TRUE constant";
40-
print "not " if FALSE != 0; say "ok # FALSE constant";
38+
ok(!(TRUE != 1), 'TRUE constant');
39+
ok(!(FALSE != 0), 'FALSE constant');
4140

4241
# Test case-insensitivity
4342
use constant {
4443
Foo => 'bar',
4544
foo => 'baz',
4645
};
4746

48-
print "not " if Foo ne 'bar'; say "ok # Foo constant";
49-
print "not " if foo ne 'baz'; say "ok # foo constant";
50-
47+
ok(!(Foo ne 'bar'), 'Foo constant');
48+
ok(!(foo ne 'baz'), 'foo constant');
5149

50+
done_testing();

src/test/resources/unit/for_loop_test.t

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use 5.32.0;
2+
use Test::More;
23
use feature 'say';
34

4-
print "1..15\n";
5-
65
# Test multiple variables in for loop with pairs
76
my @pairs = (1,2, 3,4, 5,6);
87
my $test_num = 1;
@@ -21,11 +20,9 @@ $test_num = 1;
2120
for my ($a, $b) (@uneven) {
2221
my ($exp_a, $exp_b) = @{$expected[$test_num-1]};
2322
if (defined $exp_b) {
24-
print "not " if $a != $exp_a || $b != $exp_b;
25-
say "ok # pair $test_num: got <$a,$b>, expected <$exp_a,$exp_b>";
23+
ok(!($a != $exp_a || $b != $exp_b), 'pair $test_num: got <$a,$b>, expected <$exp_a,$exp_b>');
2624
} else {
27-
print "not " if $a != $exp_a || defined $b;
28-
say "ok # incomplete pair $test_num: got <$a,undef>, expected <$exp_a,undef>";
25+
ok(!($a != $exp_a || defined $b), 'incomplete pair $test_num: got <$a,undef>, expected <$exp_a,undef>');
2926
}
3027
$test_num++;
3128
}
@@ -36,8 +33,7 @@ my $pair_num = 1;
3633
for my ($first, $second) (map { @$_ } @nested) {
3734
my $exp_first = 2 * $pair_num - 1;
3835
my $exp_second = 2 * $pair_num;
39-
print "not " if $first != $exp_first || $second != $exp_second;
40-
say "ok # nested pair $pair_num: got <$first,$second>, expected <$exp_first,$exp_second>";
36+
ok(!($first != $exp_first || $second != $exp_second), 'nested pair $pair_num: got <$first,$second>, expected <$exp_first,$exp_second>');
4137
$pair_num++;
4238
}
4339

@@ -53,8 +49,7 @@ my %expected_pairs = (
5349
key3 => 'val3'
5450
);
5551
for my ($key, $value) (%hash) {
56-
print "not " if !exists($expected_pairs{$key}) || $expected_pairs{$key} ne $value;
57-
say "ok # hash entry: got <$key,$value>, expected <$key,$expected_pairs{$key}>";
52+
ok(exists($expected_pairs{$key}) || $expected_pairs{$key} ne $value, 'hash entry: got <$key,$value>, expected <$key,$expected_pairs{$key}>');
5853
}
5954

6055
# Test with list of expressions
@@ -64,9 +59,10 @@ my $idx = 0;
6459
for my ($num, $square) (@squares) {
6560
my $exp_num = $nums[$idx];
6661
my $exp_square = $exp_num * $exp_num;
67-
print "not " if $num != $exp_num || $square != $exp_square;
68-
say "ok # number and square: got <$num,$square>, expected <$exp_num,$exp_square>";
62+
ok(!($num != $exp_num || $square != $exp_square), 'number and square: got <$num,$square>, expected <$exp_num,$exp_square>');
6963
$idx++;
7064
}
7165

7266
1;
67+
68+
done_testing();

0 commit comments

Comments
 (0)