Hardware-Vhdl-Tidy

 view release on metacpan or  search on metacpan

t/tidy_commandline.t  view on Meta::CPAN

    t <= al-foo;
#endif
    q <= t + bar * x;
end
  process
  ;
-- etc",
});
}

for my $switches ( [qw( -b -bext backup )] ) {
test_tidy_commandline ({
	test_description => 'tidy_commandline with switches '.join(' ', @$switches), 
	switches => $switches,
    inplace => 1,
    ext => 'backup',
	vhdl =>
"--process
process
begin
    wait on foo;
#if SIMULATING==1
    t <= al-foo*5;
#else
    t <= al-foo;
#endif
    q <= t + bar * x;
end
  process
  ;
-- etc",
});
}

sub slurp {
    my $fh = shift;
    local $/;
    return <$fh>;
}

sub test_tidy_commandline {
	my $args = shift;
	my $infile = 'test_in.vhd';

	my ($correct_tidy_ref, $untidy_ref) = create_tidy_test($args->{vhdl});

	# write $vhdl_in to a file
	{
		my $fh;
		open $fh, '>', $infile || die $!;
        binmode $fh;
		print $fh @{$untidy_ref};
		close $fh;
	}

	# open new temp. for output
	my $fho = tempfile;
    #open $fho, '+>', 'test_out.vhd' || die $!;
    binmode $fho;
	{
		local @ARGV = (@{$args->{switches}}, $infile);
        open my $oldout, '>&STDOUT' or die "Can't dup STDOUT: $!";
		my $restore_old_fh = AtExit->new( sub { open STDOUT, ">&", $oldout or die "Can't dup \$oldout: $!"; } );
        open STDOUT, '>&', $fho or die "Can't redirect STDOUT: $!";
        select STDOUT; $| = 1;      # make unbuffered
		Hardware::Vhdl::Tidy::parse_commandline();
        $restore_old_fh = undef;
	}
    if ($args->{inplace}) {
        seek $fho, 0, 2; # go to the end of the output file so that we can find out how much output there was
        is(tell $fho, 0, $args->{test_description}.': nothing written to STDOUT');
        $fho = undef;
        
        open $fho, '<', $infile. $args->{ext} || die $!;
        binmode $fho;
        my $input_backup = [readline $fho];
        ok(compare_indentation($untidy_ref, $input_backup), $args->{test_description}.': backup file');
        $fho = undef;

        open $fho, '<', $infile || die $!;
        binmode $fho;
    }
    else {
        seek $fho, 0, 0; # go to the start of the output file so that we can read it all
    }
	my $tidy_output = [readline $fho];
	close $fho;
	ok(compare_indentation($correct_tidy_ref, $tidy_output), $args->{test_description});
}



( run in 1.700 second using v1.01-cache-2.11-cpan-800906f7e73 )