1269000a789c — Duncan Ross Palmer 1 year, 2 months ago
Use sut slot in tester framework
1 files changed, 15 insertions(+), 10 deletions(-)

M t/raw2c.pl
M t/raw2c.pl +15 -10
@@ 12,14 12,21 @@ use Test::Output;
 
 extends 'Test::Module::Runnable';
 
+sub setUp {
+	my ($self) = @_;
+
+	$self->sut(Main->new());
+
+	return EXIT_SUCCESS;
+}
+
 sub testStrings {
+	my ($self) = @_;
 	plan tests => 3;
 
-	my $sut = Main->new();
+	stdout_is { $self->sut->title() } "raw2c by Duncan Ross Palmer\n", 'title';
 
-	stdout_is { $sut->title() } "raw2c by Duncan Ross Palmer\n", 'title';
-
-	stdout_is { $sut->syntax() }
+	stdout_is { $self->sut->syntax() }
 		"Syntax: [-q] [-n] [--symbol=__symbol] <binary_file> <source_file>[.c]\n" .
 		"-q disables non-critical output\n" .
 		"-n adds a NULL terminator\n" .

          
@@ 29,7 36,7 @@ sub testStrings {
 	, 'syntax';
 
 	is(
-		$sut->getHead(),
+		$self->sut->getHead(),
 		"/*\n  This file was autogenerated by raw2c, by Duncan Ross Palmer.\n  Visit http://www.daybologic.co.uk\n*/\n\n",
 		'getHead'
 	);

          
@@ 38,21 45,19 @@ sub testStrings {
 }
 
 sub testRandom {
-	#my ($self) = @_;
+	my ($self) = @_;
 	plan tests => 2;
 
-	my $sut = Main->new();
-
 	my %chars = ( );
 	do {
-		my $char = $sut->randChar();
+		my $char = $self->sut->randChar();
 		$chars{$char} = $char if ($char eq '0' || $char eq 'q' || $char eq 'Z' || $char eq '_');
 	} while (scalar(keys(%chars)) < 4);
 
 	cmp_ok(scalar(keys(%chars)), '==', 4, 'randChar');
 
 	srand(0); # Predictable symbol
-	my $randomSymbol = $sut->randomSymbol();
+	my $randomSymbol = $self->sut->randomSymbol();
 	my $expect = '__rawimage_aL6SANHnTKsmKgoMRAJ5';
 	is($randomSymbol, $expect, "Generated expected symbol: '$expect'");