Skip to content

Commit f1b2bcf

Browse files
committed
Adds the exit primitive and directly introduces it into the primitive test runner
1 parent 1c9dd51 commit f1b2bcf

File tree

4 files changed

+23
-14
lines changed

4 files changed

+23
-14
lines changed

ports-js/scheme.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,11 @@ function addGlobals(env) {
289289
env.set(Sym('boolean?'), x => typeof x === 'boolean');
290290
env.set(Sym('pair?'), isPair);
291291

292-
292+
// System operations
293293
env.set(Sym('display'), (...args) => {
294294
process.stdout.write(args.map((ea) => asString(ea)).join(''));
295295
});
296+
env.set(Sym('exit'), (code = 0) => process.exit(code));
296297

297298
return env;
298299
}

ports-py/lispy.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import threading
1212
from functools import reduce
1313
from fractions import Fraction
14+
import sys
1415

1516
class Symbol(str): pass
1617

@@ -264,7 +265,8 @@ def add_globals(self):
264265
'open-output-file':lambda f:open(f,'w'), 'close-output-port':lambda p: p.close(),
265266
'eof-object?':lambda x:x is eof_object, 'read-char':readchar,
266267
'read':read, 'write':lambda x,port=sys.stdout:port.write(to_string(x)),
267-
'display':lambda x:print(x if isa(x,str) else to_string(x), end="",flush=True)})
268+
'display':lambda x:print(x if isa(x,str) else to_string(x), end="",flush=True),
269+
'exit':lambda code: sys.exit(code)})
268270
return self
269271

270272
isa = isinstance

ports/ports.scm

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -195,15 +195,14 @@
195195
(define (data-test-data data-test) (list-ref data-test 4))
196196

197197
(define (test-run-with-result test)
198-
(with-exception-handler
199-
(lambda (e)
200-
(if (is-assertion-error? e)
201-
(test-result test 'failure e)
202-
(test-result test 'error e))
203-
(raise e))
204-
(lambda ()
205-
(test-run test)
206-
(test-result test 'success '()))))
198+
(with-exception-handler
199+
(lambda (e)
200+
(if (is-assertion-error? e)
201+
(test-result test 'failure e)
202+
(test-result test 'error e)))
203+
(lambda ()
204+
(test-run test)
205+
(test-result test 'success '()))))
207206

208207
; Setup/tearDown
209208
;
@@ -253,11 +252,17 @@
253252
((tests (capability-all-tests root-capability)))
254253
(let
255254
((selected-tests (select-tests tests only-tests only-capabilities exclude-tests exclude-capabilities)))
256-
(display-test-results
255+
(let
256+
((test-results
257257
(map
258258
(lambda (test)
259259
(let ((test-result (test-run-with-result test)))
260260
(display (short-hand-test-result test-result))
261261
test-result))
262-
selected-tests)))))
262+
selected-tests)))
263+
(display-test-results test-results)
264+
(if (any?
265+
(lambda (test-result) (or (is-failure? test-result) (is-error? test-result)))
266+
test-results)
267+
(exit 1))))))
263268
)

ports/spec.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,13 @@ PorTS does not support hygenic macros, as we expect macros to be almost exclusiv
4141
- null?
4242
- symbol?
4343
- boolean?
44-
- display
44+
- display (Should not print newline after the string)
4545
- not
4646
- +, -, *, /
4747
- >, <, >=, <=, =
4848
- abs
4949
- length
50+
- exit
5051
<!-- - apply? -->
5152

5253
<!--

0 commit comments

Comments
 (0)