From: <de...@de...> - 2012-07-12 06:18:43
|
Author: HideyoImazu Date: 2012-07-12 01:18:36 -0500 (Thu, 12 Jul 2012) New Revision: 23071 Trac url: http://develop.twiki.org/trac/changeset/23071 Modified: twiki/trunk/UnitTestContrib/lib/Unit/TestCase.pm twiki/trunk/UnitTestContrib/test/unit/MdrepoTests.pm Log: Item6901: UnitTestContrib to execute test_* functions in the alphabetical order Modified: twiki/trunk/UnitTestContrib/lib/Unit/TestCase.pm =================================================================== --- twiki/trunk/UnitTestContrib/lib/Unit/TestCase.pm 2012-07-11 09:08:08 UTC (rev 23070) +++ twiki/trunk/UnitTestContrib/lib/Unit/TestCase.pm 2012-07-12 06:18:36 UTC (rev 23071) @@ -63,7 +63,7 @@ my @tests; my @verifies; my $clz = new Devel::Symdump($suite); - for my $i ($clz->functions()) { + for my $i (sort $clz->functions()) { if ($i =~ /^$suite\:\:test/) { push(@tests, $i); } elsif ($i =~ /^$suite\:\:(verify.*$)/) { Modified: twiki/trunk/UnitTestContrib/test/unit/MdrepoTests.pm =================================================================== --- twiki/trunk/UnitTestContrib/test/unit/MdrepoTests.pm 2012-07-11 09:08:08 UTC (rev 23070) +++ twiki/trunk/UnitTestContrib/test/unit/MdrepoTests.pm 2012-07-12 06:18:36 UTC (rev 23071) @@ -52,113 +52,236 @@ sub var_test { my ($this, $var, $expected) = @_; - my $expanded = $twiki->handleCommonTags( $var, $twiki->{webName}, $twiki->{topicName} ); - $this->assert_equals($expanded, $expected); + my $expanded = + $twiki->handleCommonTags($var, $twiki->{webName}, $twiki->{topicName}); + $this->assert_equals($expected, $expanded); } -sub test_mdrepo { +my %siteTable = ( + am => {server => 'strawman', + datadir => '/d/twiki/data', + pubdir => '/d/twiki/pub', + }, + eu => {server => 'woodenman', + datadir => '/var/twiki/data', + pubdir => '/var/twiki/pub', + }, + as => {server => 'tinman', + datadir => '/share/twiki/data', + pubdir => '/share/twiki/pub', + }, +); + +my %webTable = ( + WebOne => {admin => 'GodelGroup', master => 'am'}, + WebTwo => {admin => 'EscherGroup', master => 'eu'}, + WebThree => {admin => 'BachGroup', master => 'as'}, +); + +sub load_sites { my $this = shift; + my $mdrepo = $twiki->{mdrepo}; + # putting and getting data to/from the sites table + for my $i ( keys %siteTable ) { + $mdrepo->putRec('sites', $i, $siteTable{$i}); + } +} + +sub load_webs { + my $this = shift; my $mdrepo = $twiki->{mdrepo}; - my $rec; + # putting and getting data to/from the webs table + for my $i ( keys %webTable ) { + $mdrepo->putRec('webs', $i, $webTable{$i}); + } +} + +sub test_010_webs_empty { + my $this = shift; + my $mdrepo = $twiki->{mdrepo}; + # new empty table is expected to be created my @webs = $mdrepo->getList('webs'); - $this->assert_equals(scalar(@webs), 0); + $this->assert_equals(0, scalar(@webs)); +} +sub test_020_webs_nonexistent_record { + my $this = shift; + my $mdrepo = $twiki->{mdrepo}; + # retrieving nonexistent record - $rec = $mdrepo->getRec('webs', 'foo'); - $this->assert_str_equals($rec, ''); + my $rec = $mdrepo->getRec('webs', 'foo'); + $this->assert_str_equals('', $rec); +} +sub test_030_sites_empty { + my $this = shift; + my $mdrepo = $twiki->{mdrepo}; + # another new empty table is expected to be created my @sites = $mdrepo->getList('sites'); - $this->assert_equals(scalar(@sites), 0); + $this->assert_equals(0, scalar(@sites)); +} - # a nonexistent table +sub test_040_nonexistent_table { + my $this = shift; + my $mdrepo = $twiki->{mdrepo}; + my @nonexistent = $mdrepo->getList('nonexistent'); - $this->assert_equals(scalar(@nonexistent), 0); - $rec = $mdrepo->getRec('nonexistent', 'bar'); - $this->assert_str_equals($rec, ''); + $this->assert_equals(0, scalar(@nonexistent)); + my $rec = $mdrepo->getRec('nonexistent', 'bar'); + $this->assert_str_equals('', $rec); +} +sub test_050_reset_table { + my $this = shift; + my $mdrepo = $twiki->{mdrepo}; + # nothing should break by resetting empty and nonexistent tables $mdrepo->resetTable('webs'); $mdrepo->resetTable('nonexistent'); +} - my %siteTable = ( - am => {server => 'strawman', datadir => '/d/twiki/data', pubdir => '/d/twiki/pub'}, - eu => {server => 'woodenman', datadir => '/var/twiki/data', pubdir => '/var/twiki/pub'}, - as => {server => 'tinman', datadir => '/share/twiki/data', pubdir => '/share/twiki/pub'}, - ); - my %webTable = ( - WebOne => {admin => 'GodelGroup', master => 'am'}, - WebTwo => {admin => 'EscherGroup', master => 'eu'}, - WebThree => {admin => 'BachGroup', master => 'as'}, - ); +sub test_060_put_sites_rec { + my $this = shift; + my $mdrepo = $twiki->{mdrepo}; # putting and getting data to/from the sites table + $this->load_sites(); for my $i ( keys %siteTable ) { - $mdrepo->putRec('sites', $i, $siteTable{$i}); + my $rec = $mdrepo->getRec('sites', $i); + $this->assert_deep_equals($siteTable{$i}, $rec); } - for my $i ( keys %siteTable ) { - $rec = $mdrepo->getRec('sites', $i); - $this->assert_deep_equals($rec, $siteTable{$i}); - } +} + +sub test_070_MDREPO_sites_vanilla { + my $this = shift; + + $this->load_sites(); $this->var_test('%MDREPO{"sites"}%', '| am | datadir=/d/twiki/data pubdir=/d/twiki/pub server=strawman | | as | datadir=/share/twiki/data pubdir=/share/twiki/pub server=tinman | | eu | datadir=/var/twiki/data pubdir=/var/twiki/pub server=woodenman |'); - $this->var_test('%MDREPO{"sites" format="?pubdir?$_=$server()?" separator=", "}%', -'am=strawman, as=tinman, eu=woodenman'); +} +sub test_075_MDREPO_sites_custom { + my $this = shift; + + $this->load_sites(); + $this->var_test( + '%MDREPO{"sites" format="?pubdir?$_=$server()?" separator=", "}%', + 'am=strawman, as=tinman, eu=woodenman' + ); +} + +sub test_080_put_webs_rec { + my $this = shift; + my $mdrepo = $twiki->{mdrepo}; + # putting and getting data to/from the webs table + $this->load_webs(); for my $i ( keys %webTable ) { - $mdrepo->putRec('webs', $i, $webTable{$i}); + my $rec = $mdrepo->getRec('webs', $i); + $this->assert_deep_equals($webTable{$i}, $rec); } - for my $i ( keys %webTable ) { - $rec = $mdrepo->getRec('webs', $i); - $this->assert_deep_equals($rec, $webTable{$i}); - } +} + +sub test_090_MDREPO_webs { + my $this = shift; + my $mdrepo = $twiki->{mdrepo}; + + $this->load_webs(); $this->var_test('%MDREPO{"webs"}%', '| WebOne | admin=GodelGroup master=am | | WebThree | admin=BachGroup master=as | | WebTwo | admin=EscherGroup master=eu |'); +} +sub test_100_put_nonexistent_table { + my $this = shift; + my $mdrepo = $twiki->{mdrepo}; + # confirming nothing breaks by putting a record to a nonexistent table $mdrepo->putRec('nonexistent', 'foo', {bar => 123}); - $rec = $mdrepo->getRec('nonexistent', 'foo'); - $this->assert_equals($rec, ''); + my $rec = $mdrepo->getRec('nonexistent', 'foo'); + $this->assert_equals('', $rec); +} +sub test_110_del_webs_rec { + my $this = shift; + my $mdrepo = $twiki->{mdrepo}; + + $this->load_webs(); $mdrepo->delRec('webs', 'WebThree'); - $rec = $mdrepo->getRec('webs', 'WebThree'); - $this->assert_str_equals($rec, ''); + my $rec = $mdrepo->getRec('webs', 'WebThree'); + $this->assert_str_equals('', $rec); my @list = $mdrepo->getList('webs'); - $this->assert_equals(scalar(@list), 2); + $this->assert_equals(2, scalar(@list)); +} +sub test_120_del_sites_rec { + my $this = shift; + my $mdrepo = $twiki->{mdrepo}; + + $this->load_sites(); $mdrepo->delRec('sites', 'as'); - $rec = $mdrepo->getRec('sites', 'as'); - $this->assert_str_equals($rec, ''); - @list = $mdrepo->getList('sites'); + my $rec = $mdrepo->getRec('sites', 'as'); + $this->assert_str_equals('', $rec); + my @list = $mdrepo->getList('sites'); $this->assert_equals(scalar(@list), 2); +} - my $siteAm1 = {server => 'strawma', datadir => '/d/twiki/dat', pubdir => '/d/twiki/pu'}; +sub test_130_updt_sites_rec { + my $this = shift; + my $mdrepo = $twiki->{mdrepo}; + + $this->load_sites(); + my $siteAm1 = { + server => 'strawma', + datadir => '/d/twiki/dat', + pubdir => '/d/twiki/pu', + }; $mdrepo->putRec('sites', 'am', $siteAm1); - $rec = $mdrepo->getRec('sites', 'am'); + my $rec = $mdrepo->getRec('sites', 'am'); $this->assert_deep_equals($rec, $siteAm1); +} - my $webTwo1 = {admin => 'EscheGroup', master => 'as'}; +sub test_140_updt_webs_rec { + my $this = shift; + my $mdrepo = $twiki->{mdrepo}; + + $this->load_webs(); + my $webTwo1 = { + admin => 'EscheGroup', + master => 'as', + }; $mdrepo->putRec('webs', 'WebTwo', $webTwo1); - $rec = $mdrepo->getRec('webs', 'WebTwo'); + my $rec = $mdrepo->getRec('webs', 'WebTwo'); $this->assert_deep_equals($rec, $webTwo1); +} +sub test_150_reset_webs_again { + my $this = shift; + my $mdrepo = $twiki->{mdrepo}; + + $this->load_webs(); $mdrepo->resetTable('webs'); - $this->assert_equals(scalar($mdrepo->getList('webs')), 0); - $rec = $mdrepo->getRec('webs', 'WebOne'); - $this->assert_str_equals($rec, ''); + $this->assert_equals(0, scalar($mdrepo->getList('webs'))); + my $rec = $mdrepo->getRec('webs', 'WebOne'); + $this->assert_str_equals('', $rec); +} +sub test_160_reset_sites_again { + my $this = shift; + my $mdrepo = $twiki->{mdrepo}; + + $this->load_sites(); $mdrepo->resetTable('sites'); $this->assert_equals(scalar($mdrepo->getList('sites')), 0); - $rec = $mdrepo->getRec('sites', 'am'); - $this->assert_str_equals($rec, ''); + my $rec = $mdrepo->getRec('sites', 'am'); + $this->assert_str_equals('', $rec); } 1; |