#!/usr/bin/perl -w
#
# $Id: test_deformatters,v 1.1 2002/05/19 16:19:46 ed Exp $
#
# Test the three ispell deformatters - TeX, nroff and HTML.  Uses the
# test_dict dictionary and a simple file which contains misspellings
# escaped in various different ways.  We want to check, for example,
# that the TeX deformatter causes ispell to ignore unknown words
# escaped by backslashes, but not to ignore the nroff or HTML markup.
#
# Copyright 2001 Geoff Kuenning, Claremont, CA
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
# 3. All modifications to the source code must be clearly marked as
#    such.  Binary redistributions based on modified source code
#    must be clearly marked as modified versions in the documentation
#    and/or other materials provided with the distribution.
# (clause 4 removed with permission from Geoff Kuenning)
# 5. The name of Geoff Kuenning may not be used to endorse or promote
#    products derived from this software without specific prior
#    written permission.
#
# THIS SOFTWARE IS PROVIDED BY GEOFF KUENNING AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED.  IN NO EVENT SHALL GEOFF KUENNING OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.

# $Log: test_deformatters,v $
# Revision 1.1  2002/05/19 16:19:46  ed
# Added a test case for ispell's various deformatters.  This involved
# creating a new dictionary, test_dict, which contains only a few words.  For
# whatever reason this new test_dict is not included in 'all-languages', it
# has its own Makefile targets which are used only by 'test' and 'clean'.
#
# With that dictionary available, test_deformatters runs ispell four times
# on the sample input test_data/test_deformatters.in, with four different
# deformatters (TeX, nroff, HTML and 'ordinary'), and compares the results
# to expected values.
#
# Also changed 'make test' to clean up after itself, since the ispell binary
# left over from testing installation is no use.
#

use strict;
use Getopt::Std;
my $in = 'test_data/test_deformatters.in';
my %ds = (ordinary => '-o', tex => '-t', nroff => '-n', html => '-H');
foreach (sort keys %ds) {
    my $out = "test_data/test_deformatters.$_.out";
    my $expected  = "test_data/test_deformatters.$_.expected";
    system "./ispell -a -d languages/test_dict/test_dict.hash $ds{$_} <$in >$out";

    # We die for not being able to run the command - but not for any
    # exit status or signals.
    #
    die "could not run ./ispell: $!" if $!;

    system('diff', '-qs', $expected, $out)
      && die "diff $expected $out failed\n";
    unlink $out or die "cannot unlink $out: $!";
}
