Mailing List Archive

1 2  View All
Re: Is it time for Test2 to go to core? [ In reply to ]
On Sat, 29 Apr 2023 at 16:57, Dagfinn Ilmari Mannsåker
<ilmari@ilmari.org> wrote:
>
> Leon Timmermans <fawaka@gmail.com> writes:
>
> > First of all, you really shouldn't be printing to STDOUT/STDERR in a test
> > anyway. The test framework owns the outputs, and it will actually take care
> > that the output is UTF-8. This problem doesn't exist if you use the tool
> > the way it's meant to be used.
>
> A concrete example:
>
> $ cat mojibake.t
> #!/usr/bin/env perl
>
> use strict;
> use warnings;
> use Test2::V0;
>
> pass("ok");
>
> diag "skjærgårdsøl";
> no utf8;
> diag "blåbærsyltetøy";
>
> done_testing();
>
> $ perl mojibake.t
> # Seeded srand with seed '20230429' from local date.

What produces that output? I checked the Test2 repo and I couldn't
find any code that emits that.

Unfortunately one can't set srand() explicitly without breaking rand()
under fork(). In 5.37.3 we added support for a PERL_RAND_SEED env var
that does things "right" (deterministic but each fork gets its own
seed).

Yves
--
perl -Mre=debug -e "/just|another|perl|hacker/"
Re: Is it time for Test2 to go to core? [ In reply to ]
On Wed, 3 May 2023 at 09:35, demerphq <demerphq@gmail.com> wrote:
>
> On Sat, 29 Apr 2023 at 16:57, Dagfinn Ilmari Mannsåker
> <ilmari@ilmari.org> wrote:
> >
> > Leon Timmermans <fawaka@gmail.com> writes:
> >
> > > First of all, you really shouldn't be printing to STDOUT/STDERR in a test
> > > anyway. The test framework owns the outputs, and it will actually take care
> > > that the output is UTF-8. This problem doesn't exist if you use the tool
> > > the way it's meant to be used.
> >
> > A concrete example:
> >
> > $ cat mojibake.t
> > #!/usr/bin/env perl
> >
> > use strict;
> > use warnings;
> > use Test2::V0;
> >
> > pass("ok");
> >
> > diag "skjærgårdsøl";
> > no utf8;
> > diag "blåbærsyltetøy";
> >
> > done_testing();
> >
> > $ perl mojibake.t
> > # Seeded srand with seed '20230429' from local date.
>
> What produces that output? I checked the Test2 repo and I couldn't
> find any code that emits that.
>
> Unfortunately one can't set srand() explicitly without breaking rand()
> under fork(). In 5.37.3 we added support for a PERL_RAND_SEED env var
> that does things "right" (deterministic but each fork gets its own
> seed).

Notice that this gives each process its own independent seed

$ PERL_RAND_SEED=1234 ./perl -le'fork; print "$$:", rand();'
272516:0.740876929442496
272517:0.842944087068648

and this does not:

$ ./perl -le'srand(1234); fork; print "$$:", rand();'
272534:0.740876929442496
272535:0.740876929442496

In hindsight I probably should have made it possible to set the
PERL_RAND_SEED without using an env var. No reason we couldn't have
${^RAND_SEED} be set from $ENV{PERL_RAND_SEED} in the environment and
then use it instead.

cheers,
yves

--
perl -Mre=debug -e "/just|another|perl|hacker/"
Re: Is it time for Test2 to go to core? [ In reply to ]
demerphq <demerphq@gmail.com> writes:

> On Sat, 29 Apr 2023 at 16:57, Dagfinn Ilmari Mannsåker
> <ilmari@ilmari.org> wrote:
>>
>> Leon Timmermans <fawaka@gmail.com> writes:
>>
>> > First of all, you really shouldn't be printing to STDOUT/STDERR in a test
>> > anyway. The test framework owns the outputs, and it will actually take care
>> > that the output is UTF-8. This problem doesn't exist if you use the tool
>> > the way it's meant to be used.
>>
>> A concrete example:
>>
>> $ cat mojibake.t
>> #!/usr/bin/env perl
>>
>> use strict;
>> use warnings;
>> use Test2::V0;
>>
>> pass("ok");
>>
>> diag "skjærgårdsøl";
>> no utf8;
>> diag "blåbærsyltetøy";
>>
>> done_testing();
>>
>> $ perl mojibake.t
>> # Seeded srand with seed '20230429' from local date.
>
> What produces that output? I checked the Test2 repo and I couldn't
> find any code that emits that.

That comes from Test2::Plugin::SRand¹, which is part of Test2-Suite dist
and is loaded by Test2::V0²;

[1] https://metacpan.org/dist/Test2-Suite/source/lib/Test2/Plugin/SRand.pm#L64
[2] https://metacpan.org/pod/Test2::V0#SRAND

> Unfortunately one can't set srand() explicitly without breaking rand()
> under fork(). In 5.37.3 we added support for a PERL_RAND_SEED env var
> that does things "right" (deterministic but each fork gets its own
> seed).

Please file a bug against the above plugin if it gets fixing for this.

> Yves

- ilmari
Re: Is it time for Test2 to go to core? [ In reply to ]
Dagfinn Ilmari Mannsåker <ilmari@ilmari.org> writes:

> That comes from Test2::Plugin::SRand¹, which is part of Test2-Suite dist
> and is loaded by Test2::V0²;
>
> [1] https://metacpan.org/dist/Test2-Suite/source/lib/Test2/Plugin/SRand.pm#L64
> [2] https://metacpan.org/pod/Test2::V0#SRAND
>
>> Unfortunately one can't set srand() explicitly without breaking rand()
>> under fork(). In 5.37.3 we added support for a PERL_RAND_SEED env var
>> that does things "right" (deterministic but each fork gets its own
>> seed).
>
> Please file a bug against the above plugin if it gets fixing for this.

"needs fixing", even.

>> Yves
>
> - ilmari

- ilmari
Re: Is it time for Test2 to go to core? [ In reply to ]
On Wed, 3 May 2023 at 11:32, Dagfinn Ilmari Mannsåker <ilmari@ilmari.org> wrote:
>
> demerphq <demerphq@gmail.com> writes:
>
> > On Sat, 29 Apr 2023 at 16:57, Dagfinn Ilmari Mannsåker
> > <ilmari@ilmari.org> wrote:
> >>
> >> Leon Timmermans <fawaka@gmail.com> writes:
> >>
> >> > First of all, you really shouldn't be printing to STDOUT/STDERR in a test
> >> > anyway. The test framework owns the outputs, and it will actually take care
> >> > that the output is UTF-8. This problem doesn't exist if you use the tool
> >> > the way it's meant to be used.
> >>
> >> A concrete example:
> >>
> >> $ cat mojibake.t
> >> #!/usr/bin/env perl
> >>
> >> use strict;
> >> use warnings;
> >> use Test2::V0;
> >>
> >> pass("ok");
> >>
> >> diag "skjærgårdsøl";
> >> no utf8;
> >> diag "blåbærsyltetøy";
> >>
> >> done_testing();
> >>
> >> $ perl mojibake.t
> >> # Seeded srand with seed '20230429' from local date.
> >
> > What produces that output? I checked the Test2 repo and I couldn't
> > find any code that emits that.
>
> That comes from Test2::Plugin::SRand¹, which is part of Test2-Suite dist
> and is loaded by Test2::V0²;
>
> [1] https://metacpan.org/dist/Test2-Suite/source/lib/Test2/Plugin/SRand.pm#L64
> [2] https://metacpan.org/pod/Test2::V0#SRAND
>
> > Unfortunately one can't set srand() explicitly without breaking rand()
> > under fork(). In 5.37.3 we added support for a PERL_RAND_SEED env var
> > that does things "right" (deterministic but each fork gets its own
> > seed).
>
> Please file a bug against the above plugin if it gets fixing for this.

https://github.com/Test-More/Test2-Suite/issues/269

Yves


--
perl -Mre=debug -e "/just|another|perl|hacker/"

1 2  View All