diff options
| author | Andrey Listopadov <andreyorst@gmail.com> | 2021-05-10 18:33:17 +0000 |
|---|---|---|
| committer | Andrey Listopadov <andreyorst@gmail.com> | 2021-05-10 18:33:17 +0000 |
| commit | 9ff783f512674e60add2ce71bd20745ff446f57f (patch) | |
| tree | ca9d6e464aff19fdf6141c21f6b87e5054aa76d3 | |
| parent | 9ff8b7069da390540168723ce110b92f6d17c6b0 (diff) | |
| parent | 3fee82f050e055ba7770a2b0135f2ebe4ee7b985 (diff) | |
Merge branch 'try-multi-value-return' into 'master'
Try multi value return
Closes #2
See merge request andreyorst/fennel-cljlib!10
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | .gitlab-ci.yml | 57 | ||||
| -rw-r--r-- | .luacov | 2 | ||||
| -rw-r--r-- | Makefile | 61 | ||||
| -rw-r--r-- | macros.fnl | 6 | ||||
| -rw-r--r-- | tests/macros.fnl | 14 |
6 files changed, 74 insertions, 67 deletions
@@ -1,2 +1,3 @@ *.lua luacov.* +coverage/* diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1b4ed46..e16aeb2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,39 +4,23 @@ stages: - test - coverage -cache: - paths: - - .cache - variables: GIT_SUBMODULE_STRATEGY: recursive + fennel_ver: 0.9.2 + fenneldoc_ver: v0.1.6 .install_fennel: &fennel |- - cd "$CI_PROJECT_DIR" - mkdir -p .cache - cd .cache - [ -d fennel ] || git clone -q https://git.sr.ht/~technomancy/fennel + cd "$HOME" + git clone -q --depth=1 --branch=0.9.2 https://git.sr.ht/~technomancy/fennel cd fennel || exit -1 - git checkout -q . - git checkout -q main - git pull -q --rebase - git checkout 0.8.1 - make clean make install cd "$CI_PROJECT_DIR" .install_fenneldoc: &fenneldoc |- - cd "$CI_PROJECT_DIR" - mkdir -p .cache - cd .cache - [ -d fenneldoc ] || git clone -q https://gitlab.com/andreyorst/fenneldoc.git + cd "$HOME" + git clone -q --depth=1 --branch="$fenneldoc_ver" \ + --recursive https://gitlab.com/andreyorst/fenneldoc.git cd fenneldoc || exit -1 - git checkout -q . - git checkout -q master - git pull -q --rebase - git checkout -q v0.1.5 - git submodule update --init - make clean make install cd "$CI_PROJECT_DIR" @@ -50,10 +34,19 @@ Lua: git make gcc musl-dev - luarocks-5.3 install luafilesystem - export LUA=lua5.3 - - *fennel + - luarocks-5.3 install fennel "$fennel_ver" + - luarocks-5.3 install luacov + - luarocks-5.3 install luacov-cobertura + - luarocks-5.3 install luacov-console - *fenneldoc script: - - LUA_EXECUTABLES="lua5.2 lua5.3 lua5.4" make testall >/dev/null + - LUAEXECUTABLES="lua5.2 lua5.3 lua5.4" make testall >/dev/null + - make luacov-console # doesn't use --correlate, more accurate + - make luacov # produces Cobertura XML + artifacts: + reports: + cobertura: coverage/cobertura-coverage.xml + coverage: '/Total.*\s(\d+.\d+%)$/' # Luajit actually is an impostor in Alpine, as the package actually # uses Moonjit implementation, which is different from what I'm @@ -67,17 +60,3 @@ Luajit: - *fennel script: - LUA=luajit make test - -# We install fennel via luarocks because I don't want to figure out -# how to install luacov without luarocks -Coverage: - image: alpine:3.12.1 - stage: coverage - before_script: - - apk add -q lua5.3 lua5.3-dev luarocks5.3 make gcc musl-dev - - luarocks-5.3 install fennel - - luarocks-5.3 install luacov - - luarocks-5.3 install luacov-console - script: - - LUA=lua5.3 make luacov-console >/dev/null - - luacov-console --no-colored -s @@ -3,7 +3,7 @@ -- see https://keplerproject.github.io/luacov/doc/modules/luacov.defaults.html return { - exclude = {"src/fennel/macros.fnl", ".cache/*"}, + exclude = {"macros%.fnl", "tests/.*", "luarocks/.*"}, runreport = true, statsfile = "luacov.stats"; reportfile = "luacov.report"; @@ -1,64 +1,79 @@ LUA ?= lua FENNEL ?= fennel +VERSION ?= $(shell git describe --abbrev=0) FNLSOURCES = init.fnl -LUASOURCES = $(FNLSOURCES:.fnl=.lua) -FNLTESTS = tests/fn.fnl tests/macros.fnl tests/core.fnl -FNLDOCS = init.fnl macros.fnl +FNLMACROS = macros.fnl +FNLTESTS = $(wildcard tests/*.fnl) LUATESTS = $(FNLTESTS:.fnl=.lua) -LUA_EXECUTABLES ?= lua luajit +FNLDOCS = $(FNLMACROS) $(FNLSOURCES) +LUASOURCES = $(FNLSOURCES:.fnl=.lua) +LUAEXECUTABLES ?= lua luajit FENNELDOC := $(shell command -v fenneldoc) +LUACOV_COBERTURA := $(shell command -v luacov-cobertura) +COMPILEFLAGS = --metadata -.PHONY: build clean distclean help test luacov luacov-console doc $(LUA_EXECUTABLES) +.PHONY: build clean distclean test luacov luacov-console doc help $(LUAEXECUTABLES) build: $(LUASOURCES) ${LUASOURCES}: $(FNLSOURCES) %.lua: %.fnl - $(FENNEL) --lua $(LUA) --compile $< > $@ + $(FENNEL) --lua $(LUA) $(COMPILEFLAGS) --compile $< > $@ clean: rm -f $(LUASOURCES) $(LUATESTS) distclean: clean - rm -f luacov* + rm -rf luacov* coverage test: $(FNLTESTS) @echo "Testing on" $$($(LUA) -v) >&2 - @$(foreach test,$?,$(FENNEL) --lua $(LUA) --metadata $(test) || exit;) + @$(foreach test,$?,$(FENNEL) --lua $(LUA) $(test) || exit;) ifdef FENNELDOC @fenneldoc --mode check $(FNLDOCS) || exit else - @echo "" + @echo "" >&2 @echo "fenneldoc is not installed" >&2 @echo "Please install fenneldoc to check documentation during testing" >&2 @echo "https://gitlab.com/andreyorst/fenneldoc" >&2 - @echo "" + @echo "" >&2 endif -testall: $(LUA_EXECUTABLES) +testall: $(LUAEXECUTABLES) @$(foreach lua,$?,LUA=$(lua) make test || exit;) -luacov: build $(LUATESTS) +luacov: COMPILEFLAGS = --no-metadata --correlate +luacov: distclean build $(LUATESTS) @$(foreach test,$(LUATESTS),$(LUA) -lluarocks.loader -lluacov $(test) || exit;) luacov +ifdef LUACOV_COBERTURA + mkdir -p coverage + luacov-cobertura -o coverage/cobertura-coverage.xml +endif -luacov-console: luacov - @$(foreach test, $(LUATESTS), mv $(test) $(test).tmp;) +luacov-console: COMPILEFLAGS = --no-metadata +luacov-console: clean build $(LUATESTS) + @$(foreach test,$(LUATESTS),$(LUA) -lluarocks.loader -lluacov $(test) || exit;) + luacov luacov-console . - @$(foreach test, $(LUATESTS), mv $(test).tmp $(test);) + luacov-console --no-colored -s doc: - fenneldoc $(FNLDOCS) +ifdef FENNELDOC + fenneldoc --project-version $(VERSION) --config $(FNLMACROS) $(FNLSOURCES) +else + @echo "" >&2 + @echo "fenneldoc is not installed" >&2 + @echo "Visit https://gitlab.com/andreyorst/fenneldoc for installation instructions" >&2 + @echo "" >&2 +endif help: @echo "make -- create lua library" >&2 - @echo "make doc -- generate documentation files (requires fenneldoc)" >&2 - @echo "make test -- run tests" >&2 @echo "make clean -- remove lua files" >&2 - @echo "make distclean -- remove all unnecessary files" >&2 - @echo "make luacov -- build coverage report" >&2 - @echo "make luacov-console -- build coverage report for luacov-console" >&2 + @echo "make distclean -- remove all files not necessary for the project" >&2 + @echo "make luacov -- run tests to produce luacov report" >&2 + @echo "make luacov-console -- run tests to produce luacov-console report" >&2 + @echo "make doc -- create documentation with fenneldoc" >&2 @echo "make help -- print this message and exit" >&2 - --include .depend.mk @@ -1116,7 +1116,7 @@ clauses when we push body epression." (table.insert try form)) (fn try [...] - (let [try '(fn []) + (let [try '(do) catches [] finally []] (each [_ form (ipairs [...])] @@ -1125,8 +1125,8 @@ clauses when we push body epression." (finally? form) (add-finally finally form) (add-to-try finally catches try form)) (add-to-try finally catches try form))) - `(match (pcall ,try) - (true _#) (do ,(. finally 1) _#) + `(match (pcall (fn [] ((or table.pack #(doto [$...] (tset :n (select :# $...)))) ,try))) + (true _#) (do ,(. finally 1) ((or table.unpack _G.unpack) _# 1 _#.n)) ,(make-catch-clauses catches finally)))) (attach-meta try {:fnl/arglist [:body* :catch-clause* :finally-clause?] diff --git a/tests/macros.fnl b/tests/macros.fnl index ec8aebd..2176f15 100644 --- a/tests/macros.fnl +++ b/tests/macros.fnl @@ -210,6 +210,7 @@ (assert-eq (try (+ 1 2 3) (catch _ 0) (finally 10)) 6) (assert-eq (try (+ 1 2 3 nil) (catch _ 0) (finally 10)) 0) (assert-eq (try (+ 1 2 3 nil) (catch _) (finally 10)) nil)) + (testing "catch-all" (assert-eq (try (error "10") @@ -219,6 +220,7 @@ (error [10]) (catch err err)) [10])) + (testing "finally" (let [tbl []] (try @@ -234,4 +236,14 @@ (catch _ (table.insert tbl 5)) (catch 20 (table.insert tbl 6)) (finally (table.insert tbl 7))) - (assert-eq tbl [1 2 3 4 5 7])))) + (assert-eq tbl [1 2 3 4 5 7]))) + + (testing "runtime error" + (assert-eq 0 (try + (/ 1 nil) + (catch _ 0)))) + + (testing "multi-value results" + (assert-eq 3 (select :# (try (values 1 2 3)))) + (assert-eq [1 2 3] [(try (values 1 2 3))]) + (assert-eq 6 (select :# (try (values 1 nil 3 nil nil nil)))))) |