summaryrefslogtreecommitdiff
path: root/t/op/filetest_t.t
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2012-01-23 23:36:29 -0800
committerFather Chrysostomos <sprout@cpan.org>2012-01-23 23:39:39 -0800
commit8db8f6b697e6f705eda3222828417099787adba4 (patch)
tree9443248f2134133a9a1adda030fdab3a70a96054 /t/op/filetest_t.t
parent7e68c38b607a044ee5879e316bb8a7347284ec8e (diff)
downloadperl-8db8f6b697e6f705eda3222828417099787adba4.tar.gz
[perl #77388] Make stacked -t work
Up till now, -t was popping too much off the stack when stacked with other filetest operators. Since the special use of _ doesn’t apply to -t, we cannot simply have it use _ when stacked, but instead we pass the argument down from the previous op. To facilitate this, the whole stacked mechanism has to change. As before, in an expression like -r -w -x, -x and -w are flagged as ‘stacking’ ops (followed by another filetest), and -w and -r are flagged as stacked (preceded by another filetest). Stacking filetest ops no longer return a false value to the next op when a test fails, and stacked ops no longer check the truth of the value on the stack to determine whether to return early (if it’s false). The argument to the first filetest is now passed from one op to another. This is similar to the mechanism that overloaded objects were already using. Now it applies to any argument. Since it could be false, we cannot rely on the boolean value of the stack item. So, stacking ops, when they return false, now traverse the ->op_next pointers and find the op after the last stacked op. That op is returned to the runloop. This short-circuiting is proba- bly faster than calling every subsequent op (a separate function call for each). Filetest ops other than -t continue to use the last stat buffer when stacked, so the argument on the stack is ignored. But if the op is preceded by nothing other than -t (where preceded means on the right, since the ops are evaluated right-to-left), it *does* use the argument on the stack, since -t has not set the last stat buffer. The new OPpFT_AFTER_t flag indicates that a stacked op is preceded by nothing other than -t. In ‘-e -t foo’, the -e gets the flag, but not in ‘-e -t -r foo’, because -r will have saved the stat buffer, so -e can just use that.
Diffstat (limited to 't/op/filetest_t.t')
-rw-r--r--t/op/filetest_t.t9
1 files changed, 8 insertions, 1 deletions
diff --git a/t/op/filetest_t.t b/t/op/filetest_t.t
index 350856411d..cd552a748d 100644
--- a/t/op/filetest_t.t
+++ b/t/op/filetest_t.t
@@ -8,7 +8,7 @@ BEGIN {
use strict;
-plan 2;
+plan 7;
my($dev_tty, $dev_null) = qw(/dev/tty /dev/null);
($dev_tty, $dev_null) = qw(con nul ) if $^O =~ /^(MSWin32|os2)$/;
@@ -23,9 +23,16 @@ SKIP: {
skip("'$tt_dev' is probably not a terminal") if $tt_dev !~ m/^_(tt|ft|rt)/i;
}
ok(-t $tty, "'$dev_tty' is a TTY");
+ ok(-t -e $tty, "'$dev_tty' is a TTY (with -t -e)");
+ -e 'mehyparchonarcheion'; # clear last stat buffer
+ ok(-e -t $tty, "'$dev_tty' is a TTY (with -e -t)");
+ -e 'mehyparchonarcheion';
+ ok(-e -t -t $tty, "'$dev_tty' is a TTY (with -e -t -t)");
}
SKIP: {
open(my $null, "<", $dev_null)
or skip("Can't open null device '$dev_null': $!");
ok(!-t $null, "'$dev_null' is not a TTY");
+ ok(!-t -e $null, "'$dev_null' is not a TTY (with -t -e)");
+ ok(!-e -t $null, "'$dev_null' is not a TTY (with -e -t)");
}