Re: Writing our own modules in Test2
[email protected] (Lasse Makholm) Thu, 30 Jun 2016 10:57:29 +0200
| Newsgroups | perl.qa |
|---|---|
| Message-ID | <CAGDbts=M5vWJ8yi68JAkWHbWfhMVXr9Lw6+_FH5Bin7oTaNH7g@mail.gmail.com> |
--001a114768f656147505367b0fbf Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Mon, Jun 27, 2016 at 4:34 PM, Andy Lester <[email protected]> wrote: > > On Jun 24, 2016, at 4:41 PM, Buddy Burden <[email protected]> wrote= : > > is_true($val); > is_false($val); > > Because with just `ok($val)` you can tell whether it's true or false, but= , > when it inevitably fails, you really want to know what the bad value turn= ed > out to be. > > > I have a bool_eq() so you can do this: > > bool_eq( $want_foos, scalar @foos ); > > without having to do > > if ( $want_foos ) { > ok( scalar @foos ); > } > else { > is( scalar @foos, 0 ); > } > > We were also writing that as > > is( !!$want_foos, !!(scalar @foos) ); > > which works, but obscures the meaning. > > I don=E2=80=99t like the name bool_eq() (=E2=80=9Cbooleans are equal=E2= =80=9D) but it was the best > I could come up with. > bool_not_xor_ok() ? :-D Kidding aside, I would argue that using a conditional is actually the more readable option in this particular case, though I'd probably compress it down to: $want_foos ? ok(scalar @foos, 'got some foos') : is(scalar @foos, 0, 'got no foos'); I find that minimizing the logic inside the argument list makes my tests more readable... That doesn't negate the need for a bool_eq() though... How about is_truth($got_bool, $expected_bool) ? That seems to line up nicely with is_true() and is_false()... /L > > -- > Andy Lester =3D> www.petdance.com > > --001a114768f656147505367b0fbf Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><br><div class=3D"gmail_extra"><br><div class=3D"gmail_quo= te">On Mon, Jun 27, 2016 at 4:34 PM, Andy Lester <span dir=3D"ltr"><<a h= ref=3D"mailto:[email protected]" target=3D"_blank">[email protected]</a>>= ;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0px 0p= x 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color= :rgb(204,204,204);padding-left:1ex"><div style=3D"word-wrap:break-word"><sp= an class=3D""><br><div><blockquote type=3D"cite"><div>On Jun 24, 2016, at 4= :41 PM, Buddy Burden <<a href=3D"mailto:[email protected]" target= =3D"_blank">[email protected]</a>> wrote:</div><br><div><span styl= e=3D"font-family:Georgia;font-size:14px;font-style:normal;font-variant:norm= al;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:s= tart;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0p= x;float:none;display:inline!important">=C2=A0=C2=A0=C2=A0is_true($val);</sp= an><br style=3D"font-family:Georgia;font-size:14px;font-style:normal;font-v= ariant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;t= ext-align:start;text-indent:0px;text-transform:none;white-space:normal;word= -spacing:0px"><span style=3D"font-family:Georgia;font-size:14px;font-style:= normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-he= ight:normal;text-align:start;text-indent:0px;text-transform:none;white-spac= e:normal;word-spacing:0px;float:none;display:inline!important">=C2=A0=C2=A0= =C2=A0is_false($val);</span><br style=3D"font-family:Georgia;font-size:14px= ;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:no= rmal;line-height:normal;text-align:start;text-indent:0px;text-transform:non= e;white-space:normal;word-spacing:0px"><br style=3D"font-family:Georgia;fon= t-size:14px;font-style:normal;font-variant:normal;font-weight:normal;letter= -spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-tr= ansform:none;white-space:normal;word-spacing:0px"><span style=3D"font-famil= y:Georgia;font-size:14px;font-style:normal;font-variant:normal;font-weight:= normal;letter-spacing:normal;line-height:normal;text-align:start;text-inden= t:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;di= splay:inline!important">Because with just `ok($val)` you can tell whether i= t's true or false, but, when it inevitably fails, you really want to kn= ow what the bad value turned out to be.</span></div></blockquote></div><div= ><br></div></span><div>I have a bool_eq() so you can do this:</div><div><br= ></div><div>bool_eq( $want_foos, scalar @foos );</div><div><br></div><div>w= ithout having to do</div><div><br></div><div>if ( $want_foos ) {</div><div>= =C2=A0 =C2=A0 ok( scalar @foos );</div><div>}</div><div>else {</div><div>= =C2=A0 =C2=A0 is( scalar @foos, 0 );</div><div>}</div><div><br></div><div>W= e were also writing that as</div><div><br></div><div>is( !!$want_foos, !!(s= calar @foos) );</div><div><br></div><div>which works, but obscures the mean= ing.</div><div><br></div><div>I don=E2=80=99t like the name bool_eq() (=E2= =80=9Cbooleans are equal=E2=80=9D) but it was the best I could come up with= .</div></div></blockquote><div><br></div><div>bool_not_xor_ok() ? :-D</div>= <div><br></div><div>Kidding aside, I would argue that using a conditional i= s actually the more readable option in this particular case, though I'd= probably compress it down to:</div><div><br></div><div>$want_foos</div><di= v>=C2=A0 =C2=A0 ? ok(scalar @foos, 'got some foos')<br></div><div>= =C2=A0 =C2=A0 : =C2=A0is(scalar @foos, 0, 'got no foos');</div><div= ><br></div><div>I find that minimizing the logic inside the argument list m= akes my tests more readable...</div><div><br></div><div>That doesn't ne= gate the need for a bool_eq() though...</div><div><br></div><div>How about = is_truth($got_bool, $expected_bool) ?</div><div><br></div><div>That seems t= o line up nicely with is_true() and is_false()...</div><div><br></div><div>= /L</div><div>=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"margin:= 0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left= -color:rgb(204,204,204);padding-left:1ex"><div style=3D"word-wrap:break-wor= d"><span class=3D""><br><div> --<br>Andy Lester =3D>=C2=A0<a href=3D"http://www.petdance.com" target= =3D"_blank">www.petdance.com</a> </div> <br></span></div></blockquote></div><br></div></div> --001a114768f656147505367b0fbf--