X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=scpubgit%2FQ-Branch.git;a=blobdiff_plain;f=lib%2FSQL%2FAbstract%2FTest.pm;h=e163f2c5987a0758e96bce06276e752b45f96d83;hp=343b1fad3b6dd982800101f228c3d3d65a98e84e;hb=cf5b7ab163f8ac123ebc9bb1156e79646cd5bd2f;hpb=77617257225dda6e402c4bc4ab20b991cb5ff246 diff --git a/lib/SQL/Abstract/Test.pm b/lib/SQL/Abstract/Test.pm index 343b1fa..e163f2c 100644 --- a/lib/SQL/Abstract/Test.pm +++ b/lib/SQL/Abstract/Test.pm @@ -7,6 +7,42 @@ use Test::Builder; use Test::Deep (); use SQL::Abstract::Tree; +{ + my $class; + if ($class = $ENV{SQL_ABSTRACT_TEST_AGAINST}) { + my $mod = join('/', split '::', $class).".pm"; + require $mod; + eval qq{sub SQL::Abstract () { "\Q${class}\E" }; 1} + or die "Failed to create const sub for ${class}: $@"; + } + if ($ENV{SQL_ABSTRACT_TEST_EXPAND_STABILITY}) { + $class ||= do { require SQL::Abstract; 'SQL::Abstract' }; + my $orig = $class->can('expand_expr'); + require Data::Dumper::Concise; + my $wrapped = sub { + my ($self, @args) = @_; + my $e1 = $self->$orig(@args); + return $e1 if our $Stab_Check_Rec; + local $Stab_Check_Rec = 1; + my $e2 = $self->$orig($e1); + my ($d1, $d2) = map Data::Dumper::Concise::Dumper($_), $e1, $e2; + (our $tb)->is_eq( + $d2, $d1, + 'expand_expr stability ok' + ) or do { + require Path::Tiny; + Path::Tiny->new('e1')->spew($d1); + Path::Tiny->new('e2')->spew($d2); + system('diff -u e1 e2 1>&2'); + die "Differences between e1 and e2, bailing out"; + }; + return $e1; + }; + no strict 'refs'; no warnings 'redefine'; + *{"${class}::expand_expr"} = $wrapped; + } +} + our @EXPORT_OK = qw( is_same_sql_bind is_same_sql is_same_bind eq_sql_bind eq_sql eq_bind dumper diag_where