Re: Writing our own modules in Test2
[email protected] (Andy Lester) Mon, 27 Jun 2016 09:34:57 -0500
| Newsgroups | perl.qa |
|---|---|
| Message-ID | <[email protected]> |
--Apple-Mail=_0FF72905-D909-4775-AC5B-74453741E890 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=windows-1252 > On Jun 24, 2016, at 4:41 PM, Buddy Burden <[email protected]> = wrote: >=20 > is_true($val); > is_false($val); >=20 > 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 turned 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=92t like the name bool_eq() (=93booleans are equal=94) but it was = the best I could come up with. -- Andy Lester =3D> www.petdance.com --Apple-Mail=_0FF72905-D909-4775-AC5B-74453741E890 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=windows-1252 <html><head><meta http-equiv=3D"Content-Type" content=3D"text/html = charset=3Dwindows-1252"></head><body style=3D"word-wrap: break-word; = -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" = class=3D""><br class=3D""><div><blockquote type=3D"cite" class=3D""><div = class=3D"">On Jun 24, 2016, at 4:41 PM, Buddy Burden <<a = href=3D"mailto:[email protected]" = class=3D"">[email protected]</a>> wrote:</div><br = class=3D"Apple-interchange-newline"><div class=3D""><span = style=3D"font-family: Georgia; font-size: 14px; font-style: normal; = font-variant: normal; font-weight: normal; letter-spacing: normal; = line-height: normal; orphans: auto; text-align: start; text-indent: 0px; = text-transform: none; white-space: normal; widows: auto; word-spacing: = 0px; -webkit-text-stroke-width: 0px; float: none; display: inline = !important;" class=3D""> is_true($val);</span><br = style=3D"font-family: Georgia; font-size: 14px; font-style: normal; = font-variant: normal; font-weight: normal; letter-spacing: normal; = line-height: normal; orphans: auto; text-align: start; text-indent: 0px; = text-transform: none; white-space: normal; widows: auto; word-spacing: = 0px; -webkit-text-stroke-width: 0px;" class=3D""><span = style=3D"font-family: Georgia; font-size: 14px; font-style: normal; = font-variant: normal; font-weight: normal; letter-spacing: normal; = line-height: normal; orphans: auto; text-align: start; text-indent: 0px; = text-transform: none; white-space: normal; widows: auto; word-spacing: = 0px; -webkit-text-stroke-width: 0px; float: none; display: inline = !important;" class=3D""> is_false($val);</span><br = style=3D"font-family: Georgia; font-size: 14px; font-style: normal; = font-variant: normal; font-weight: normal; letter-spacing: normal; = line-height: normal; orphans: auto; text-align: start; text-indent: 0px; = text-transform: none; white-space: normal; widows: auto; word-spacing: = 0px; -webkit-text-stroke-width: 0px;" class=3D""><br style=3D"font-family:= Georgia; font-size: 14px; font-style: normal; font-variant: normal; = font-weight: normal; letter-spacing: normal; line-height: normal; = orphans: auto; text-align: start; text-indent: 0px; text-transform: = none; white-space: normal; widows: auto; word-spacing: 0px; = -webkit-text-stroke-width: 0px;" class=3D""><span style=3D"font-family: = Georgia; font-size: 14px; font-style: normal; font-variant: normal; = font-weight: normal; letter-spacing: normal; line-height: normal; = orphans: auto; text-align: start; text-indent: 0px; text-transform: = none; white-space: normal; widows: auto; word-spacing: 0px; = -webkit-text-stroke-width: 0px; float: none; display: inline = !important;" class=3D"">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 turned out to = be.</span></div></blockquote></div><div class=3D""><br = class=3D""></div><div class=3D"">I have a bool_eq() so you can do = this:</div><div class=3D""><br class=3D""></div><div class=3D"">bool_eq( = $want_foos, scalar @foos );</div><div class=3D""><br class=3D""></div><div= class=3D"">without having to do</div><div class=3D""><br = class=3D""></div><div class=3D"">if ( $want_foos ) {</div><div = class=3D""> ok( scalar @foos );</div><div = class=3D"">}</div><div class=3D"">else {</div><div class=3D""> = is( scalar @foos, 0 );</div><div class=3D"">}</div><div = class=3D""><br class=3D""></div><div class=3D"">We were also writing = that as</div><div class=3D""><br class=3D""></div><div class=3D"">is( = !!$want_foos, !!(scalar @foos) );</div><div class=3D""><br = class=3D""></div><div class=3D"">which works, but obscures the = meaning.</div><div class=3D""><br class=3D""></div><div class=3D"">I = don=92t like the name bool_eq() (=93booleans are equal=94) but it was = the best I could come up with.</div><br class=3D""><div = apple-content-edited=3D"true" class=3D""> --<br class=3D"">Andy Lester =3D> <a = href=3D"http://www.petdance.com" class=3D"">www.petdance.com</a> </div> <br class=3D""></body></html>= --Apple-Mail=_0FF72905-D909-4775-AC5B-74453741E890--