Add userlib tests

Document userlib in readme
extend example configuration to include userlib
This commit is contained in:
Ava Apples Affine 2023-03-17 13:24:31 -07:00
parent 1ee9ba55fb
commit 34e77903a6
Signed by: affine
GPG key ID: 3A4645B8CF806069
5 changed files with 64 additions and 11 deletions

View file

@ -1,9 +1,12 @@
;; comment out to load USERLIB
;; (load (concat HOME "/.relish/userlib.rls"))
(def CFG_RELISH_POSIX
"my job control preference"
"1")
;; if you have userlib
;; (set CFG_RELISH_POSIX "1")
;; else
(def CFG_RELISH_POSIX
(get-doc (q CFG_RELISH_POSIX))
"1")
(echo "Welcome back to relish.")
(echo "Enjoy your computing.")

View file

@ -0,0 +1,43 @@
;; this file implements unit tests for handwritten userlib functions
(def passed
'prints if a test has passed'
(test)
(echo (concat "PASSED: " test)))
(def failed
'prints if a test has failed'
(test)
(echo (concat "FAILED: " test)))
(def test-cases 'all test cases'
(('set updates var'
(quote
(let ((test-val 0))
(set test-val 3)
(eq? test-val 3))))
('prepend prepends to list'
(quote
(let ((list (2 3 4))
(list (prepend 1 list))
(list-head (head list)))
(eq? (car list-head) 1))))
;; add more test cases here
))
(def test-iter 'iterates over test cases'
(head test-cases))
;; run all test cases, print output
(while (gt? (len (cdr test-iter))
0)
(let ((test (car test-iter))
(remaining (cdr test-iter))
(test-name (car test))
(test-body (cdr test)))
(if (eval test-body)
(passed test-name)
(failed test-name))
(def test-iter '' (head remaining))))

View file

@ -13,7 +13,7 @@
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;
;; USERLIB
;; This file contains a plethora of useful features that are not shipped in the STL