Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 159 lines (144 sloc) 3.195 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
# -*- coding: utf-8 -*-

# assuming these executables are in PATH.
# memo: 'spidermonkey' is a symlink to my local spidermonkey build.
JS_EXECUTABLES = %w[rhino spidermonkey]
COMMON_JS_EXECUTABLES = %w[node narwhal]

JS_TESTS = %w[js]
COMMON_JS_TESTS = %w[commonjs]

SAMPLE_DIR = File.expand_path(File.join(File.dirname(__FILE__), '..', 'sample'))
def on_dir(name, &blk)
  Dir.chdir(File.join(SAMPLE_DIR, name)) do
    blk.call
  end
end


describe 'Engine Compatibility' do

  js_expected = <<-EOS
# module: math module
# test: add
ok 1
ok 2
ok 3 - passing 3 args
ok 4 - just one arg
ok 5 - no args
not ok 6 - expected: '7' got: '1'
not ok 7 - with message, expected: '7' got: '1'
ok 8
ok 9 - with message
not ok 10
not ok 11 - with message
# module: incr module
# test: increment
ok 12
ok 13
# module: TAP spec compliance
# test: Diagnostic lines
ok 14 - with\r
# multiline
# message
not ok 15 - with\r
# multiline
# message, expected: 'foo\r
# bar' got: 'foo
# bar'
not ok 16 - with\r
# multiline
# message, expected: 'foo
# bar' got: 'foo\r
# bar'
1..16
EOS

  JS_TESTS.product(JS_EXECUTABLES).each do |test, command|
    context "#{test} test on #{command}" do
      before do
        on_dir(test) do
          @output = `#{command} run_tests.js`
        end
      end
      subject { @output }
      it { should == js_expected }
    end
  end

  JS_TESTS.product(["./phantomjs_test.sh"]).each do |test, command|
    context "#{test} test on #{command}" do
      before do
        on_dir(test) do
          @output = `#{command}`
        end
      end
      subject { @output }
      it { should == js_expected }
    end
  end

  commonjs_math_expected = <<-EOS
# module: math module
# test: add
ok 1
ok 2
ok 3 - passing 3 args
ok 4 - just one arg
ok 5 - no args
not ok 6 - expected: '7' got: '1'
not ok 7 - with message, expected: '7' got: '1'
ok 8
ok 9 - with message
not ok 10
not ok 11 - with message
1..11
EOS

  commonjs_incr_expected = <<-EOS
# module: incr module
# test: increment
ok 1
ok 2
1..2
EOS

  commonjs_tap_compliance_expected = <<-EOS
# module: TAP spec compliance
# test: Diagnostic lines
ok 1 - with\r
# multiline
# message
not ok 2 - with\r
# multiline
# message, expected: 'foo\r
# bar' got: 'foo
# bar'
not ok 3 - with\r
# multiline
# message, expected: 'foo
# bar' got: 'foo\r
# bar'
1..3
EOS


  COMMON_JS_TESTS.product(COMMON_JS_EXECUTABLES).each do |test, command|
    context "#{test} test on #{command}" do
      context "math" do
        before do
          on_dir(test) do
            @output = `#{command} test/math_test.js`
          end
        end
        subject { @output }
        it { should == commonjs_math_expected }
      end
      context "incr" do
        before do
          on_dir(test) do
            @output = `#{command} test/incr_test.js`
          end
        end
        subject { @output }
        it { should == commonjs_incr_expected }
      end
      context "TAP spec compliance" do
        before do
          on_dir(test) do
            @output = `#{command} test/tap_compliance_test.js`
          end
        end
        subject { @output }
        it { should == commonjs_tap_compliance_expected }
      end
    end
  end

end
Something went wrong with that request. Please try again.