Commits

Anonymous committed 5946dbb

Converted a test from bash to Perl+TAP and made the exit value consistent.

Comments (0)

Files changed (14)

installer/perl5/Shlomif/Quad/Pres/CmdLine.pm

 {
     my $self = shift;
 
+    my $ret;
     try {
-        return $self->real_run();
+        $ret = $self->real_run();
     }
     catch $error_class with {
         my $e = shift;
         print STDERR "Quad-Pres Error: ", $e->text(), "\n";
-        return (-1);        
+        $ret = -1;        
     }
     otherwise {
         my $e = shift;
         print STDERR "$e\n"; 
-        return (-1);
+        $ret = -1;
     };
+
+    return $ret;
 }
 
 sub real_run
     
     my $callback = $registered_commands{$cmd_aliases{$command}};
     
-    $self->$callback();    
+    return $self->$callback();    
 }
 
 sub get_dir_path
     close(O);
 
     print "Successfully Created $src_dir_name\n";
+
+    return 0;
 }
 
 sub chdir_to_base
     {
         $self->_convert_to_hardisk()
     }
+
+    return 0;
 }
 
 sub _convert_to_hardisk
     my $dest_dir = $cfg->get_server_dest_dir();
 
     File::Path::rmtree([$dest_dir], 0, 0);
+
+    return 0;
 }
 
 sub perform_upload_command
     }
 
     print (join(" ", @command), "\n");
-    system(@command);
+    return system(@command);
 }
 
 sub add_filename_to_path

installer/tests/Makefile

 all:
 
-BASH_TESTS = workflow html-correctness stop-on-error lang-settings body-dir credit gen-hd-html template-toolkit bolded-nav-links update-images
+BASH_TESTS = html-correctness stop-on-error lang-settings body-dir credit gen-hd-html template-toolkit bolded-nav-links update-images
 
 BASH_TESTS_TARGETS = $(addprefix test-,$(BASH_TESTS))
 
 check: perl-tests bash-tests 
 
 TEST_VERBOSE = 0
-TEST_FILES = perl/t/*.t
+TEST_FILES = t/*.t
 
 perl-tests-t:
-	PERL_DL_NONLAZY=1 perl "-MExtUtils::Command::MM" "-e" "test_harness($(TEST_VERBOSE))" $(TEST_FILES)
+	cd "perl" && PERL_DL_NONLAZY=1 perl "-MExtUtils::Command::MM" "-e" "test_harness($(TEST_VERBOSE))" $(TEST_FILES)

installer/tests/perl/t/lib/workflow/template/Contents.pm

+package Contents;
+
+use strict;
+
+my $contents =
+{
+    'title' => "My Lecture Title",
+    'subs' =>
+    [
+        {
+            'url' => "two.html",
+            'title' => "Child Node",
+        },
+    ],
+    'images' =>
+    [
+        'style.css',
+    ],
+};
+
+sub get_contents
+{
+    return $contents;
+}
+
+1;

installer/tests/perl/t/lib/workflow/template/src/index.html.wml

+#include 'template.wml'
+
+<h1><font color="red">FILL IN</font></h1>

installer/tests/perl/t/lib/workflow/template/src/two.html.wml

+#include 'template.wml'
+
+<ol>
+<li>
+Hi there!
+</li>
+</ol>

installer/tests/perl/t/workflow.t

+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 7;
+
+use File::Path;
+use File::Copy::Recursive qw(dircopy fcopy);
+use Cwd;
+use IO::All;
+
+my $io_dir = "t/data/in-out-workflow";
+rmtree ($io_dir);
+mkpath ($io_dir);
+
+sub check_files
+{
+    local $Test::Builder::Level = $Test::Builder::Level + 1;
+    my $output_dir = shift;
+
+    return ok (((-e "$output_dir/index.html") && (-e "$output_dir/two.html")),
+        "The requested files exist in the output directory"
+    );
+}
+
+sub perform_test
+{
+    my $orig_dir = Cwd::getcwd();
+
+    chdir($io_dir);
+    my $test_dir = "testhtml1";
+    my $output_dir = "$test_dir-output";
+
+    my $pwd = Cwd::getcwd();
+
+    # TEST
+    ok(
+        !system(
+        "quadp", "setup", $test_dir, "--dest-dir=$pwd/$output_dir"
+        ),
+        "Running quadp setup was succesful."
+    );
+
+    my $tmpl_dir = "$orig_dir/t/lib/workflow/template";
+
+    fcopy("$tmpl_dir/Contents.pm", "$test_dir/Contents.pm",);
+    foreach my $file (glob("$tmpl_dir/src/*.html.wml"))
+    {
+        fcopy($file, "$test_dir/src");
+    }
+
+    # TEST
+    ok(
+        !system("cd $test_dir && quadp render -a"),
+        "quadp render -a",
+    );
+
+    # TEST
+    check_files("$test_dir-output");
+
+    my @l = io("$test_dir/quadpres.ini")->getlines();
+    foreach (@l)
+    {
+        s{\Aupload_path=.*\Z}{upload_path=$pwd/upload};
+    }
+    io("$test_dir/quadpres.ini")->print(@l);
+
+    # TEST
+    ok (!system("cd $test_dir && quadp upload -a"),
+        "quapd upload succeeded",
+    );
+
+    my $count = `diff -u -r upload "$output_dir" | wc -l`;
+
+    $count =~ s{\D}{}g;
+
+    # TEST
+    is(
+        $count,
+        0,
+        "Uploading failed.",
+    );
+
+    # TEST
+    ok(
+        !system("cd $test_dir && quadp render -a -hd"),
+        "quadp Hard-Disk rendering succeeded."
+    );
+
+    # TEST
+    check_files("$test_dir/hard-disk-html");
+
+    chdir($orig_dir);
+}
+
+perform_test();

installer/tests/workflow/template/Contents.pm

-package Contents;
-
-use strict;
-
-my $contents =
-{
-    'title' => "My Lecture Title",
-    'subs' =>
-    [
-        {
-            'url' => "two.html",
-            'title' => "Child Node",
-        },
-    ],
-    'images' =>
-    [
-        'style.css',
-    ],
-};
-
-sub get_contents
-{
-    return $contents;
-}
-
-1;

installer/tests/workflow/template/src/index.html.wml

-#include 'template.wml'
-
-<h1><font color="red">FILL IN</font></h1>

installer/tests/workflow/template/src/two.html.wml

-#include 'template.wml'
-
-<ol>
-<li>
-Hi there!
-</li>
-</ol>

installer/tests/workflow/test1.bash

-#!/bin/bash
-
-# Verify the HTML correctness for all the themes
-
-if [ ! -e in-out ] ; then
-    mkdir in-out
-else
-    rm -fr in-out/*
-fi
-cd "in-out"
-
-# Check that the default charset and lang are OK.
-t=0
-
-check_files()
-{
-    local output_dir
-    output_dir="$1"
-    shift
-    if [ \( \! -e $output_dir/index.html \) -o \( \! -e $output_dir/two.html \) ] ; then
-        echo "The requested file do not exist in the output directory" 1>&2
-        exit 1
-    fi
-}
-
-perform_test()
-{
-let t++
-echo "Test No. $t : Theme=$theme credit=$credit"
-
-test_dir=testhtml$t
-output_dir="$test_dir-output"
-quadp setup $test_dir --dest-dir="`pwd`/$output_dir"
-
-cp -R ../template/Contents.pm $test_dir
-cp -R ../template/src/*.html.wml $test_dir/src
-
-if ! (cd $test_dir && quadp render -a) ; then
-    echo "quadp render -a Failed!" 1>&2
-    exit 1
-fi
-
-check_files $test_dir-output
-
-sed -i '/^upload_path=/s!=!='"`pwd`"'/upload!' $test_dir/quadpres.ini
-
-if ! (cd $test_dir && quadp upload -a) ; then
-    echo "quadp upload Failed!" 1>&2
-    exit 1
-fi
-
-
-A="$(diff -u -r upload "$output_dir" | wc -l)"
-if test "$A" -ne 0 ; then
-    echo "Uploading failed!" 1>&2
-    exit 1
-fi
-
-if ! (cd $test_dir && quadp render -a -hd) ; then
-    echo "quadp Hard-Disk rendering Failed!" 1>&2
-    exit 1
-fi
-
-check_files "$test_dir/hard-disk-html"
-}
-echo "Workflow Test"
-
-
-perform_test
-
-

rejects/installer/workflow/template/Contents.pm

+package Contents;
+
+use strict;
+
+my $contents =
+{
+    'title' => "My Lecture Title",
+    'subs' =>
+    [
+        {
+            'url' => "two.html",
+            'title' => "Child Node",
+        },
+    ],
+    'images' =>
+    [
+        'style.css',
+    ],
+};
+
+sub get_contents
+{
+    return $contents;
+}
+
+1;

rejects/installer/workflow/template/src/index.html.wml

+#include 'template.wml'
+
+<h1><font color="red">FILL IN</font></h1>

rejects/installer/workflow/template/src/two.html.wml

+#include 'template.wml'
+
+<ol>
+<li>
+Hi there!
+</li>
+</ol>

rejects/installer/workflow/test1.bash

+#!/bin/bash
+
+# Verify the HTML correctness for all the themes
+
+if [ ! -e in-out ] ; then
+    mkdir in-out
+else
+    rm -fr in-out/*
+fi
+cd "in-out"
+
+# Check that the default charset and lang are OK.
+t=0
+
+check_files()
+{
+    local output_dir
+    output_dir="$1"
+    shift
+    if [ \( \! -e $output_dir/index.html \) -o \( \! -e $output_dir/two.html \) ] ; then
+        echo "The requested file do not exist in the output directory" 1>&2
+        exit 1
+    fi
+}
+
+perform_test()
+{
+let t++
+echo "Test No. $t : Theme=$theme credit=$credit"
+
+test_dir=testhtml$t
+output_dir="$test_dir-output"
+quadp setup $test_dir --dest-dir="`pwd`/$output_dir"
+
+cp -R ../template/Contents.pm $test_dir
+cp -R ../template/src/*.html.wml $test_dir/src
+
+if ! (cd $test_dir && quadp render -a) ; then
+    echo "quadp render -a Failed!" 1>&2
+    exit 1
+fi
+
+check_files $test_dir-output
+
+sed -i '/^upload_path=/s!=!='"`pwd`"'/upload!' $test_dir/quadpres.ini
+
+if ! (cd $test_dir && quadp upload -a) ; then
+    echo "quadp upload Failed!" 1>&2
+    exit 1
+fi
+
+
+A="$(diff -u -r upload "$output_dir" | wc -l)"
+if test "$A" -ne 0 ; then
+    echo "Uploading failed!" 1>&2
+    exit 1
+fi
+
+if ! (cd $test_dir && quadp render -a -hd) ; then
+    echo "quadp Hard-Disk rendering Failed!" 1>&2
+    exit 1
+fi
+
+check_files "$test_dir/hard-disk-html"
+}
+echo "Workflow Test"
+
+
+perform_test
+
+