New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
t/op/not.t: Misspecified tests; add descriptions to tests lacking them #12676
Comments
From @jkeenanSince the St Louis Perl Hackathon in November, I and others have been Consider tests 4 and 5 in t/op/not.t: ##### Currently, none of the tests in t/op/not.t have descriptions. Hence, ##### Now, suppose we add descriptions to all tests in this file. Here I ##### is(! 1, not 1, q{description 1}); The output I get is: ##### Where did the descriptions for tests 4 and 5 go? And why is test 5 now I posed this question on the St Louis and Toronto Perlmongers mailing Adapting a diagnostic suggested by Fulko Hew, let's set aside the ##### Let's first pass to this function the 3 arguments provided to is() ##### The output: ##### The high-precedence '!' operator binds to the number following it and Now let's add the string 'not ' to the second argument in each call: ##### This time, our overall output is: Here we're seeing the apparently anomalous results we saw when we tried 1. The high-precedence '!' operator is continuing to bind to the number 2. Each call, however, is only reporting two "arguments" -- and each In the discussion on the Perlmonger mailing lists, Uri Guttman observed ##### Since 'not' as a function is prototyped to expect a scalar argument, the If you adapt the diagnostic suggested by Fulko to use either This suggests that tests in 4 and 5 in t/op/not.t are not conducting a Hence, I propose we apply the two patches attached. The first merely Please review. Thank you very much. |
From @jkeenan0001-Add-parens-around-second-argument-to-tests-4-and-5.patchFrom 22adfd31e44fba1a05f3c8a238c1e6a94539996a Mon Sep 17 00:00:00 2001
From: James E Keenan <jkeenan@cpan.org>
Date: Sat, 29 Dec 2012 11:09:34 -0500
Subject: [PATCH 1/2] Add parens around second argument to tests 4 and 5.
If a description were to be added to these tests, in the absence of
parentheses the scalar prototype of CORE::not would enforce a scalar context
onto the balance of the statement, leading to apparently anomalous behavior,
viz., the descriptions would not be printed and test 5 would be reported to
FAIL.
---
t/op/not.t | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/t/op/not.t b/t/op/not.t
index 3d07797..aa3e192 100644
--- a/t/op/not.t
+++ b/t/op/not.t
@@ -14,8 +14,8 @@ is(not(), 1);
is(not(), not(0));
# test not(..) and !
-is(! 1, not 1);
-is(! 0, not 0);
+is(! 1, (not 1));
+is(! 0, (not 0));
is(! (0, 0), not(0, 0));
# test the return of !
--
1.6.3.2
|
From @jkeenan0002-t-op-not.t-Add-descriptions-to-all-tests.patchFrom 68b3dfb6c35650d77142c62c9aad62acea4c7b4c Mon Sep 17 00:00:00 2001
From: James E Keenan <jkeenan@cpan.org>
Date: Sat, 29 Dec 2012 11:23:56 -0500
Subject: [PATCH 2/2] t/op/not.t: Add descriptions to all tests.
Also, add note() before tests 4 and 5 explaining rationale for addition of
parentheses to second arguments.
---
t/op/not.t | 47 +++++++++++++++++++++++++++++++----------------
1 files changed, 31 insertions(+), 16 deletions(-)
diff --git a/t/op/not.t b/t/op/not.t
index aa3e192..4aae02c 100644
--- a/t/op/not.t
+++ b/t/op/not.t
@@ -9,14 +9,19 @@ BEGIN {
plan tests => 16;
# not() tests
-pass() if not();
-is(not(), 1);
-is(not(), not(0));
+pass("logical negation of empty list") if not();
+is(not(), 1, "logical negation of empty list in numeric comparison");
+is(not(), not(0),
+ "logical negation of empty list compared with logical negation of false value");
# test not(..) and !
-is(! 1, (not 1));
-is(! 0, (not 0));
-is(! (0, 0), not(0, 0));
+note("parens needed around second argument in next two tests\nto preserve list context inside function call");
+is(! 1, (not 1),
+ "high- and low-precedence logical negation of true value");
+is(! 0, (not 0),
+ "high- and low-precedence logical negation of false value");
+is(! (0, 0), not(0, 0),
+ "high- and low-precedence logical negation of lists");
# test the return of !
{
@@ -24,13 +29,18 @@ is(! (0, 0), not(0, 0));
my $not1 = ! 1;
no warnings;
- ok($not1 == undef);
- ok($not1 == ());
+ ok($not1 == undef,
+ "logical negation (high-precedence) of true value is numerically equal to undefined value");
+ ok($not1 == (),
+ "logical negation (high-precedence) of true value is numerically equal to empty list");
use warnings;
- ok($not1 eq '');
- ok($not1 == 0);
- ok($not0 == 1);
+ ok($not1 eq '',
+ "logical negation (high-precedence) of true value in string context is equal to empty string");
+ ok($not1 == 0,
+ "logical negation (high-precedence) of true value is false in numeric context");
+ ok($not0 == 1,
+ "logical negation (high-precedence) of false value is true in numeric context");
}
# test the return of not
@@ -39,11 +49,16 @@ is(! (0, 0), not(0, 0));
my $not1 = not 1;
no warnings;
- ok($not1 == undef);
- ok($not1 == ());
+ ok($not1 == undef,
+ "logical negation (low-precedence) of true value is numerically equal to undefined value");
+ ok($not1 == (),
+ "logical negation (low-precedence) of true value is numerically equal to empty list");
use warnings;
- ok($not1 eq '');
- ok($not1 == 0);
- ok($not0 == 1);
+ ok($not1 eq '',
+ "logical negation (low-precedence) of true value in string context is equal to empty string");
+ ok($not1 == 0,
+ "logical negation (low-precedence) of true value is false in numeric context");
+ ok($not0 == 1,
+ "logical negation (low-precedence) of false value is true in numeric context");
}
--
1.6.3.2
|
From @tonycozOn Sat Dec 29 08:29:43 2012, jkeen@verizon.net wrote:
That all makes sense to me. Tony |
The RT System itself - Status changed from 'new' to 'open' |
From @jkeenanOn Wed Jan 02 19:37:18 2013, tonyc wrote:
Thanks for your feedback. Applied to blead in these commits: commit 129da47 commit 877c9ac Resolving ticket. Thank you very much. |
@jkeenan - Status changed from 'open' to 'resolved' |
From @ap* James E Keenan <perlbug-followup@perl.org> [2012-12-29 17:35]:
Ugh. Whyever is the prototype `$;` rather than just `$`? The latter would do exactly what one would expect here: $ perl -E 'say not 0, "foo"' $ perl -E 'sub non ($) { !$_[0] } say non 0, "foo"' There must be hysterical raisins for this nonsense, I’m sure… it Regards, |
Migrated from rt.perl.org#116242 (status was 'resolved')
Searchable as RT116242$
The text was updated successfully, but these errors were encountered: