diff options
author | Paul "LeoNerd" Evans <leonerd@leonerd.org.uk> | 2023-02-13 11:59:09 +0000 |
---|---|---|
committer | Paul Evans <leonerd@leonerd.org.uk> | 2023-02-13 17:41:49 +0000 |
commit | 3249496afe65ad71b051caad311d33c4fdd43d8d (patch) | |
tree | d5a2c4401b61dd0ec7a7cdd3eecf0f23735b5cd7 | |
parent | e98863010dd41bde8cde1ac333d1a53d3d1c282e (diff) | |
download | perl-3249496afe65ad71b051caad311d33c4fdd43d8d.tar.gz |
Unit-test classes and instances with threads
-rw-r--r-- | MANIFEST | 1 | ||||
-rw-r--r-- | t/class/threads.t | 47 |
2 files changed, 48 insertions, 0 deletions
@@ -5648,6 +5648,7 @@ t/class/field.t See if class field declarations work t/class/inherit.t See if class inheritance works t/class/method.t See if class method declarations work t/class/phasers.t See if class phaser blocks work +t/class/threads.t See if classes work across multiple threads t/cmd/elsif.t See if else-if works t/cmd/for.t See if for loops work t/cmd/mod.t See if statement modifiers work diff --git a/t/class/threads.t b/t/class/threads.t new file mode 100644 index 0000000000..4bd9fa444d --- /dev/null +++ b/t/class/threads.t @@ -0,0 +1,47 @@ +#!./perl + +BEGIN { + chdir 't' if -d 't'; + require './test.pl'; + set_up_inc('../lib'); + require Config; + + skip_all_without_config('useithreads'); + skip_all_if_miniperl("no dynamic loading on miniperl, no threads"); +} + +use v5.36; +use feature 'class'; +no warnings 'experimental::class'; + +use threads; + +class Test1 { + field $x :param; + method x { return $x } +} + +{ + my $ret = threads->create(sub { + pass("Created dummy thread"); + return 1; + })->join; + next_test(); # account for pass() inside thread + is($ret, 1, "Returned from dummy thread"); +} + +{ + my $obj = Test1->new(x => 10); + threads->create(sub { + is($obj->x, 10, '$obj->x inside thread created before'); + })->join; + next_test(); # account for is() inside thread +} + +threads->create(sub { + my $obj = Test1->new(x => 20); + is($obj->x, 20, '$obj->x created inside thread'); +})->join; +next_test(); # account for is() inside thread + +done_testing; |