This channel is intended for people just starting with the Raku Programming Language ( Logs are available at
Set by lizmat on 8 June 2022.
01:10 Kaipei joined 01:12 Kaiepi left 01:59 deadmarshal left 02:25 deadmarshal joined 10:48 frost joined 12:05 Guest86 joined 12:10 frost left 12:55 Guest86 left 14:00 discord-raku-bot left 14:01 discord-raku-bot joined 14:03 discord-raku-bot left, discord-raku-bot joined 14:41 discord-raku-bot left, discord-raku-bot joined 15:59 discord-raku-bot left, discord-raku-bot joined 19:16 deoac joined
deoac How can I use regexs when calling Test subroutines? 19:17
use Test;
throws-like({ say 42[2] }, X::OutOfRange, message => /Index out of range .*/);
gives this result
    not ok 3 - .message matches /Index out of range .*/ 19:18
not ok 1 - did we throws-like X::OutOfRange?
    # Failed test '.message matches /Index out of range .*/'
    # at SETTING::src/core.c/Any-iterable-methods.pm6 line 563
    # Expected: /Index out of range .*/
    # Got: Index out of range. Is: 2, should be in 0..0
    # You failed 1 test of 3
19:18 deoac left, deoac joined
lizmat m: CATCH { dd .^name }; 42[2] 19:33
camelia ( no output )
lizmat m: CATCH { dd .^name }; say 42[2]
camelia "X::OutOfRange"
Index out of range. Is: 2, should be in 0..0
in block <unit> at <tmp> line 1
CIAvash deoac: spaces are not significant: `/'Index out of range' .*/`
use quotes 19:34
19:42 deoac2 joined 19:44 deoac2 left, deoac17 joined 19:45 deoac17 left
deoac How do I specify the :message() parameter so that 19:48
the #Expected: and #Got: match?
I tried assigning a regex to :message(), but the Test module treats it like a literal string. 19:49
        # Expected: /Index out of range .*/
        # Got: Index out of range. Is: 2, should be in 0..0
CIAvash use... (full message at 19:57
Nemokosch what could it be? 👀 20:07
oh makes sense
the thing to remember is that regex literals aren't sensitive to whitespace 20:09
if you want to match literal strings, it's generally a good idea to quote them inside the regex
even if they aren't special characters or there is no whitespace involved imo
but here, whitespace involved: go for the quoting
deoac Ahh, got it.  Thanks 20:12
21:45 avuserow left
deoac         use Test; 22:15
        sub foo { print ' bar '; };
l.       ives-ok {foo}, 'foo() runs correctly';
         is foo(), 'bar ';
         ->bar<- ok 1 - foo() runs correctly
         ->bar<- not ok 2 -
         # Failed test at scratch.raku line 7
         # expected: 'bar'
         # got: 'True'
How can I test that foo() printed correctly?
guifa You can set $*OUT to something else, and capture the printed output 22:21
22:53 deoac left 22:55 deoac joined