把代码写成 inline-test 形式
/cc @liuyq @grant-s-z @yh-chen20
令 test.scm 为
(let ((environment (top-level-environment '(mit inline-testing))))
(link-variables system-global-environment 'run-inline-tests
environment 'run-inline-tests))
(run-inline-tests "arithmatic.scm")
令 arithmatic.scm 为
(+ 2 2) '(expect eqv? 4)
运行
$ echo '(load "test.scm")' | mit-scheme
MIT/GNU Scheme running under GNU/Linux
Type `^C' (control-C) followed by `H' to obtain information about interrupts.
Copyright (C) 2022 Massachusetts Institute of Technology
This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Image saved on Wednesday January 11, 2023 at 11:12:18 PM
Release 12.1 || SF || LIAR/x86-64
1 ]=>
;Loading "test.scm"...
; Loading "/usr/lib/x86_64-linux-gnu/mit-scheme/libraries/inline-testing.comld"... done
;;; Ran 1 test: 0 failures
;... done
;Value: #t
1 ]=>
End of input stream reached.
Post proelium, praemium.
这样就测试了 2+2=4,我们把代码的 define 部分和运行的部分分开。 define 部分用来其它程序引用,而运行部分写成 test。