Navigation Menu

Skip to content

Commit

Permalink
refactor tests to be more explicit like ruby
Browse files Browse the repository at this point in the history
  • Loading branch information
ingydotnet committed Mar 30, 2013
1 parent c260d09 commit 8908819
Show file tree
Hide file tree
Showing 26 changed files with 64 additions and 54 deletions.
3 changes: 1 addition & 2 deletions lib/TestML/Runtime.pm
Expand Up @@ -5,16 +5,15 @@ has testml => ();
has bridge => ();
has library => ();
has compiler => ();
has base => ();
has skip => ();

has function => ();
has error => ();
has global => ();
has base => ();

sub BUILD {
my ($self) = @_;
# Put current Runtime singleton object into a global variable.
$TestML::Runtime::Singleton = $self;
$self->{base} ||= $0 =~ m!(.*)/! ? $1 : ".";
}
Expand Down
18 changes: 9 additions & 9 deletions lib/TestML/Runtime/TAP.pm
Expand Up @@ -5,7 +5,7 @@ package TestML::Runtime::TAP;
use TestML::Base;
extends 'TestML::Runtime';

has test_framework => sub { Test::Builder->new };
has tap_object => sub { Test::Builder->new };
has planned => 0;

sub run {
Expand Down Expand Up @@ -35,31 +35,31 @@ sub title {
if (my $title = $self->function->getvar('Title')) {
$title = $title->value;
$title = "=== $title ===\n";
$self->test_framework->note($title);
$self->tap_object->note($title);
}
}

sub skip_test {
my ($self, $reason) = @_;
$self->test_framework->plan(skip_all => $reason);
$self->tap_object->plan(skip_all => $reason);
}

sub plan_begin {
my ($self) = @_;
if (my $tests = $self->function->getvar('Plan')) {
$self->test_framework->plan(tests => $tests->value);
$self->tap_object->plan(tests => $tests->value);
}
}

sub plan_end {
my ($self) = @_;
$self->test_framework->done_testing();
$self->tap_object->done_testing();
}

# TODO Use Test::Diff here.
sub assert_EQ {
my ($self, $got, $want) = @_;
$self->test_framework->is_eq(
$self->tap_object->is_eq(
$got->str->value,
$want->str->value,
$self->get_label,
Expand All @@ -78,14 +78,14 @@ Failed TestML HAS (~~) assertion. This text:
does not contain this string:
'$has'
...
$self->test_framework->diag($msg);
$self->tap_object->diag($msg);
}
$self->test_framework->ok($assertion, $self->get_label);
$self->tap_object->ok($assertion, $self->get_label);
}

sub assert_OK {
my ($self, $got) = @_;
$self->test_framework->ok(
$self->tap_object->ok(
$got->bool->value,
$self->get_label,
);
Expand Down
2 changes: 2 additions & 0 deletions lib/TestML/Setup.pm
Expand Up @@ -45,6 +45,8 @@ sub setup {
}
if ($template) {
(my $test = $file) =~ s/\.tml$/.t/;
$test = $conf->{test_file_prefix} . $test
if $conf->{test_file_prefix};
$test = abs_path "$tests/$test";
my $hash = {
file => $self->rel($t, $base),
Expand Down
File renamed without changes.
34 changes: 17 additions & 17 deletions t/compile.t
Expand Up @@ -16,28 +16,28 @@ use TestML::Compiler::Pegex;
use TestML::Compiler::Lite;
use YAML::XS;

test('t/testml/arguments.tml', 'TestML::Compiler::Pegex');
test('t/testml/assertions.tml', 'TestML::Compiler::Pegex');
test('t/testml/basic.tml', 'TestML::Compiler::Pegex');
test('t/testml/dataless.tml', 'TestML::Compiler::Pegex');
test('t/testml/exceptions.tml', 'TestML::Compiler::Pegex');
test('t/testml/external.tml', 'TestML::Compiler::Pegex');
test('t/testml/function.tml', 'TestML::Compiler::Pegex');
test('t/testml/label.tml', 'TestML::Compiler::Pegex');
test('t/testml/markers.tml', 'TestML::Compiler::Pegex');
test('t/testml/semicolons.tml', 'TestML::Compiler::Pegex');
test('t/testml/truth.tml', 'TestML::Compiler::Pegex');
test('t/testml/types.tml', 'TestML::Compiler::Pegex');
test('testml/arguments.tml', 'TestML::Compiler::Pegex');
test('testml/assertions.tml', 'TestML::Compiler::Pegex');
test('testml/basic.tml', 'TestML::Compiler::Pegex');
test('testml/dataless.tml', 'TestML::Compiler::Pegex');
test('testml/exceptions.tml', 'TestML::Compiler::Pegex');
test('testml/external.tml', 'TestML::Compiler::Pegex');
test('testml/function.tml', 'TestML::Compiler::Pegex');
test('testml/label.tml', 'TestML::Compiler::Pegex');
test('testml/markers.tml', 'TestML::Compiler::Pegex');
test('testml/semicolons.tml', 'TestML::Compiler::Pegex');
test('testml/truth.tml', 'TestML::Compiler::Pegex');
test('testml/types.tml', 'TestML::Compiler::Pegex');

test('t/testml/arguments.tml', 'TestML::Compiler::Lite');
test('t/testml/basic.tml', 'TestML::Compiler::Lite');
test('t/testml/exceptions.tml', 'TestML::Compiler::Lite');
test('t/testml/semicolons.tml', 'TestML::Compiler::Lite');
test('testml/arguments.tml', 'TestML::Compiler::Lite');
test('testml/basic.tml', 'TestML::Compiler::Lite');
test('testml/exceptions.tml', 'TestML::Compiler::Lite');
test('testml/semicolons.tml', 'TestML::Compiler::Lite');

sub test {
my ($file, $compiler) = @_;
(my $filename = $file) =~ s!(.*)/!!;
my $runtime = TestML::Runtime->new(base => $1);
my $runtime = TestML::Runtime->new(base => "t/$1");
my $testml = $runtime->read_testml_file($filename);
my $ast1 = $compiler->new->compile($testml);
my $yaml1 = Dump($ast1);
Expand Down
2 changes: 1 addition & 1 deletion t/inline.t
@@ -1,4 +1,4 @@
use lib 't/lib';
use lib 't';
use TestML;
use TestMLBridge;

Expand Down
2 changes: 1 addition & 1 deletion t/standard.t
@@ -1,4 +1,4 @@
use lib 't/lib';
use lib 't';
use TestML;
use TestMLBridge;

Expand Down
6 changes: 3 additions & 3 deletions t/testml-lite.yaml
@@ -1,17 +1,17 @@
source_testml_dir: ../../testml-tml
local_testml_dir: ./testml
test_file_template: |
use lib 't/lib';
use lib 't';
use TestML;
use TestML::Compiler::Lite;
use TestMLBridge;
TestML->new(
testml => '../[% file %]',
testml => '[% file %]',
bridge => 'TestMLBridge',
compiler => 'TestML::Compiler::Lite',
)->run;
test_file_dir: lite
test_file_prefix: testml_lite_
include_testml_files:
- arguments.tml
- basic.tml
Expand Down
3 changes: 2 additions & 1 deletion t/testml.yaml
@@ -1,14 +1,15 @@
source_testml_dir: ../../testml-tml
local_testml_dir: ./testml
test_file_template: |
use lib 't/lib';
use lib 't';
use TestML;
use TestMLBridge;
TestML->new(
testml => '[% file %]',
bridge => 'TestMLBridge',
)->run;
test_file_prefix: testml_
exclude_testml_files:
- comments.tml
- data.tml
Expand Down
2 changes: 1 addition & 1 deletion t/arguments.t → t/testml_arguments.t
@@ -1,4 +1,4 @@
use lib 't/lib';
use lib 't';
use TestML;
use TestMLBridge;

Expand Down
2 changes: 1 addition & 1 deletion t/assertions.t → t/testml_assertions.t
@@ -1,4 +1,4 @@
use lib 't/lib';
use lib 't';
use TestML;
use TestMLBridge;

Expand Down
2 changes: 1 addition & 1 deletion t/basic.t → t/testml_basic.t
@@ -1,4 +1,4 @@
use lib 't/lib';
use lib 't';
use TestML;
use TestMLBridge;

Expand Down
2 changes: 1 addition & 1 deletion t/dataless.t → t/testml_dataless.t
@@ -1,4 +1,4 @@
use lib 't/lib';
use lib 't';
use TestML;
use TestMLBridge;

Expand Down
2 changes: 1 addition & 1 deletion t/exceptions.t → t/testml_exceptions.t
@@ -1,4 +1,4 @@
use lib 't/lib';
use lib 't';
use TestML;
use TestMLBridge;

Expand Down
2 changes: 1 addition & 1 deletion t/external.t → t/testml_external.t
@@ -1,4 +1,4 @@
use lib 't/lib';
use lib 't';
use TestML;
use TestMLBridge;

Expand Down
2 changes: 1 addition & 1 deletion t/function.t → t/testml_function.t
@@ -1,4 +1,4 @@
use lib 't/lib';
use lib 't';
use TestML;
use TestMLBridge;

Expand Down
2 changes: 1 addition & 1 deletion t/label.t → t/testml_label.t
@@ -1,4 +1,4 @@
use lib 't/lib';
use lib 't';
use TestML;
use TestMLBridge;

Expand Down
4 changes: 2 additions & 2 deletions t/lite/basic.t → t/testml_lite_arguments.t
@@ -1,10 +1,10 @@
use lib 't/lib';
use lib 't';
use TestML;
use TestML::Compiler::Lite;
use TestMLBridge;

TestML->new(
testml => '../testml/basic.tml',
testml => 'testml/arguments.tml',
bridge => 'TestMLBridge',
compiler => 'TestML::Compiler::Lite',
)->run;
4 changes: 2 additions & 2 deletions t/lite/arguments.t → t/testml_lite_basic.t
@@ -1,10 +1,10 @@
use lib 't/lib';
use lib 't';
use TestML;
use TestML::Compiler::Lite;
use TestMLBridge;

TestML->new(
testml => '../testml/arguments.tml',
testml => 'testml/basic.tml',
bridge => 'TestMLBridge',
compiler => 'TestML::Compiler::Lite',
)->run;
4 changes: 2 additions & 2 deletions t/lite/semicolons.t → t/testml_lite_exceptions.t
@@ -1,10 +1,10 @@
use lib 't/lib';
use lib 't';
use TestML;
use TestML::Compiler::Lite;
use TestMLBridge;

TestML->new(
testml => '../testml/semicolons.tml',
testml => 'testml/exceptions.tml',
bridge => 'TestMLBridge',
compiler => 'TestML::Compiler::Lite',
)->run;
4 changes: 2 additions & 2 deletions t/lite/exceptions.t → t/testml_lite_semicolons.t
@@ -1,10 +1,10 @@
use lib 't/lib';
use lib 't';
use TestML;
use TestML::Compiler::Lite;
use TestMLBridge;

TestML->new(
testml => '../testml/exceptions.tml',
testml => 'testml/semicolons.tml',
bridge => 'TestMLBridge',
compiler => 'TestML::Compiler::Lite',
)->run;
2 changes: 1 addition & 1 deletion t/markers.t → t/testml_markers.t
@@ -1,4 +1,4 @@
use lib 't/lib';
use lib 't';
use TestML;
use TestMLBridge;

Expand Down
2 changes: 1 addition & 1 deletion t/semicolons.t → t/testml_semicolons.t
@@ -1,4 +1,4 @@
use lib 't/lib';
use lib 't';
use TestML;
use TestMLBridge;

Expand Down
8 changes: 8 additions & 0 deletions t/testml_standard.t
@@ -0,0 +1,8 @@
use lib 't';
use TestML;
use TestMLBridge;

TestML->new(
testml => 'testml/standard.tml',
bridge => 'TestMLBridge',
)->run;
2 changes: 1 addition & 1 deletion t/truth.t → t/testml_truth.t
@@ -1,4 +1,4 @@
use lib 't/lib';
use lib 't';
use TestML;
use TestMLBridge;

Expand Down
2 changes: 1 addition & 1 deletion t/types.t → t/testml_types.t
@@ -1,4 +1,4 @@
use lib 't/lib';
use lib 't';
use TestML;
use TestMLBridge;

Expand Down

0 comments on commit 8908819

Please sign in to comment.