summaryrefslogtreecommitdiff
path: root/check.py
blob: 55ffab9b106a753b353cc045c3349caacd1f64bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/env python

import os, subprocess, difflib

print 'checking testcases...\n'

for asm in os.listdir('test'):
  if asm.endswith('.asm.js'):
    print '  ', asm, ' ',
    wasm = asm.replace('.asm.js', '.wast')
    actual, err = subprocess.Popen([os.path.join('bin', 'asm2wasm'), os.path.join('test', asm)], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
    assert err == '', 'bad err:' + err
    if not os.path.exists(os.path.join('test', wasm)):
      raise Exception('output .wast file does not exist')
    expected = open(os.path.join('test', wasm)).read()
    if actual != expected:
      raise Exception("Expected to have '%s' == '%s', diff:\n\n%s" % (
        expected, actual,
        limit_size(''.join([a.rstrip()+'\n' for a in difflib.unified_diff(x.split('\n'), y.split('\n'), fromfile='expected', tofile='actual')]))
      ))
    print 'OK'

print '\nsuccess!'