From 7695a8eb59a0ea38b6cd3a332d5d0978eaa715c2 Mon Sep 17 00:00:00 2001 From: Matthew Musgrove Date: Fri, 24 Jun 2016 13:29:02 -0500 Subject: [PATCH 1/8] nulls-warn: Add an Artist with a null name and a corresponding CD. --- t/lib/DBICTest.pm | 2 ++ 1 file changed, 2 insertions(+) diff --git a/t/lib/DBICTest.pm b/t/lib/DBICTest.pm index 8b6d155..217aaf4 100755 --- a/t/lib/DBICTest.pm +++ b/t/lib/DBICTest.pm @@ -155,6 +155,7 @@ sub populate_schema { [ 2, 'Random Boy Band' ], [ 3, 'We Are Goth' ], [ 4, '' ], # Test overridden new will default name to "Test Name" using use_create => 1. + [ 5, undef ], # The artist formerly known as *silence*. [ 32948, 'Big PK' ], ]); @@ -171,6 +172,7 @@ sub populate_schema { [ 4, 2, "Generic Manufactured Singles", 2001 ], [ 5, 2, "Unicode Chars ™ © • † ∑ α β « » → …", 2015 ], [ 6, 3, "Übertreibung älterer Umlaute with us", 1998 ], + [ 7, 5, "Cosmic Nothingness", 2016 ], ]); $schema->populate('Tag', [ From 43534260342be49db907e1c959bf7c188c4ad1b0 Mon Sep 17 00:00:00 2001 From: Matthew Musgrove Date: Fri, 24 Jun 2016 13:30:23 -0500 Subject: [PATCH 2/8] nulls-warn: Add a configuration for test of null --- t/var/configs/nulls.json | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 t/var/configs/nulls.json diff --git a/t/var/configs/nulls.json b/t/var/configs/nulls.json new file mode 100644 index 0000000..f244596 --- /dev/null +++ b/t/var/configs/nulls.json @@ -0,0 +1,16 @@ +{ + "might_have": { + "fetch": 0 + }, + "has_many": { + "fetch": 0 + }, + "sets": [{ + "class": "Artist", + "cond": { "me.name": { "!=": null } }, + "quantity": "all", + "fetch": [{ + "rel": "cds" + }] + }] +} From 9ad5e940d3c2985f633a8577da757af6e3e7d500 Mon Sep 17 00:00:00 2001 From: Matthew Musgrove Date: Fri, 24 Jun 2016 13:30:47 -0500 Subject: [PATCH 3/8] nulls-warn: Add tests for null --- t/20-nulls.t | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 t/20-nulls.t diff --git a/t/20-nulls.t b/t/20-nulls.t new file mode 100644 index 0000000..cac29bb --- /dev/null +++ b/t/20-nulls.t @@ -0,0 +1,38 @@ +#!perl + +use DBIx::Class::Fixtures; +use Test::More tests => 6; +use lib qw(t/lib); +use DBICTest; +use Path::Class; +use Data::Dumper; +use Test::TempDir::Tiny; +use IO::All; +use Test::Warnings; + +my $tempdir = tempdir; + +# set up and populate schema +ok(my $schema = DBICTest->init_schema(db_dir => $tempdir), 'got schema'); + +my $config_dir = io->catfile(qw't var configs')->name; + +# do dump +ok(my $fixtures = DBIx::Class::Fixtures->new({ config_dir => $config_dir, debug => 0 }), 'object created with correct config dir'); + +ok($fixtures->dump({ config => 'nulls.json', schema => $schema, directory => $tempdir }), 'simple dump executed okay'); + +{ + # check dump is okay + my $dir = dir(io->catfile($tempdir, qw'artist')->name); + my @children = $dir->children; + is(scalar(@children), 5, 'right number of fixtures created'); +} + +{ + # check dump is okay + my $dir = dir(io->catfile($tempdir, qw'CD')->name); + my @children = $dir->children; + is(scalar(@children), 6, 'right number of fixtures created'); +} + From 2b435734229dce61d5b816395f48c12a061ee28e Mon Sep 17 00:00:00 2001 From: Matthew Musgrove Date: Fri, 24 Jun 2016 13:31:27 -0500 Subject: [PATCH 4/8] nulls-warn: Skip the s/// if $_ is not defined --- lib/DBIx/Class/Fixtures.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/DBIx/Class/Fixtures.pm b/lib/DBIx/Class/Fixtures.pm index c979849..6796692 100644 --- a/lib/DBIx/Class/Fixtures.pm +++ b/lib/DBIx/Class/Fixtures.pm @@ -813,7 +813,7 @@ sub dump_object { }; my $subsre = join( '|', keys %$subs ); - $_ =~ s{__($subsre)(?:\((.+?)\))?__}{ $subs->{ $1 }->( $self, $2 ? split( /,/, $2 ) : () ) }eg; + $_ =~ s{__($subsre)(?:\((.+?)\))?__}{ $subs->{ $1 }->( $self, $2 ? split( /,/, $2 ) : () ) }eg if (defined $_); return $_; } From 56479b70f8fe62fe5dffdd698615f0363472c21d Mon Sep 17 00:00:00 2001 From: Matthew Musgrove Date: Fri, 24 Jun 2016 13:32:03 -0500 Subject: [PATCH 5/8] nulls-warn: Add Test::Warnings to TEST_REQUIRES --- Makefile.PL | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile.PL b/Makefile.PL index ce3c5d5..936dc1e 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -49,7 +49,8 @@ my %WriteMakefileArgs = ( "File::Spec" => 0, "IO::Handle" => 0, "IPC::Open3" => 0, - "Test::More" => "0.98" + "Test::More" => "0.98", + "Test::Warnings" => 0, }, "VERSION" => "1.001036", "test" => { From c89056674558419695590b78533109adbbb2eb1f Mon Sep 17 00:00:00 2001 From: Matthew Musgrove Date: Fri, 24 Jun 2016 13:45:54 -0500 Subject: [PATCH 6/8] nulls-warn: Fixed condition in nulls.json --- t/var/configs/nulls.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/var/configs/nulls.json b/t/var/configs/nulls.json index f244596..692dfd9 100644 --- a/t/var/configs/nulls.json +++ b/t/var/configs/nulls.json @@ -7,7 +7,7 @@ }, "sets": [{ "class": "Artist", - "cond": { "me.name": { "!=": null } }, + "cond": { "me.name": { "=": null } }, "quantity": "all", "fetch": [{ "rel": "cds" From 0e5683eca71dfe609de3dc30c4274a71c5daf963 Mon Sep 17 00:00:00 2001 From: Matthew Musgrove Date: Fri, 24 Jun 2016 13:46:15 -0500 Subject: [PATCH 7/8] nulls-warn: Add config for not null. --- t/var/configs/not-nulls.json | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 t/var/configs/not-nulls.json diff --git a/t/var/configs/not-nulls.json b/t/var/configs/not-nulls.json new file mode 100644 index 0000000..f244596 --- /dev/null +++ b/t/var/configs/not-nulls.json @@ -0,0 +1,16 @@ +{ + "might_have": { + "fetch": 0 + }, + "has_many": { + "fetch": 0 + }, + "sets": [{ + "class": "Artist", + "cond": { "me.name": { "!=": null } }, + "quantity": "all", + "fetch": [{ + "rel": "cds" + }] + }] +} From b35c270732bd8372ad47a8d667aed4186cc0dad7 Mon Sep 17 00:00:00 2001 From: Matthew Musgrove Date: Fri, 24 Jun 2016 13:46:57 -0500 Subject: [PATCH 8/8] nulls-warn: Fix counts for null. Add tests for not null. --- t/20-nulls.t | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/t/20-nulls.t b/t/20-nulls.t index cac29bb..82b2969 100644 --- a/t/20-nulls.t +++ b/t/20-nulls.t @@ -1,7 +1,7 @@ #!perl use DBIx::Class::Fixtures; -use Test::More tests => 6; +use Test::More tests => 10; use lib qw(t/lib); use DBICTest; use Path::Class; @@ -22,6 +22,25 @@ ok(my $fixtures = DBIx::Class::Fixtures->new({ config_dir => $config_dir, debug ok($fixtures->dump({ config => 'nulls.json', schema => $schema, directory => $tempdir }), 'simple dump executed okay'); +{ + # check dump is okay + my $dir = dir(io->catfile($tempdir, qw'artist')->name); + my @children = $dir->children; + is(scalar(@children), 1, 'right number of fixtures created'); +} + +{ + # check dump is okay + my $dir = dir(io->catfile($tempdir, qw'CD')->name); + my @children = $dir->children; + is(scalar(@children), 1, 'right number of fixtures created'); +} + +# do dump +ok($fixtures = DBIx::Class::Fixtures->new({ config_dir => $config_dir, debug => 0 }), 'object created with correct config dir'); + +ok($fixtures->dump({ config => 'not-nulls.json', schema => $schema, directory => $tempdir }), 'simple dump executed okay'); + { # check dump is okay my $dir = dir(io->catfile($tempdir, qw'artist')->name);