From ed904704a71a5ea0d13745c6a1aa7483d7419296 Mon Sep 17 00:00:00 2001 From: "Paul \"LeoNerd\" Evans" Date: Mon, 9 Aug 2021 23:54:14 +0100 Subject: [PATCH] Add a unit test that checks we didn't break booleans with the new COW static const behaviour --- MANIFEST | 1 + t/op/bool.t | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 t/op/bool.t diff --git a/MANIFEST b/MANIFEST index bf099a95bbde..663ec3885287 100644 --- a/MANIFEST +++ b/MANIFEST @@ -5830,6 +5830,7 @@ t/op/auto.t See if autoincrement et all work t/op/avhv.t See if pseudo-hashes work t/op/bless.t See if bless works t/op/blocks.t See if BEGIN and friends work +t/op/bool.t Check misc details of boolean values t/op/bop.t See if bitops work t/op/caller.pl Tests shared between caller.t and XS op.t t/op/caller.t See if caller() works diff --git a/t/op/bool.t b/t/op/bool.t new file mode 100644 index 000000000000..21f6d3b7d544 --- /dev/null +++ b/t/op/bool.t @@ -0,0 +1,37 @@ +#!./perl + +BEGIN { + chdir 't' if -d 't'; + require './test.pl'; + set_up_inc('../lib'); +} + +use strict; +use warnings; + +my $truevar = (5 == 5); +my $falsevar = (5 == 6); + +cmp_ok($truevar, '==', 1); +cmp_ok($truevar, 'eq', "1"); + +cmp_ok($falsevar, '==', 0); +cmp_ok($falsevar, 'eq', ""); + +{ + # Check that boolean COW string buffer is safe to copy into new SVs and + # doesn't get corrupted by inplace mutations + my $x = $truevar; + $x =~ s/1/t/; + + cmp_ok($x, 'eq', "t"); + cmp_ok($truevar, 'eq', "1"); + + my $y = $truevar; + substr($y, 0, 1, "T"); + + cmp_ok($y, 'eq', "T"); + cmp_ok($truevar, 'eq', "1"); +} + +done_testing();