forked from DGNum/liminix
anoia: add assert macro module
contains expect and expect=
This commit is contained in:
parent
0f0688c802
commit
7e19d80130
4 changed files with 37 additions and 9 deletions
9
pkgs/anoia/Makefile
Normal file
9
pkgs/anoia/Makefile
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
|
||||||
|
default: fs.lua init.lua nl.lua svc.lua
|
||||||
|
|
||||||
|
test:
|
||||||
|
ln -s . anoia
|
||||||
|
fennel test.fnl
|
||||||
|
|
||||||
|
%.lua: %.fnl
|
||||||
|
fennel --compile $< > $@
|
21
pkgs/anoia/assert.fnl
Normal file
21
pkgs/anoia/assert.fnl
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
;; these are macros; this module should be imported
|
||||||
|
;; using import-macros
|
||||||
|
|
||||||
|
;; e.g. (import-macros { : expect= } :anoia.assert)
|
||||||
|
|
||||||
|
|
||||||
|
(fn expect [assertion]
|
||||||
|
(let [msg (.. "expectation failed: " (view assertion))]
|
||||||
|
`(when (not ,assertion)
|
||||||
|
(assert false ,msg))))
|
||||||
|
|
||||||
|
(fn expect= [actual expected]
|
||||||
|
`(let [view# (. (require :fennel) :view)
|
||||||
|
ve# (view# ,expected)
|
||||||
|
va# (view# ,actual)]
|
||||||
|
(when (not (= ve# va#))
|
||||||
|
(assert false
|
||||||
|
(.. "\nexpected " ve# "\ngot " va#)
|
||||||
|
))))
|
||||||
|
|
||||||
|
{ : expect : expect= }
|
|
@ -10,11 +10,8 @@ in stdenv.mkDerivation {
|
||||||
src = ./.;
|
src = ./.;
|
||||||
nativeBuildInputs = [ fennel ];
|
nativeBuildInputs = [ fennel ];
|
||||||
buildInputs = with lua.pkgs; [ luafilesystem ];
|
buildInputs = with lua.pkgs; [ luafilesystem ];
|
||||||
buildPhase = ''
|
doCheck = true;
|
||||||
for f in *.fnl ; do
|
checkPhase = "make test";
|
||||||
fennel --compile $f > `basename $f .fnl`.lua
|
|
||||||
done
|
|
||||||
'';
|
|
||||||
installPhase = ''
|
installPhase = ''
|
||||||
mkdir -p "$out/share/lua/${lua.luaversion}/${pname}"
|
mkdir -p "$out/share/lua/${lua.luaversion}/${pname}"
|
||||||
cp *.lua "$out/share/lua/${lua.luaversion}/${pname}"
|
cp *.lua "$out/share/lua/${lua.luaversion}/${pname}"
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
(local { : hash : base64url } (require :anoia))
|
(local { : hash : base64url } (require :anoia))
|
||||||
|
(import-macros { : expect= } :anoia.assert)
|
||||||
|
|
||||||
(assert (= (hash "") 5381))
|
(expect= (hash "") 5381)
|
||||||
|
|
||||||
;; these examples from https://theartincode.stanis.me/008-djb2/
|
;; these examples from https://theartincode.stanis.me/008-djb2/
|
||||||
(assert (= (hash "Hello") 210676686969))
|
(expect= (hash "Hello") 210676686969)
|
||||||
(assert (= (hash "Hello!") 6952330670010))
|
(expect= (hash "Hello!") 6952330670010)
|
||||||
|
|
||||||
(assert (= (base64url "hello world") "aGVsbG8gd29ybGQ"))
|
(expect= (base64url "hello world") "aGVsbG8gd29ybGQ")
|
||||||
|
|
Loading…
Reference in a new issue