Anonymous avatar Anonymous committed df9d446

Convert the template-toolkit test to Perl+Test::More.

Comments (0)

Files changed (9)

installer/tests/Makefile

 all:
 
-BASH_TESTS = template-toolkit bolded-nav-links update-images
+BASH_TESTS = bolded-nav-links update-images
 
 BASH_TESTS_TARGETS = $(addprefix test-,$(BASH_TESTS))
 

installer/tests/perl/t/lib/template-toolkit/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/template-toolkit/template/src/index.html.wml

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

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

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

installer/tests/perl/t/template-toolkit.t

+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 5;
+
+use File::Path;
+use File::Copy::Recursive qw(dircopy fcopy);
+use Cwd;
+use IO::All;
+use File::Spec;
+
+my $io_dir_proto = "t/data/in-out-template-toolkit";
+my $io_dir = File::Spec->rel2abs($io_dir_proto);
+rmtree ($io_dir);
+mkpath ($io_dir);
+
+my $test_idx = 0;
+
+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();
+
+    $test_idx++;
+
+    chdir($io_dir);
+    my $test_dir = "testhtml";
+    my $output_dir = "$test_dir-output-fookorw";
+
+    my $pwd = Cwd::getcwd();
+
+    # TEST
+    ok(
+        !system(
+        "quadp", "setup", $test_dir, "--dest-dir=./dest"
+        ),
+        "Running quadp setup was succesful."
+    );
+
+    my $ini_fn = "$test_dir/quadpres.ini";
+    my @lines = io->file($ini_fn)->getlines();
+    
+    @lines = 
+    (
+        map 
+        { 
+            /\Aupload_path=/
+                ? qq{tt_upload_path=[% ENV.mypath %]\n}
+                : $_
+        } 
+        @lines
+    );
+
+    io->file($ini_fn)->print(@lines);
+
+    mkpath($output_dir);
+    local $ENV{'mypath'} = "$pwd/$output_dir";
+
+    my $tmpl_dir = "$orig_dir/t/lib/template-toolkit/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/dest");
+
+    # TEST
+    ok (!system("cd $test_dir && quadp upload -a"),
+        "quadp upload succeeded",
+    );
+
+    my $count = `diff -u -r "$test_dir/dest" "$output_dir" | wc -l`;
+
+    $count =~ s{\D}{}g;
+
+    # TEST
+    is(
+        $count,
+        0,
+        "Uploading failed.",
+    );
+
+    chdir($orig_dir);
+}
+
+perform_test();

installer/tests/template-toolkit/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/template-toolkit/template/src/index.html.wml

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

installer/tests/template-toolkit/template/src/two.html.wml

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

installer/tests/template-toolkit/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
-output_dir="$test_dir-output-fookorw"
-
-quadp setup $test_dir --dest-dir="./dest"
-
-perl -lpi -e  "if (/^upload_path=/) { \$_ = \"tt_upload_path=[% ENV.mypath %]\" }" "$test_dir/quadpres.ini"
-
-mkdir -p "$output_dir"
-export mypath="$(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/dest"
-
-
-if ! (cd $test_dir && quadp upload -a) ; then
-    echo "quadp upload Failed!" 1>&2
-    exit 1
-fi
-
-
-A="$(diff -u -r "$test_dir/dest" "$output_dir" | wc -l)"
-if test "$A" -ne 0 ; then
-    echo "Uploading failed!" 1>&2
-    exit 1
-fi
-}
-echo "Workflow Test"
-
-perform_test
-
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.