Item10833: create_new_extension.pl should create stub unit tests (with patch)

pencil
Priority: Enhancement
Current State: No Action Required
Released In: n/a
Target Release: n/a
Applies To: Extension
Component: BuildContrib
Branches:
Reported By: AndrewJones
Waiting For:
Last Change By: AndrewJones
Would be nice if create_new_extension.pl created stub unit tests.

-- AndrewJones - 03 Jun 2011

Turned out to be really easy. Here is a patch that creates a working test suite with a new plugin or contrib (not skins). Release01x01 branch.

Index: create_new_extension.pl
===================================================================
--- create_new_extension.pl     (revision 11801)
+++ create_new_extension.pl     (working copy)
@@ -167,6 +167,13 @@
 writeFile( $modPath, "DEPENDENCIES", $data{DEPENDENCIES} );
 writeFile( $modPath, "MANIFEST",     $data{MANIFEST} );
 
+# write tests
+if ( $def{TYPE} eq 'Plugin' || $def{TYPE} eq 'Contrib' ) {
+    my $testPath = "$def{MODULE}/test/unit/$def{MODULE}";
+    writeFile( $testPath, "$def{MODULE}Suite.pm", $data{TEST_SUITE} );
+    writeFile( $testPath, "$def{MODULE}Tests.pm", $data{TESTS} );
+}
+
 writeFile( "$def{MODULE}/data/System", "$def{MODULE}.txt",
     ( $data{"TXT_$def{TYPE}"} || $data{TXT} ) );
 
@@ -297,6 +304,57 @@
 
 our $SHORTDESCRIPTION = '%$SHORTDESCRIPTION%';
 
+<<<< TEST_SUITE >>>>
+package %$MODULE%Suite;
+
+use strict;
+
+use Unit::TestSuite;
+our @ISA = 'Unit::TestSuite';
+
+sub name { '%$MODULE%Suite' }
+
+sub include_tests { qw(%$MODULE%Tests) }
+
+1;
+
+<<<< TESTS >>>>
+package %$MODULE%Tests;
+
+use strict;
+
+use FoswikiFnTestCase;
+our @ISA = qw( FoswikiFnTestCase );
+
+use Foswiki;
+use Foswiki::Func;
+use Foswiki::%$STUBS%::%$MODULE%;
+
+sub new {
+    my $self = shift()->SUPER::new(@_);
+    return $self;
+}
+
+sub set_up {
+    my $this = shift;
+
+    $this->SUPER::set_up();
+}
+
+sub tear_down {
+    my $this = shift;
+    $this->SUPER::tear_down();
+}
+
+sub test_self {
+    my $this = shift;
+
+    $this->assert(1);
+}
+
+1;
+
 <<<< TXT >>>>
 ---+!! !%$MODULE%
 <!--

Any objections to committing this?

-- AndrewJones - 03 Jun 2011

Turns out we don't need this in trunk, as we can create a plugin based on EmptyPlugin, which has the test infrastructure.

Closing.

-- AndrewJones - 06 Jun 2011
 

ItemTemplate edit

Summary create_new_extension.pl should create stub unit tests (with patch)
ReportedBy AndrewJones
Codebase
SVN Range
AppliesTo Extension
Component BuildContrib
Priority Enhancement
CurrentState No Action Required
WaitingFor
Checkins
TargetRelease n/a
ReleasedIn n/a
Topic revision: r2 - 06 Jun 2011, AndrewJones
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy