Anonymous avatar Anonymous committed 6e0e77f

Adding a test and the help flag

Comments (0)

Files changed (5)

modules/App-XML-DocBook-Docmake/Build.PL

     dist_version_from   => 'lib/App/XML/DocBook/Builder.pm',
     build_requires => {
         'Test::More' => 0,
+        'Test::Trap' => 0,
+
+    },
+    requires => {
+            'Getopt::Long' => '2.37',
     },
     add_to_cleanup      => [ 'App::XML::DocBook::Builder-*' ],
     script_files => [ "bin/docmake" ],

modules/App-XML-DocBook-Docmake/MANIFEST

 META.yml # Will be created by "make dist"
 README
 t/00-load.t
+t/01-use.t
 t/boilerplate.t
 t/pod-coverage.t
 t/pod.t

modules/App-XML-DocBook-Docmake/META.yml

 license: bsd
 resources:
   license: http://www.opensource.org/licenses/bsd-license.php
+requires:
+  Getopt::Long: 2.37
 build_requires:
   Test::More: 0
+  Test::Trap: 0
 provides:
   App::XML::DocBook::Builder:
     file: lib/App/XML/DocBook/Builder.pm
     version: 0.01
-generated_by: Module::Build version 0.2805
+  App::XML::DocBook::Docmake:
+    file: lib/App/XML/DocBook/Docmake.pm
+generated_by: Module::Build version 0.2801
 meta-spec:
   url: http://module-build.sourceforge.net/META-spec-v1.2.html
   version: 1.2

modules/App-XML-DocBook-Docmake/lib/App/XML/DocBook/Docmake.pm

 
 =cut
 
+my %modes = 
+(
+    'help' =>
+    {
+        standalone => 1,
+    },
+    'xhtml' =>
+    {
+    },
+);
+
 sub new
 {
     my $class = shift;
 
     my $mode = shift(@$argv);
 
-    if ($mode eq "xhtml")
+    my $mode_struct = $modes{$mode};
+
+    if ($mode_struct)
     {
         $self->_mode($mode);
     }
 
     my $input_path = shift(@$argv);
 
-    if (!defined($input_path))
+    if (! (defined($input_path) || $mode_struct->{standalone}) )
     {
         die "Input path not specified on command line";
     }
-
-    $self->_input_path($input_path);
+    else
+    {
+        $self->_input_path($input_path);
+    }
 
     return;
 }
 {
     my $self = shift;
 
+    my $mode = $self->_mode();
+
+    my $mode_func = "_run_mode_$mode";
+
+    return $self->$mode_func(@_);
+}
+
+sub _run_mode_help
+{
+    my $self = shift;
+
+    print <<"EOF";
+Docmake version $VERSION
+A tool to convert DocBook/XML to other formats
+
+Available commands:
+
+    help - this help screen.
+    xhtml - convert to xhtml.
+EOF
+}
+
+sub _run_mode_xhtml
+{
     my @stylesheet_params = ("http://docbook.sourceforge.net/release/xsl/current/xhtml/docbook.xsl");
 
     if (defined($self->_stylesheet()))

modules/App-XML-DocBook-Docmake/t/01-use.t

+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 2;
+use Test::Trap qw( trap $trap :flow:stderr(systemsafe):stdout(systemsafe):warn );
+
+use App::XML::DocBook::Docmake;
+
+{
+    my $docmake = App::XML::DocBook::Docmake->new({argv => ["help"]});
+
+    # TEST
+    ok ($docmake, "Testing that docmake was initialized");
+}
+
+{
+    my $docmake = App::XML::DocBook::Docmake->new({argv => ["help"]});
+    
+    trap { $docmake->run(); };
+
+    # TEST
+    like ($trap->stdout(),
+          qr{Docmake version.*^A tool to convert DocBook/XML to other formats.*^Available commands:\n}ms,
+          "Testing output of help"
+    );
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.