This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perlfunc: re-document old split() @_ side effect
[perl5.git] / lib / locale_threads.t
1 use strict;
2 use warnings;
3
4 # This file tests interactions with locale and threads
5
6 BEGIN {
7     chdir 't' if -d 't';
8     require './test.pl';
9     set_up_inc('../lib');
10     require './loc_tools.pl';
11     skip_all("No locales") unless locales_enabled();
12     skip_all_without_config('useithreads');
13     $| = 1;
14 }
15
16 SKIP: { # perl #127708
17     my @locales = grep { $_ !~ / ^ C \b | POSIX /x } find_locales('LC_MESSAGES',
18                                                         'non-problematic-only');
19     skip("No valid locale to test with", 1) unless @locales;
20
21     # reset the locale environment
22     local @ENV{'LANG', (grep /^LC_/, keys %ENV)};
23     local $ENV{LC_MESSAGES} = $locales[0];
24
25     # We're going to try with all possible error numbers on this platform
26     my $error_count = keys(%!) + 1;
27
28     print fresh_perl("
29         use threads;
30         use strict;
31         use warnings;
32
33         my \$errnum = 1;
34
35         my \@threads = map +threads->create(sub {
36             sleep 0.1;
37
38             for (1..5_000) {
39                 \$errnum = (\$errnum + 1) % $error_count;
40                 \$! = \$errnum;
41
42                 # no-op to trigger stringification
43                 next if \"\$!\" eq \"\";
44             }
45         }), (0..1);
46         \$_->join for splice \@threads;",
47     {}
48     );
49
50     pass("Didn't segfault");
51 }
52
53 done_testing;