-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintegration_test.py
More file actions
79 lines (64 loc) · 2.54 KB
/
integration_test.py
File metadata and controls
79 lines (64 loc) · 2.54 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
import pexpect
import pexpect.replwrap as replwrap
import unittest
import os
# the vtscript executable
cmd = './vtscript'
# the prompt to expect
prompt = u'vtscript>'
class TestREPL(unittest.TestCase):
def setUp(self):
self.wrapper = replwrap.REPLWrapper(cmd, prompt, None)
def test_add(self):
output = self.wrapper.run_command(u'(+ 1 2)')
self.assertEqual(output.strip(), "(3)")
output = self.wrapper.run_command(u'(+ 1 2 10)')
self.assertEqual(output.strip(), "(13)")
output = self.wrapper.run_command(u'(+ 1 2 0)')
self.assertEqual(output.strip(), "(3)")
output = self.wrapper.run_command(u'(+ 0 1 2)')
self.assertEqual(output.strip(), "(3)")
output = self.wrapper.run_command(u'(+ 1 2 -2)')
self.assertEqual(output.strip(), "(1)")
output = self.wrapper.run_command(u'(+ -1 -2)')
self.assertEqual(output.strip(), "(-3)")
def test_define(self):
output = self.wrapper.run_command(u'(define a True)')
self.assertEqual(output.strip(), "(True)")
output = self.wrapper.run_command(u'(define b a)')
self.assertEqual(output.strip(), "(True)")
output = self.wrapper.run_command(u'(and a b)')
self.assertEqual(output.strip(), "(True)")
def test_conditional(self):
self.wrapper.run_command(u'(define a -1)')
self.wrapper.run_command(u'(define b 1)')
self.wrapper.run_command(u'(define c 0)')
output = self.wrapper.run_command(u'(if (< a b) c False)')
self.assertEqual(output.strip(), "(0)")
def test_error(self):
output = self.wrapper.run_command(u'(define begin True)')
self.assertTrue(output.strip().startswith('Error'))
class TestExecuteCommandline(unittest.TestCase):
def test_sub(self):
args = ' -e ' + ' "(- 4 2)" '
(output, retcode) = pexpect.run(cmd+args, withexitstatus=True, extra_args=args)
self.assertEqual(retcode, 0)
self.assertEqual(output.strip(), b"(2)")
def test_error(self):
args = ' -e ' + ' "(- 4 2 12)" '
(output, retcode) = pexpect.run(cmd+args, withexitstatus=True, extra_args=args)
self.assertNotEqual(retcode, 0)
self.assertTrue(output.strip().startswith(b'Error'))
class TestExecuteFromFile(unittest.TestCase):
def test_sub(self):
args = ' /vagrant/tests/test3.vts'
(output, retcode) = pexpect.run(cmd+args, withexitstatus=True, extra_args=args)
self.assertEqual(retcode, 0)
self.assertEqual(output.strip(), b"(2)")
def test_error(self):
args = ' /there/is/no/such/file'
(output, retcode) = pexpect.run(cmd+args, withexitstatus=True, extra_args=args)
self.assertNotEqual(retcode, 0)
self.assertTrue(output.strip().startswith(b'Error'))
# run the tests
unittest.main()