This channel is intended for people just starting with the Raku Programming Language (raku.org). Logs are available at irclogs.raku.org/raku-beginner/live.html
Set by lizmat on 8 June 2022.
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
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
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 libera.ems.host/_matrix/media/r0/d...cb8f64612) 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
deoac         use Test; 22:15
        sub foo { print ' bar '; };
l.       ives-ok {foo}, 'foo() runs correctly';
         is foo(), 'bar ';
Outputs:
         ->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