Repository: lucy-clownfish Updated Branches: refs/heads/master cb85921ee -> 500912e2a
Demonstration of CLOWNFISH-44 This test demonstrates how immutable strings can be changed in Perl callbacks. Skip the test for now. Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/500912e2 Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/500912e2 Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/500912e2 Branch: refs/heads/master Commit: 500912e2a5046da2ace37cbb0340eac95b988bad Parents: cb85921 Author: Nick Wellnhofer <[email protected]> Authored: Sat May 16 18:57:33 2015 +0200 Committer: Nick Wellnhofer <[email protected]> Committed: Sat May 16 19:02:44 2015 +0200 ---------------------------------------------------------------------- runtime/core/Clownfish/Test/TestString.c | 8 ++++++++ runtime/core/Clownfish/Test/TestString.cfh | 7 +++++++ runtime/perl/t/binding/029-charbuf.t | 27 ++++++++++++++++++++++++- 3 files changed, 41 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/500912e2/runtime/core/Clownfish/Test/TestString.c ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Test/TestString.c b/runtime/core/Clownfish/Test/TestString.c index cbe0db2..f35bc8a 100644 --- a/runtime/core/Clownfish/Test/TestString.c +++ b/runtime/core/Clownfish/Test/TestString.c @@ -710,4 +710,12 @@ TestStr_Run_IMP(TestString *self, TestBatchRunner *runner) { test_iterator_substring(runner); } +/*************************** StringCallbackTest ***************************/ + +bool +StrCbTest_Unchanged_By_Callback_IMP(StringCallbackTest *self, String *str) { + String *before = Str_Clone(str); + StrCbTest_Callback(self); + return Str_Equals(str, (Obj*)before); +} http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/500912e2/runtime/core/Clownfish/Test/TestString.cfh ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Test/TestString.cfh b/runtime/core/Clownfish/Test/TestString.cfh index 479df19..88e43c9 100644 --- a/runtime/core/Clownfish/Test/TestString.cfh +++ b/runtime/core/Clownfish/Test/TestString.cfh @@ -26,4 +26,11 @@ class Clownfish::Test::TestString nickname TestStr Run(TestString *self, TestBatchRunner *runner); } +abstract class Clownfish::Test::StringCallbackTest nickname StrCbTest { + bool + Unchanged_By_Callback(StringCallbackTest *self, String *str); + + abstract void + Callback(StringCallbackTest *self); +} http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/500912e2/runtime/perl/t/binding/029-charbuf.t ---------------------------------------------------------------------- diff --git a/runtime/perl/t/binding/029-charbuf.t b/runtime/perl/t/binding/029-charbuf.t index bc802e5..a8b790b 100644 --- a/runtime/perl/t/binding/029-charbuf.t +++ b/runtime/perl/t/binding/029-charbuf.t @@ -17,7 +17,7 @@ use strict; use warnings; use lib 'buildlib'; -use Test::More tests => 3; +use Test::More tests => 4; use Encode qw( _utf8_off ); use Clownfish; @@ -41,3 +41,28 @@ $string = Clownfish::String->new($smiley); my $clone = $string->clone; is( $clone->to_perl, Clownfish::String->new($smiley)->to_perl, "clone" ); +{ + package MyStringCallbackTest; + use base qw(Clownfish::Test::StringCallbackTest); + + our $string_ref; + + sub new { + $string_ref = \$_[1]; + return $_[0]->SUPER::new; + } + + sub callback { + my $self = shift; + $$string_ref = 'bar'; + } +} + +SKIP: { + skip( "Known issue CLOWNFISH-44", 1 ); + my $string = 'foo'; + my $callback_test = MyStringCallbackTest->new($string); + ok( $callback_test->unchanged_by_callback($string), + "String unchanged by callback" ); +} +
