Skip to content

Commit

Permalink
Add support for 'include' and move Test.rb into the Test module.
Browse files Browse the repository at this point in the history
  • Loading branch information
tene committed May 18, 2009
1 parent 107cc3f commit 0ccc552
Show file tree
Hide file tree
Showing 72 changed files with 232 additions and 146 deletions.
78 changes: 78 additions & 0 deletions Test.rb
@@ -0,0 +1,78 @@
module Test
$testnum = 1
$failed = 0
$planned = 0
$started = 0
$todo_upto = 0
$todo_reason

def plan(num)
print '1..',num,"\n"
$started = 1
$testnum = 1
$planned = num
end

def pass(desc='')
proclaim(1,desc)
end

def flunk(desc='')
proclaim(0,desc)
end

def ok(cond,desc='')
proclaim(cond, desc)
end

def nok(cond,desc='')
if cond then
flunk desc
else
pass desc
end
end

def is(got,expected,desc='')
proclaim(got == expected, desc)
end

def isgt(got,expected,desc='')
proclaim(got > expected, desc)
end

def isge(got,expected,desc='')
proclaim(got >= expected, desc)
end

def isnt(got,expected,desc='')
proclaim(got != expected, desc)
end

def todo(reason,count=1)
$todo_upto = $testnum + count
$todo_reason = '# TODO ' + reason
end

def skip(reason='',count=1)
1.upto(count) { proclaim(1,'# SKIP ' + reason) }
end

def skip_rest(reason='')
skip(reason,$planned - $testnum)
end

def proclaim(cond,desc)
if cond then
else
print "n"
$failed += 1 if $todo_upto < $testnum
end
print 'ok ', $testnum, ' - ', desc
$testnum += 1
if $todo_reason and $todo_upto < $testnum then
print $todo_reason
end
puts
end
end
6 changes: 3 additions & 3 deletions build/Makefile.in
Expand Up @@ -30,7 +30,7 @@ PCT = $(BUILD_DIR)/runtime/parrot/library/PCT.pbc

PMC_DIR = src/pmc

all: cardinal.pbc test.pir cardinal$(EXE)
all: cardinal.pbc Test.pir cardinal$(EXE)

CARDINAL_GROUP = $(PMC_DIR)/cardinal_group$(LOAD_EXT)

Expand Down Expand Up @@ -86,8 +86,8 @@ installable_cardinal$(EXE): cardinal.pbc
cardinal.pbc: $(PARROT) $(SOURCES)
$(PARROT) $(PARROT_ARGS) -o cardinal.pbc cardinal.pir

test.pir: $(PARROT) test.rb cardinal.pbc
$(PARROT) $(PARROT_ARGS) cardinal.pbc --target=pir --output=test.pir test.rb
Test.pir: $(PARROT) Test.rb cardinal.pbc
$(PARROT) $(PARROT_ARGS) cardinal.pbc --target=pir --output=Test.pir Test.rb

src/gen_grammar.pir: $(PERL6GRAMMAR) src/parser/grammar.pg
$(PARROT) $(PARROT_ARGS) $(PERL6GRAMMAR) \
Expand Down
15 changes: 15 additions & 0 deletions src/builtins/eval.pir
Expand Up @@ -112,6 +112,21 @@ such as C<eval>, C<require>, and C<use>.
.return (result)
.end

.sub 'include'
.param pmc module
.local pmc it, item, callerns
$P0 = getinterp
callerns = $P0['namespace';1]
it = new 'Iterator', module
it_loop:
unless it goto it_loop_end
$S0 = shift it
item = module[$S0]
callerns[$S0] = item
goto it_loop
it_loop_end:
.end


.sub 'load'
.param string file
Expand Down
3 changes: 2 additions & 1 deletion t/02-functions.t
@@ -1,4 +1,5 @@
require 'test'
require 'Test'
include Test

plan 7

Expand Down
3 changes: 2 additions & 1 deletion t/05-op-cmp.t
@@ -1,4 +1,5 @@
require 'test'
require 'Test'
include Test
plan 12

ok 1 < 2, '<';
Expand Down
3 changes: 2 additions & 1 deletion t/07-loops.t
@@ -1,4 +1,5 @@
require 'test'
require 'Test'
include Test
plan 12

i = 1
Expand Down
3 changes: 2 additions & 1 deletion t/09-test.t
@@ -1,4 +1,5 @@
require 'test'
require 'Test'
include Test

plan 3

Expand Down
3 changes: 2 additions & 1 deletion t/10-regex.t
@@ -1,4 +1,5 @@
require 'test'
require 'Test'
include Test
plan 3

ok "foo" =~ /oo/, 'basic regex matching'
Expand Down
3 changes: 2 additions & 1 deletion t/11-slurpy.t
@@ -1,4 +1,5 @@
require 'test'
require 'Test'
include Test
plan 4

def foo(*n)
Expand Down
3 changes: 2 additions & 1 deletion t/12-gather.t
@@ -1,4 +1,5 @@
require 'test'
require 'Test'
include Test
plan 4

items = gather do
Expand Down
3 changes: 2 additions & 1 deletion t/99-other.t
@@ -1,4 +1,5 @@
require 'test'
require 'Test'
include Test
plan 8

n = 5
Expand Down
3 changes: 2 additions & 1 deletion t/alias.t
@@ -1,4 +1,5 @@
require 'test'
require 'Test'
include Test
plan 2

class NumberHolder
Expand Down
3 changes: 2 additions & 1 deletion t/array/array.t
@@ -1,4 +1,5 @@
require 'test'
require 'Test'
include Test
plan 10

a = [ 1, 2, 3, 4 ]
Expand Down
3 changes: 2 additions & 1 deletion t/array/clear.t
@@ -1,4 +1,5 @@
require 'test'
require 'Test'
include Test
plan 8

a = Array.new()
Expand Down
3 changes: 2 additions & 1 deletion t/array/collect.t
@@ -1,4 +1,5 @@
require 'test'
require 'Test'
include Test
plan 2

a = [ "a", "b", "c", "d" ]
Expand Down
3 changes: 2 additions & 1 deletion t/array/empty.t
@@ -1,4 +1,5 @@
require 'test'
require 'Test'
include Test
plan 2

a = [ 1, 2 ]
Expand Down
3 changes: 2 additions & 1 deletion t/array/equals.t
@@ -1,4 +1,5 @@
require 'test'
require 'Test'
include Test
plan 2

a = [ 1, 2, 3 ]
Expand Down
3 changes: 2 additions & 1 deletion t/array/fill.t
@@ -1,4 +1,5 @@
require 'test'
require 'Test'
include Test
plan 4

a = Array.new(2)
Expand Down
3 changes: 2 additions & 1 deletion t/array/grep.t
@@ -1,4 +1,5 @@
require 'test'
require 'Test'
include Test
plan 1


Expand Down
3 changes: 2 additions & 1 deletion t/array/include.t
@@ -1,4 +1,5 @@
require 'test'
require 'Test'
include Test
plan 6

a = [ 1, 2 ]
Expand Down
3 changes: 2 additions & 1 deletion t/array/intersection.t
@@ -1,4 +1,5 @@
require 'test'
require 'Test'
include Test
plan 6

a = [ 0, 1, 2, 3, 4, 5, 6 ]
Expand Down
3 changes: 2 additions & 1 deletion t/array/mathop.t
@@ -1,4 +1,5 @@
require 'test'
require 'Test'
include Test
plan 10

a = [ 1, 2 ]
Expand Down
3 changes: 2 additions & 1 deletion t/array/sort.t
@@ -1,4 +1,5 @@
require 'test'
require 'Test'
include Test
plan 8

a = [ 2, 1, 3 ]
Expand Down
3 changes: 2 additions & 1 deletion t/array/to_s.t
@@ -1,4 +1,5 @@
require 'test'
require 'Test'
include Test
plan 1

a = [ 1, 2 ]
Expand Down
3 changes: 2 additions & 1 deletion t/array/uniq.t
@@ -1,4 +1,5 @@
require 'test'
require 'Test'
include Test
plan 6

a = [ 1, 1, 2, 2, 3, 3, 1, 2, 3, 1, 2, 3]
Expand Down
3 changes: 2 additions & 1 deletion t/array/warray.t
@@ -1,4 +1,5 @@
require 'test'
require 'Test'
include Test
plan 3

a = %w{ fe fi fo }
Expand Down
3 changes: 2 additions & 1 deletion t/assignment.t
@@ -1,4 +1,5 @@
require 'test'
require 'Test'
include Test
plan 4

a = 1
Expand Down
3 changes: 2 additions & 1 deletion t/blocks.t
@@ -1,4 +1,5 @@
require 'test'
require 'Test'
include Test
plan 4

1.upto(2) { |x| is x, x, 'curly brace block' }
Expand Down
3 changes: 2 additions & 1 deletion t/constants.t
@@ -1,4 +1,5 @@
require 'test'
require 'Test'
include Test
plan 2

is RUBY_PLATFORM, 'parrot', 'RUBY_PLATORM'
Expand Down
3 changes: 2 additions & 1 deletion t/continuation.t
@@ -1,4 +1,5 @@
require 'test'
require 'Test'
include Test
plan 4

k = 0
Expand Down
3 changes: 2 additions & 1 deletion t/file/dir.t
@@ -1,4 +1,5 @@
require 'test'
require 'Test'
include Test
plan 4

d = Dir.new('.')
Expand Down
3 changes: 2 additions & 1 deletion t/file/file.t
@@ -1,4 +1,5 @@
require 'test'
require 'Test'
include Test
plan 12


Expand Down
3 changes: 2 additions & 1 deletion t/file/stat.t
@@ -1,4 +1,5 @@
require 'test'
require 'Test'
include Test
plan 20

# need a better test for these things. this shows that we at least can parse and execute these commands
Expand Down
3 changes: 2 additions & 1 deletion t/freeze.t
@@ -1,4 +1,5 @@
require 'test'
require 'Test'
include Test
plan 1

class NumberHolder
Expand Down
3 changes: 2 additions & 1 deletion t/gc.t
@@ -1,4 +1,5 @@
require 'test'
require 'Test'
include Test
plan 4


Expand Down
3 changes: 2 additions & 1 deletion t/hash/hash.t
@@ -1,4 +1,5 @@
require 'test'
require 'Test'
include Test
plan 5

a = { "a" => "ok", "b" => 1}
Expand Down
3 changes: 2 additions & 1 deletion t/integer/integer.t
@@ -1,4 +1,5 @@
require 'test'
require 'Test'
include Test
plan 51

# add a test against the expected class type when we get .class worked out better
Expand Down
3 changes: 2 additions & 1 deletion t/integer/times.t
@@ -1,4 +1,5 @@
require 'test'
require 'Test'
include Test
plan 5
j = 0
5.times do |i|
Expand Down
3 changes: 2 additions & 1 deletion t/kernel/exit.t
@@ -1,4 +1,5 @@
require 'test'
require 'Test'
include Test
plan 1

pass '.exit! on Kernel'
Expand Down
3 changes: 2 additions & 1 deletion t/kernel/open.t
@@ -1,4 +1,5 @@
require 'test'
require 'Test'
include Test
plan 2

pipe = open("| echo *.t")
Expand Down
3 changes: 2 additions & 1 deletion t/kernel/sprintf.t
@@ -1,4 +1,5 @@
require 'test'
require 'Test'
include Test
plan 11

Kernel.printf("%s %d %s\n", 'ok', 1, '- .printf() on Kernel')
Expand Down
3 changes: 2 additions & 1 deletion t/math/functions.t
@@ -1,4 +1,5 @@
require 'test'
require 'Test'
include Test
plan 3


Expand Down

0 comments on commit 0ccc552

Please sign in to comment.