This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
ref.t: To-do test for retvals of folded ops
[perl5.git] / t / comp / fold.t
index 69d1903..f6a9470 100644 (file)
@@ -4,7 +4,7 @@
 # we've not yet verified that use works.
 # use strict;
 
-print "1..23\n";
+print "1..27\n";
 my $test = 0;
 
 # Historically constant folding was performed by evaluating the ops, and if
@@ -132,3 +132,29 @@ package other { # hide the "ok" sub
  print " ", ++$test, " - print followed by const || URSINE\n";
  BEGIN { $^W = 1 }
 }
+
+# or stat
+print "not " unless stat(1 ? INSTALL : 0) eq stat("INSTALL");
+print "ok ", ++$test, " - stat(const ? word : ....)\n";
+# in case we are in t/
+print "not " unless stat(1 ? TEST : 0) eq stat("TEST");
+print "ok ", ++$test, " - stat(const ? word : ....)\n";
+
+# or truncate
+my $n = "for_fold_dot_t$$";
+open F, ">$n" or die "open: $!";
+print F "bralh blah blah \n";
+close F or die "close $!";
+eval "truncate 1 ? $n : 0, 0;";
+print "not " unless -z $n;
+print "ok ", ++$test, " - truncate(const ? word : ...)\n";
+unlink $n;
+
+# Constant folding should not change the mutability of returned values.
+for(1+2) {
+    eval { $_++ };
+    print "not " unless $_ eq 4;
+    print "ok ", ++$test,
+          " - 1+2 returns mutable value, just like \$a+\$b",
+          " # TODO\n";
+}