Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

first test framework for noscript

  • Loading branch information...
commit 5522b25906d532eb0f39f158b62a7475360e0f8c 1 parent 82d2e6b
Josep M. Bach authored

Showing 2 changed files with 76 additions and 39 deletions. Show diff stats Hide diff stats

  1. +52 14 kernel/test.ns
  2. +24 25 test/kernel/test_test.rb
66 kernel/test.ns
... ... @@ -1,17 +1,55 @@
1   -Test = Object.clone()
  1 +TestCase = Object.clone({
  2 + setup: ->; end,
  3 + teardown: ->; end,
2 4
3   -Test.assert = -> value
4   - if value != true
5   - raise('Expected true, got #{value}.')
6   - else
7   - true
8   - end
9   -end
  5 + errors: [],
  6 +
  7 + tests: 0,
  8 + assertions: 0,
  9 + failures: 0,
  10 +
  11 + assert: -> value
  12 + if value != false
  13 + print('\e[32m.')
  14 + else
  15 + print('\e[31mF')
  16 + @errors.push('Expected #{value} to be truthy.')
  17 + @failures = @failures + 1
  18 + end
  19 + @assertions = @assertions + 1
  20 + end,
  21 +
  22 + assert equal: -> expected, actual
  23 + if expected == actual
  24 + print('\e[32m.')
  25 + else
  26 + print('\e[31mF')
  27 + @errors.push('Expected #{expected}, got #{actual}.')
  28 + @failures = @failures + 1
  29 + end
  30 + @assertions = @assertions + 1
  31 + end,
  32 +
  33 + print report: ->
  34 + puts('\n\n\e[0m#{@tests} tests, #{@assertions} assertions, #{@failures} failures')
  35 + puts(' Failure report:')
  36 + @errors.each(-> error
  37 + puts(' * #{error}')
  38 + end)
  39 + end,
  40 +
  41 + run: ->
  42 + @setup()
  43 +
  44 + @each(-> name, test
  45 + if name.starts with('it')
  46 + test()
  47 + @tests = @tests + 1
  48 + end
  49 + end)
  50 +
  51 + @teardown()
10 52
11   -Test.assert equal = -> expected, actual
12   - if expected != actual
13   - raise('Expected #{expected}, got #{actual}.')
14   - else
15   - true
  53 + @print report()
16 54 end
17   -end
  55 +})
49 test/kernel/test_test.rb
@@ -2,41 +2,40 @@
2 2
3 3 class TestTest < MiniTest::Unit::TestCase
4 4
5   - def test_assert_returns_true
  5 + def test_test
6 6 code = <<-CODE
7   - foo = true
8   - Test.assert(foo)
9   -CODE
10 7
11   - assert_equal Noscript::AST::True.new, compiles(code)
12   - end
  8 + MyTestCase = TestCase.clone({
13 9
14   - def test_assert_raises
15   - code = <<-CODE
16   - foo = false
17   - Test.assert(foo)
18   -CODE
  10 + setup: ->
  11 + @foo = 'bar'
  12 + end,
19 13
20   - assert_raises Noscript::AST::Exception do
21   - compiles(code)
22   - end
23   - end
  14 + it does foo things: ->
  15 + @assert equal(@foo, 'bar')
  16 + end,
24 17
25   - def test_assert_equal_returns_true
26   - code = <<-CODE
27   - Test.assert equal(1, 1)
28   -CODE
  18 + it does bar things: ->
  19 + @assert(true)
  20 + end,
29 21
30   - assert_equal Noscript::AST::True.new, compiles(code)
31   - end
  22 + it can fail too: ->
  23 + @assert(false)
  24 + end,
32 25
33   - def test_assert_equal_raises
34   - code = <<-CODE
35   - Test.assert equal(3, 2)
  26 + teardown: ->
  27 + @foo = nil
  28 + end
  29 +
  30 + })
  31 +
  32 + MyTestCase.run()
36 33 CODE
37 34
38   - assert_raises Noscript::AST::Exception do
  35 + expected = "\e[32m.\e[32m.\e[31mF\n\n\e[0m3 tests, 3 assertions, 1 failures\n Failure report:\n * Expected false to be truthy.\n"
  36 + assert_output expected do
39 37 compiles(code)
40 38 end
41 39 end
  40 +
42 41 end

0 comments on commit 5522b25

Please sign in to comment.
Something went wrong with that request. Please try again.