#! /usr/bin/env perl
#
#	Define an environment with two sub references as
#	construction variables.  Call each on the list of targets,
#	both separately and on the same line, dumping them to a
#	file.  Check that the output matches what we expect.
#

# $Id: t0057.t,v 1.3 2000/06/01 22:00:45 knight Exp $

# Copyright (c) 1996-2000 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING.  If not, write to
# the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.

use Test::Cmd::Cons;

$test = Test::Cmd::Cons->new(string => '%[ %] substitution');

#
$foo_1 = 'foo.1';
$foo_2 = 'foo.2';
$foo_3 = 'foo.3';

#
$test->write('Construct', <<_EOF_);
\%env_hash = ( ${\$test->cons_env} );
\$env_hash{X_COMMA} = sub { join(',', \@_) };
\$env_hash{X_HYPHEN} = sub { join('-', \@_) };
\$env = new cons ( \%env_hash );
Command \$env 'output', qw($foo_1 $foo_2 $foo_3), qq(
	\Q$^X\E -e "print '%<', \\\\"\\\\n\\\\"" >> %>
	\Q$^X\E -e "print '%[X_COMMA %< %]', \\\\"\\\\n\\\\"" >> %>
	\Q$^X\E -e "print '%[X_HYPHEN %< %]', \\\\"\\\\n\\\\"" >> %>
	\Q$^X\E -e "print '%[X_COMMA %< %] %[X_HYPHEN %< %]', \\\\"\\\\n\\\\"" >> %>
);
_EOF_

$test->write($foo_1, <<_EOF_);
This is the $foo_1 file.
_EOF_

$test->write($foo_2, <<_EOF_);
This is the $foo_2 file.
_EOF_

$test->write($foo_3, <<_EOF_);
This is the $foo_3 file.
_EOF_

#
$test->run(targets => ".");

$test->file_matches('output', <<_EOF_);
\Q$foo_1 $foo_2 $foo_3\E
\Q$foo_1,$foo_2,$foo_3\E
\Q$foo_1-$foo_2-$foo_3\E
\Q$foo_1,$foo_2,$foo_3\E \Q$foo_1-$foo_2-$foo_3\E
_EOF_

#
$test->pass;
__END__
