Skip to content

Commit

Permalink
Create REPL at the TestCase setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Affonso-Gui committed Aug 4, 2020
1 parent dce7aa4 commit f8ff3ae
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
6 changes: 0 additions & 6 deletions tests/eus9-27_slime2-20.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ class eus(EuslimeTestCase):
EUSLISP_PROGRAM = 'eus'
EUSLISP_PROGRAM_NAME = 'eus'

# CREATE-REPL
def test_001_create_repl(self):
self.assertSocket(
'(:emacs-rex (swank-repl:create-repl nil :coding-system "utf-8-unix") "COMMON-LISP-USER" t 4)',
'(:return (:ok ("USER" "{}")) 4)'.format(self.EUSLISP_PROGRAM_NAME))

# LISTENER-EVAL
def test_eval_1(self):
self.assertSocket(
Expand Down
17 changes: 17 additions & 0 deletions tests/euslime_test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ def setUpClass(self):
self.socket.connect((host, port))
# Wait for process to fully start
time.sleep(1)
# Create REPL
log.info('Creating REPL...')
req = '(:emacs-rex (swank-repl:create-repl nil :coding-system "utf-8-unix") "COMMON-LISP-USER" t 4)'
res = ('(:return (:ok ("USER" "{}")) 4)'.format(self.EUSLISP_PROGRAM_NAME),)
response = self.socket_get_response(req, 1)
log.debug('expected response: \n%s', pprint.pformat(res, width=5))
log.debug('received response: \n%s', pprint.pformat(response, width=5))
if res != response:
raise Exception('REPL Initialization Failed')

log.info('Initialization Complete.')
log.info('Starting testing...')

@classmethod
def tearDownClass(self):
Expand All @@ -47,6 +59,7 @@ def __del__(self):
except Exception:
pass

@classmethod
def socket_recv_one(self, *options):
try:
len = self.socket.recv(HEADER_LENGTH, *options)
Expand All @@ -55,6 +68,7 @@ def socket_recv_one(self, *options):
except socket.error:
return

@classmethod
def socket_recv(self, times):
result = []
for i in range(times):
Expand All @@ -64,14 +78,17 @@ def socket_recv(self, times):
result.append(res)
return tuple(result) or None

@classmethod
def socket_clean(self):
while self.socket_recv_one(socket.MSG_DONTWAIT):
pass

@classmethod
def socket_send(self, req):
header = '{0:06x}'.format(len(req))
self.socket.send(header + req)

@classmethod
def socket_get_response(self, req, n):
log.info('request: \n%s', req)
# self.socket_clean()
Expand Down
4 changes: 4 additions & 0 deletions tests/euslime_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
# ./euslime_tests.py irteusgl
# ./euslime_tests.py roseus

## RUN A SINGLE TEST
# ./euslime_tests.py eus.test_eval_1


from euslime.logger import set_log_level
import unittest

Expand Down

0 comments on commit f8ff3ae

Please sign in to comment.