xref: /openbsd/gnu/usr.bin/perl/t/lib/subs/subs (revision f2a19305)
1__END__
2
3# Error - not predeclaring a sub
4Fred 1,2 ;
5sub Fred {}
6EXPECT
7Number found where operator expected (Do you need to predeclare "Fred"?) at - line 3, near "Fred 1"
8syntax error at - line 3, near "Fred 1"
9Execution of - aborted due to compilation errors.
10########
11
12# Error - not predeclaring a sub in time
13Fred 1,2 ;
14use subs qw( Fred ) ;
15sub Fred {}
16EXPECT
17Number found where operator expected (Do you need to predeclare "Fred"?) at - line 3, near "Fred 1"
18syntax error at - line 3, near "Fred 1"
19Execution of - aborted due to compilation errors.
20########
21
22# AOK
23use subs qw( Fred) ;
24Fred 1,2 ;
25sub Fred { print $_[0] + $_[1], "\n" }
26EXPECT
273
28########
29
30# override a built-in function
31use subs qw( open ) ;
32open 1,2 ;
33sub open { print $_[0] + $_[1], "\n" }
34EXPECT
353
36########
37
38# override a built-in function, call after definition
39use subs qw( open ) ;
40sub open { print $_[0] + $_[1], "\n" }
41open 1,2 ;
42EXPECT
433
44########
45
46# override a built-in function, call with ()
47use subs qw( open ) ;
48open (1,2) ;
49sub open { print $_[0] + $_[1], "\n" }
50EXPECT
513
52########
53
54# override a built-in function, call with () after definition
55use subs qw( open ) ;
56sub open { print $_[0] + $_[1], "\n" }
57open (1,2) ;
58EXPECT
593
60########
61
62--FILE-- abc
63Fred 1,2 ;
641;
65--FILE--
66use subs qw( Fred ) ;
67require "./abc" ;
68sub Fred { print $_[0] + $_[1], "\n" }
69EXPECT
703
71########
72
73# check that it isn't affected by block scope
74{
75    use subs qw( Fred ) ;
76}
77Fred 1, 2;
78sub Fred { print $_[0] + $_[1], "\n" }
79EXPECT
803
81########
82
83# Error - not predeclaring a sub
84use utf8;
85use open qw( :utf8 :std );
86Frèd 1,2 ;
87sub Frèd {}
88EXPECT
89Number found where operator expected (Do you need to predeclare "Frèd"?) at - line 5, near "Frèd 1"
90syntax error at - line 5, near "Frèd 1"
91Execution of - aborted due to compilation errors.
92########
93
94# Error - not predeclaring a sub in time
95use utf8;
96use open qw( :utf8 :std );
97ふれど 1,2 ;
98use subs qw( ふれど ) ;
99sub ふれど {}
100EXPECT
101Number found where operator expected (Do you need to predeclare "ふれど"?) at - line 5, near "ふれど 1"
102syntax error at - line 5, near "ふれど 1"
103Execution of - aborted due to compilation errors.
104