Batch-Interpreter

 view release on metacpan or  search on metacpan

lib/Batch/Interpreter/TestSupport.pm  view on Meta::CPAN

package Batch::Interpreter::TestSupport;

=head1 NAME

Batch::Interpreter::TestSupport - support code for testing Batch::Interpreter

=head1 SYNOPSIS

The output of runbat is compared with the output of CMD.EXE. On systems with CMD.EXE the batch files can be run with CMD.EXE to store the expected output. The switch --complete combines both steps.

=head1 METHODS

=cut

use v5.10;
use warnings;
use strict;
use parent 'Exporter';
our @EXPORT_OK = qw(
	get_test_attr compare_output
	read_file
);

our $VERSION = 0.01;

use Getopt::Long;
use Test::More;
use Test::Differences;
use Data::Dump qw(dump);
use File::Spec;
use File::Temp;
use Cwd;

=head2 ->get_test_attr()

Read C<@ARGV> to generate a C<$test_attr> HashRef, that is returned for (possibly modified) use in ->compare_output().

=cut
sub get_test_attr {
	my ($record, $compare, $complete);
	my $dump;
	my $verbose;
	my $help;
	GetOptions(
		'record' => \$record,
		'compare' => \$compare,
		'complete' => \$complete,
		'dump' => \$dump,
		'verbose!' => \$verbose,
		'help|h|?!' => \$help,
	);
	if ($help) {
		say <<"EOH";
usage: $0 [--record|--compare|--complete] [--dump] [--[no-]verbose] [--help|-h|-?] [-- <runbat arguments>]

	--record
		Run the test script with the system shell and store the	output.
		Only available under Win32.
	--compare
		Run the test script with runbat and compare the output.
		This is the default.
	--complete
		First --record, then --compare.

	--dump	Dump the outputs before comparison.

	--verbose
		Be verbose.

	--help
		This help.
EOH
		exit 1;
	}
	my $mode = $complete ? 'record,compare'
		: $record ? 'record'
		: 'compare';
	return {
		mode => $mode,
		dump => $dump,
		argv => [ @ARGV ],
		verbose => $verbose,
		number => 0,
	};
}

# TODO: use a prepackaged implementation
sub quote_argument {



( run in 0.646 second using v1.01-cache-2.11-cpan-39bf76dae61 )