Skip to content

Commit

Permalink
add a run_test utility to run an individual test. Fix all tests so th…
Browse files Browse the repository at this point in the history
…at the test suite actually runs (but several tests fail)
  • Loading branch information
Whiteknight committed Mar 22, 2010
1 parent 878a834 commit b697c2c
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 33 deletions.
2 changes: 1 addition & 1 deletion t/pmc/fixedpmcqueue.t
@@ -1,6 +1,6 @@
#! parrot-nqp

class Test::FixedPMCQueue is Pds::TestCase::FixedQueue;
class Test::FixedPMCQueue is Pds::Testcase::FixedQueue;

INIT {
use('UnitTest::Testcase');
Expand Down
2 changes: 1 addition & 1 deletion t/pmc/fixedpmcstack.t
@@ -1,6 +1,6 @@
#! parrot-nqp

class Test::FixedPMCStack is Pds::TestCase::FixedStack;
class Test::FixedPMCStack is Pds::Testcase::FixedStack;

INIT {
use('UnitTest::Testcase');
Expand Down
2 changes: 1 addition & 1 deletion t/pmc/resizablepmcqueue.t
@@ -1,6 +1,6 @@
#! parrot-nqp

class Test::ResizablePMCQueue is Pds::TestCase::ResizableQueue;
class Test::ResizablePMCQueue is Pds::Testcase::ResizableQueue;

INIT {
use('UnitTest::Testcase');
Expand Down
2 changes: 1 addition & 1 deletion t/pmc/resizablepmcstack.t
@@ -1,6 +1,6 @@
#! parrot-nqp

class Test::ResizablePMCStack is Pds::TestCase::ResizableStack;
class Test::ResizablePMCStack is Pds::Testcase::ResizableStack;

INIT {
use('UnitTest::Testcase');
Expand Down
2 changes: 1 addition & 1 deletion t/pmc/resizablepmcstack2.t
@@ -1,6 +1,6 @@
#! parrot-nqp

class Test::ResizablePMCStack2 is Pds::TestCase::ResizableStack;
class Test::ResizablePMCStack2 is Pds::Testcase::ResizableStack;

INIT {
use('UnitTest::Testcase');
Expand Down
27 changes: 27 additions & 0 deletions t/run_test
@@ -0,0 +1,27 @@
#! parrot-nqp

INIT {
pir::load_bytecode('./library/kakapo_full.pbc');
Nqp::compile_file('t/testlib/common.nqp');
pir::loadlib__ps("./dynext/pds_group");
}

class MyProgram is Program {
method main(*@args) {
for @args {
my $test := $_;
my $sub := Nqp::compile_file("t/pmc/" ~ $test);
$sub[0]();
}
}
}

INIT {
Program::instance(
MyProgram.new( :from_parrot )
);
}

Program::instance().run;


6 changes: 3 additions & 3 deletions t/sanity.t
Expand Up @@ -9,11 +9,11 @@ INIT {

MAIN();
sub MAIN() {
my $proto := Opcode::get_root_global(pir::get_namespace__P().get_name);
$proto.suite.run;
my $proto := Opcode::get_root_global(pir::get_namespace__P().get_name);
$proto.suite.run;
}

method test_load_pds_group() {
my $pla := pir::loadlib__ps(""./dynext/pds_group"");
my $pla := pir::loadlib__ps("./dynext/pds_group");
assert_not_instance_of($pla, "Undef", "Cannot load PDS library, pds_group");
}
74 changes: 49 additions & 25 deletions t/testlib/common.nqp
@@ -1,3 +1,9 @@

INIT {
use('UnitTest::Testcase');
use('UnitTest::Assertions');
}

class Pds::Testcase is UnitTest::Testcase {
method is_resizable() {
return (0);
Expand All @@ -9,6 +15,23 @@ class Pds::Testcase is UnitTest::Testcase {
).throw;
}

method set_integer($f, $x) {
Q:PIR {
$P0 = find_lex '$f'
$P1 = find_lex '$x'
$I0 = $P1
$P0 = $I0
}
}
method push_pmc($f, $x) {
Q:PIR {
$P0 = find_lex '$f'
$P1 = find_lex '$x'
push $P0, $P1
}
}

has @!roles;

##### TEST METHODS #####
Expand Down Expand Up @@ -53,11 +76,11 @@ class Pds::Testcase is UnitTest::Testcase {

method test_METHOD_to_array() {
my $f := self.create();
if (!self.is_resizable) { pir::set__PI($f, 5); }
pir::push__PP($f, 1);
pir::push__PP($f, 2);
pir::push__PP($f, 3);
pir::push__PP($f, 4);
if (!self.is_resizable) { self.set_integer($f, 5); }
self.push_pmc($f, 1);
self.push_pmc($f, 2);
self.push_pmc($f, 3);
self.push_pmc($f, 4);
my $a := $f.to_array();
if (self.is_resizable) {
assert_instance_of($a, "ResizablePMCArray", "Incorrect array type");
Expand All @@ -82,9 +105,9 @@ class Pds::Testcase::Stack is Pds::Testcase {
method test_VTABLE_elements() {
my $f := self.create();

if (!self.is_resizable) { pir::set__PI($f, 5); }
if (!self.is_resizable) { self.set_integer($f, 5); }

pir::push__PP($f, pir::box__PI(1));
self.push_pmc($f, pir::box__PI(1));
assert_equal(pir::elements__IP($f), 1, "pushing doesn't give us an element");

pir::pop__PP($f);
Expand All @@ -94,16 +117,16 @@ class Pds::Testcase::Stack is Pds::Testcase {
method test_VTABLE_push_pmc_SANITY() {
assert_throws_nothing("push_pmc throws something", {
my $f := self.create();
if (!self.is_resizable) { pir::set__PI($f, 5); }
pir::push__PP($f, pir::box__PI(1));
if (!self.is_resizable) { self.set_integer($f, 5); }
self.push_pmc($f, pir::box__PI(1));
});
}

method test_VTABLE_pop_pmc() {
my $f := self.create();
if (!self.is_resizable) { pir::set__PI($f, 5); }
if (!self.is_resizable) { self.set_integer($f, 5); }
my $i := pir::box__PI(1);
pir::push__PP($f, $i);
self.push_pmc($f, $i);
my $j := pir::pop__PP($f);
assert_same($i, $j, "push/pop returns the same PMC");
}
Expand All @@ -113,10 +136,10 @@ class Pds::Testcase::Stack is Pds::Testcase {
assert_false($f, "empty struct is not false");

if (!self.is_resizable) {
pir::set__PI($f, 5);
self.set_integer($f, 5);
assert_false($f, "allocation does not change truth value");
}
pir::push__PP($f, pir::box__PI(1));
self.push_pmc($f, pir::box__PI(1));
assert_true($f, "non-empty struct is not true");

pir::shift__PP($f);
Expand All @@ -129,7 +152,7 @@ class Pds::Testcase::FixedStack is Pds::Testcase::Stack {
method test_VTABLE_set_integer_native_SANITY() {
assert_throws_nothing("Cannot set_integer_native", {
my $f := self.create();
pir::set__PI($f, 5);
self.set_integer($f, 5);
});
}

Expand All @@ -139,7 +162,7 @@ class Pds::Testcase::FixedStack is Pds::Testcase::Stack {
my $s := pir::typeof__SP($f);
assert_equal($i, 0, "new $s is allocated");

pir::set__PI($f, 5);
self.set_integer($f, 5);
$i := pir::set__IP($f);
assert_equal($i, 5, "does not have proper allocated storage");
}
Expand All @@ -162,25 +185,26 @@ class Pds::Testcase::Queue is Pds::Testcase {
method test_VTABLE_push_pmc() {
assert_throws_nothing("push_pmc throws something", {
my $f := self.create();
if (!self.is_resizable) { pir::set__PI($f, 5); }
pir::push__PP($f, pir::box__PI(1));
if (!self.is_resizable) { self.set_integer($f, 5); }
self.push_pmc($f, pir::box__PI(1));
});
}

method test_VTABLE_shift_pmc() {
my $f := self.create();
if (!self.is_resizable) { pir::set__PI($f, 5); }
pir::push__PP($f, pir::box__PI(1));
if (!self.is_resizable) { self.set_integer($f, 5); }
my $i := pir::box__PI(1);
self.push_pmc($f, $i);
my $j := pir::shift__PP($f);
assert_equal($i, $j, "push/shift is destructive");
}

method test_VTABLE_elements() {
my $f := self.create();
if (!self.is_resizable) { pir::set__PI($f, 5); }
if (!self.is_resizable) { self.set_integer($f, 5); }
assert_equal(pir::elements__IP($f), 0, "new FPQ is not empty");

pir::push__PP($f, pir::box__PI(1));
self.push_pmc($f, pir::box__PI(1));
assert_equal(pir::elements__IP($f), 1, "non-empty FPQ is empty");

pir::shift__PP($f);
Expand All @@ -191,10 +215,10 @@ class Pds::Testcase::Queue is Pds::Testcase {
my $f := self.create();
assert_false($f, "empty queue is not false");
if (!self.is_resizable) {
pir::set__PI($f, 5);
self.set_integer($f, 5);
assert_false($f, "allocation does not change truth value");
}
pir::push__PP($f, pir::box__PI(1));
self.push_pmc($f, pir::box__PI(1));
assert_true($f, "non-empty queue is not true");

pir::shift__PP($f);
Expand All @@ -207,15 +231,15 @@ class Pds::Testcase::FixedQueue is Pds::Testcase::Queue {
method test_VTABLE_set_integer_native() {
assert_throws_nothing("set_integer_native throws", {
my $f := Parrot::new("FixedPMCQueue");
pir::set__PI($f, 5);
self.set_integer($f, 5);
});
}

method test_VTABLE_get_integer() {
my $f := Parrot::new("FixedPMCQueue");
assert_equal(int($f), 0, "empty FPQ does not have zero size");

pir::set__PI($f, 5);
self.set_integer($f, 5);
assert_equal(int($f), 5, "cannot get reading of allocated storage");
}
}
Expand Down

0 comments on commit b697c2c

Please sign in to comment.