Commits

Anonymous committed 3cdfb40

Convert the body-dir test to Perl+TAP.

  • Participants
  • Parent commits a532c75

Comments (0)

Files changed (5)

installer/tests/MANIFEST

 MANIFEST
 MANIFEST-DIRS
 Makefile
-body-dir/test1.bash
 bolded-nav-links/template/Contents.pm
 bolded-nav-links/template/src/finale/books.html.wml
 bolded-nav-links/template/src/finale/links.html.wml
 gen-hd-html/test1.bash
 gen-manifests.sh
 get-files-list.pl
-lang-settings/set-lang-settings.pl
-lang-settings/test1.bash
-lang-settings/verify-lang-settings.pl
 perl/t/cmdline-1.t
 perl/t/empty-group.t
 perl/t/getopt.t
+perl/t/html-correctness.t
+perl/t/lang-settings.t
+perl/t/lib/stop-on-error/template/slides/Contents.pm
+perl/t/lib/stop-on-error/template/slides/src/index.html.wml
+perl/t/lib/stop-on-error/template/slides/src/one.html.wml
+perl/t/lib/stop-on-error/template/slides/src/style.css
+perl/t/lib/stop-on-error/template/slides/src/three.html.wml
+perl/t/lib/stop-on-error/template/slides/src/two.html.wml
 perl/t/lib/workflow/template/Contents.pm
 perl/t/lib/workflow/template/src/index.html.wml
 perl/t/lib/workflow/template/src/two.html.wml
+perl/t/stop-on-error.t
 perl/t/to-be-added-later/stages.t
 perl/t/tree.t
 perl/t/workflow.t

installer/tests/MANIFEST-DIRS

 credit/template/
 credit/template/src/
 gen-hd-html/
-lang-settings/
 perl/
 perl/t/
 perl/t/data/
 perl/t/lib/
+perl/t/lib/stop-on-error/
+perl/t/lib/stop-on-error/template/
+perl/t/lib/stop-on-error/template/slides/
+perl/t/lib/stop-on-error/template/slides/src/
 perl/t/lib/workflow/
 perl/t/lib/workflow/template/
 perl/t/lib/workflow/template/src/
 perl/t/to-be-added-later/
-stop-on-error/
-stop-on-error/template/
-stop-on-error/template/slides/
-stop-on-error/template/slides/src/
 template-toolkit/
 template-toolkit/template/
 template-toolkit/template/src/

installer/tests/Makefile

 all:
 
-BASH_TESTS = body-dir credit gen-hd-html template-toolkit bolded-nav-links update-images
+BASH_TESTS = credit gen-hd-html template-toolkit bolded-nav-links update-images
 
 BASH_TESTS_TARGETS = $(addprefix test-,$(BASH_TESTS))
 

installer/tests/body-dir/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
-
-perform_test()
-{
-let t++
-local theme
-theme="$1"
-shift
-local dir
-dir="$1"
-shift
-echo "Test No. $t : Theme=$theme dir=$dir"
-
-test_dir=testhtml$t
-quadp setup $test_dir --dest-dir=`pwd`/${test_dir}-output
-sed -i "s/-DTHEME=[-a-zA-Z_]\+/-DTHEME=${theme}/" $test_dir/.wmlrc
-
-cat > $test_dir/src/index.html.wml <<EOF
-<set-var qp_body_dir="$dir" />
-#include 'template.wml'
-
-<p>
-Hello world!
-</p>
-
-EOF
-
-(cd $test_dir && quadp render -a)
-output_file=$test_dir-output/index.html
-if ! tidy -errors $output_file ; then
-    echo "File does not validate!" 1>&2 
-    exit 1
-fi
-
-body_str="<body>"
-if test "$dir" == "rtl" ; then
-    body_str="<body dir=\"rtl\">"
-fi
-
-if ! grep -F "$body_str" $output_file > /dev/null ; then
-    echo "File does not contain the correct body!" 1>&2
-    exit 1
-fi 
-
-}
-
-for theme in $(cd ../../installation/share/quad-pres/wml/themes/ && ls) ; do
-    for dir in ltr rtl ; do        
-        perform_test "$theme" "$dir"
-    done
-done
-

installer/tests/perl/t/body-dir.t

+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 16;
+
+use File::Path;
+use File::Copy::Recursive qw(dircopy fcopy);
+use Cwd;
+use IO::All;
+use HTML::Lint;
+
+my $io_dir = "t/data/in-out-body-dir";
+rmtree ($io_dir);
+mkpath ($io_dir);
+
+# TEST:$num_themes=2;
+my @themes = (qw(alon-altman-text shlomif-text));
+
+# TEST:$num_dirs=2;
+my @dirs = (qw(ltr rtl));
+
+# TEST:$num_cfgs=$num_dirs*$num_themes;
+
+
+my $test_idx = 0;
+
+# TEST:$n=0;
+sub perform_test
+{
+    local $Test::Builder::Level = $Test::Builder::Level + 1;
+    my $orig_dir = Cwd::getcwd();
+
+    chdir($io_dir);
+
+    $test_idx++;
+    my $theme = shift;
+    my $dir = shift;
+
+    my $test_dir = "testhtml$test_idx";
+
+    my $pwd = Cwd::getcwd();
+
+    # TEST:$n++;
+    ok (!system(
+            "quadp", "setup", $test_dir, "--dest-dir=$pwd/${test_dir}-output",
+        ),
+        "setup for test $test_idx is successful.",
+    );
+
+
+    my $wml_rc = io->file("$test_dir/.wmlrc");
+
+    my $text = $wml_rc->slurp();
+    $text =~ s{(-DTHEME=)[\w\-]+}{$1$theme};
+    $wml_rc->print($text);
+
+    io()->file("$test_dir/src/index.html.wml")->print(<<"EOF");
+<set-var qp_body_dir="$dir" />
+#include 'template.wml'
+
+<p>
+Hello world!
+</p>
+
+EOF
+
+    chdir($test_dir);
+
+    # TEST:$n++;
+    ok(
+        !system(qw(quadp render -a)),
+        "quadp render -a for test $test_idx",
+    );
+    chdir($pwd);
+
+    my $output_file="$test_dir-output/index.html";
+
+    my $lint = HTML::Lint->new;
+
+
+    $lint->parse_file("$test_dir-output/index.html");
+
+    # TEST:$n++;
+    ok (!scalar($lint->errors()),
+        "HTML is valid for test No. $test_idx."
+    );
+
+    my $body_str="<body>";
+    if ($dir eq "rtl")
+    {
+        $body_str = q{<body dir="rtl">};
+    }
+    
+    # TEST:$n++;
+    like(
+        scalar(io()->file($output_file)->slurp),
+        qr{\Q$body_str\E},
+        "output file contains the right body tag - $test_idx.",
+    );
+
+    return;
+}
+
+# TEST:$num_assertions=$n;
+
+# TEST*$num_assertions*$num_cfgs
+for my $theme (@themes)
+{
+    for my $dir (@dirs)
+    {
+        perform_test($theme,$dir);
+    }
+}
+