Skip to content

Commit

Permalink
add iuwandbox test
Browse files Browse the repository at this point in the history
  • Loading branch information
srz-zumix committed Apr 11, 2017
1 parent 2013177 commit d940b45
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 16 deletions.
2 changes: 2 additions & 0 deletions tools/docker/Dockerfile
Expand Up @@ -29,6 +29,8 @@ RUN pyenv local 3.6.0 && \
pyenv local --unset
RUN pyenv local 2.7.13 3.5.2 3.6.0

RUN pip install virtualenv

ADD Dockerfile /data
RUN git clone https://github.com/srz-zumix/iutest.git /iutest

Expand Down
31 changes: 22 additions & 9 deletions tools/wandbox/iuwandbox.py
Expand Up @@ -35,7 +35,7 @@ def parse_command_line():
'-v',
'--version',
action='version',
version=u'%(prog)s version 5.2'
version=u'%(prog)s version 5.3'
)
parser.add_argument(
'--list_compiler',
Expand Down Expand Up @@ -276,6 +276,10 @@ def make_code(path, encoding, expand, includes, included_files):
return code


def print_undefined_option(option, compiler):
print('Wandbox is not supported option [{0}] ({1})'.format(opt, compiler))


# check config
def check_config(options):
has_error = False
Expand All @@ -288,11 +292,11 @@ def check_config(options):
if options.options:
for o in options.options.split(','):
if o not in opt:
print('Wandbox is not supported option [{0}] ({1})'.format(o, options.compiler))
print_undefined_option(o, options.compiler)
has_error = True
if options.std:
if options.std not in opt:
print('Wandbox is not supported option [{0}] ({1})'.format(options.std, options.compiler))
print_undefined_option(options.std, options.compiler)
has_error = True
if has_error:
listup_options(options.compiler)
Expand Down Expand Up @@ -512,6 +516,15 @@ def wandbox_hint(r):
print(' If you do not use boost test, please specify the file with the main function first.')


def byte_to_str(value):
try:
if isinstance(value, bytes):
return value.decode('utf_8')
except:
pass
return value


# show result
def show_result(r, options):
if 'error' in r:
Expand All @@ -520,21 +533,21 @@ def show_result(r, options):
if options.stderr:
if 'compiler_output' in r:
print('compiler_output:')
print(r['compiler_output'].encode('utf_8'))
print(byte_to_str(r['compiler_output']))
if 'compiler_error' in r:
sys.stderr.write(r['compiler_error'].encode('utf_8'))
sys.stderr.write(byte_to_str(r['compiler_error']))
if 'program_output' in r:
print('program_output:')
print(r['program_output'].encode('utf_8'))
print(byte_to_str(r['program_output']))
if options.xml is None and options.junit is None and 'program_error' in r:
sys.stderr.write(r['program_error'].encode('utf_8'))
sys.stderr.write(byte_to_str(r['program_error']))
else:
if 'compiler_message' in r:
print('compiler_message:')
print(r['compiler_message'].encode('utf_8'))
print(byte_to_str(r['compiler_message']))
if 'program_message' in r:
print('program_message:')
print(r['program_message'].encode('utf_8'))
print(byte_to_str(r['program_message']))
if 'url' in r:
print('permlink: ' + r['permlink'])
print('url: ' + r['url'])
Expand Down
2 changes: 1 addition & 1 deletion tools/wandbox/setup.py
Expand Up @@ -6,7 +6,7 @@
#readme = f.read()
#f.close()

VERSION = "5.2"
VERSION = "5.3"

setup(
name = "iuwandbox"
Expand Down
Empty file added tools/wandbox/tests/__init__.py
Empty file.
7 changes: 7 additions & 0 deletions tools/wandbox/tests/src/A/sample.cpp
@@ -0,0 +1,7 @@
#include "../../../../../include/iutest.hpp"
#include "sample.h"

IUTEST(A, Bar)
{
IUTEST_ASSERT_EQ(42, f());
}
2 changes: 2 additions & 0 deletions tools/wandbox/tests/src/A/sample.h
@@ -0,0 +1,2 @@

inline int f() { return 42; }
7 changes: 7 additions & 0 deletions tools/wandbox/tests/src/B/sample.cpp
@@ -0,0 +1,7 @@
#include "../../../../../include/iutest.hpp"
#include "sample.h"

IUTEST(B, Bar)
{
IUTEST_ASSERT_EQ(1, f());
}
2 changes: 2 additions & 0 deletions tools/wandbox/tests/src/B/sample.h
@@ -0,0 +1,2 @@

inline int f() { return 1; }
7 changes: 7 additions & 0 deletions tools/wandbox/tests/src/main.cpp
@@ -0,0 +1,7 @@
#include "../../../../include/iutest.hpp"

int main(int argc, char** argv)
{
IUTEST_INIT(&argc, argv);
return IUTEST_RUN_ALL_TESTS();
}
31 changes: 30 additions & 1 deletion tools/wandbox/tests/test_iuwandbox.py
Expand Up @@ -3,6 +3,8 @@
# test_iuwandbox.py
#

from __future__ import print_function

import sys
import os
sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/../../fused')
Expand All @@ -26,16 +28,31 @@
test_opt_nomain = [ '--encoding', 'utf-8-sig' ]
test_opt = [ '--encoding', 'utf-8-sig', '-f"-DIUTEST_USE_MAIN"' ]


def eprint(*args, **kwargs):
print(*args, file=sys.stderr, **kwargs)


class iuwandbox_test_base(unittest.TestCase):
dir = None

def setUp(self):
self.capture = StringIO()
sys.stdout = self.capture
self.dir = os.getcwd()
os.chdir(os.path.dirname(os.path.abspath(__file__)))
return super(iuwandbox_test_base, self).setUp()

def tearDown(self):
sys.stdout = sys.__stdout__
os.chdir(self.dir)
self.capture.close()
return super(iuwandbox_test_base, self).tearDown()

def dump(self):
value = self.capture.getvalue()
eprint(value)


class nofused_iuwandbox_test(iuwandbox_test_base):
def setUp(self):
Expand All @@ -48,6 +65,7 @@ def test_nofused(self):
sys.argv.extend(test_opt)
with self.assertRaises(SystemExit) as cm:
iuwandbox.main()
self.dump()
self.assertEqual(cm.exception.code, 1, self.capture.getvalue())
self.assertRegex(self.capture.getvalue(), '.*please try \"make fused\".*')

Expand All @@ -63,6 +81,7 @@ def test_nomain(self):
sys.argv.extend(test_opt_nomain)
with self.assertRaises(SystemExit) as cm:
iuwandbox.main()
self.dump()
self.assertEqual(cm.exception.code, 1, self.capture.getvalue())
self.assertRegex(self.capture.getvalue(), '.*hint:.*')
self.assertRegex(self.capture.getvalue(), '.*If you do not use boost test, please specify the file with the main function first..*')
Expand All @@ -72,8 +91,18 @@ def test_run(self):
sys.argv.extend(test_opt)
with self.assertRaises(SystemExit) as cm:
iuwandbox.main()
self.dump()
self.assertEqual(cm.exception.code, 0, self.capture.getvalue())
self.assertRegex(self.capture.getvalue(), '.*OK.*')

def test_same_filename(self):
sys.argv[1:] = [ 'src/main.cpp', 'src/A/sample.cpp', 'src/B/sample.cpp' ]
sys.argv.extend(test_opt_nomain)
with self.assertRaises(SystemExit) as cm:
iuwandbox.main()
self.dump()
self.assertEqual(cm.exception.code, 0, self.capture.getvalue())
self.assertRegex(self.capture.getvalue(), '.*OK.*')

if __name__ == "__main__":
unittest.main()
unittest.main()
2 changes: 1 addition & 1 deletion tools/wandbox/tox.ini
Expand Up @@ -2,7 +2,7 @@
envlist = py27, py36

[testenv]
changedir=test
changedir=tests
deps=unittest2
commands=unit2 discover []

Expand Down
4 changes: 0 additions & 4 deletions tox.ini
@@ -1,10 +1,6 @@
[tox]
skipsdist=True

[testenv]
changedir=tools/wandbox
commands=tox

[flake8]
ignore = E265
max-line-length = 100

0 comments on commit d940b45

Please sign in to comment.