Add tests for tic80 docset and fake external docset.

This commit is contained in:
Phil Hagelberg 2025-02-26 22:41:59 -08:00
parent 6790a19fb5
commit 9b54f882c9
4 changed files with 43 additions and 12 deletions

View File

@ -13,7 +13,8 @@ BINDIR ?= $(PREFIX)/bin
FENNELFLAGS=--add-package-path "deps/?.lua" --add-fennel-path "src/?.fnl;deps/?.fnl"
REQUIRE_AS_INCLUDE_SETTINGS=$(shell $(FENNEL) tools/require-flags.fnl)
ROCKSPEC_LATEST_SCM=rockspecs/fennel-ls-scm-$(shell ls rockspecs | grep -Eo 'scm-[0-9]+' | grep -Eo [0-9]+ | sort -n | tail -1).rockspec
ROCKSPEC_LATEST_SCM=rockspecs/fennel-ls-scm-$(shell ls rockspecs | \
grep -Eo 'scm-[0-9]+' | grep -Eo [0-9]+ | sort -n | tail -1).rockspec
.PHONY: all clean test repl install docs docs-love2d install-deps ci selflint \
deps rm-docs rm-deps count testall check-deps check-luarocks
@ -22,18 +23,31 @@ all: $(EXE)
$(EXE): $(SRC)
echo "#!/usr/bin/env $(LUA)" > $@
$(FENNEL) $(FENNELFLAGS) $(REQUIRE_AS_INCLUDE_SETTINGS) --require-as-include --compile src/fennel-ls.fnl >> $@
$(FENNEL) $(FENNELFLAGS) $(REQUIRE_AS_INCLUDE_SETTINGS) --require-as-include \
--compile src/fennel-ls.fnl >> $@
chmod 755 $@
repl:
$(FENNEL) $(FENNELFLAGS)
install: $(EXE)
mkdir -p $(DESTDIR)$(BINDIR) && cp $< $(DESTDIR)$(BINDIR)/
## Generating docs
docs:
$(FENNEL) $(FENNELFLAGS) tools/get-docs.fnl $(GET_DOCS_FLAGS)
docs-love2d:
XDG_DATA_HOME ?= $(HOME)/.local/share
DOCSET_DIR = $(XDG_DATA_HOME)/fennel-ls/docsets/
$(DOCSET_DIR)/love2d.lua: src/fennel-ls/docs/generated/love2d.fnl
mkdir -p $(DOCSET_DIR)
$(FENNEL) $(FENNELFLAGS) --compile $< > $@
src/fennel-ls/docs/generated/love2d.fnl:
$(FENNEL) $(FENNELFLAGS) tools/get-docs.fnl --generate-love2d
# has to be separate for licensing reasons
docs-love2d: $(DOCSET_DIR)/love2d.lua
rm-docs:
rm -rf src/fennel-ls/docs/
@ -49,13 +63,13 @@ selflint:
count:
cloc $(shell find src -name "*.fnl" | grep -v "generated")
install: $(EXE)
mkdir -p $(DESTDIR)$(BINDIR) && cp $< $(DESTDIR)$(BINDIR)/
repl:
DEV=y $(FENNEL) $(FENNELFLAGS)
# to run one module: make test FAITH_TEST=test.lint
# to run one test: make test FAITH_TEST="test.lint test-unset-var"
test: $(EXE)
TESTING=1 $(FENNEL) $(FENNELFLAGS) test/init.fnl
DEV=y XDG_DATA_HOME=test/data $(FENNEL) $(FENNELFLAGS) test/init.fnl
testall:
$(MAKE) test LUA=lua5.1

View File

@ -350,7 +350,7 @@ identifiers are declared / referenced in which places."
(case ...
(true ?item1 ?item2) (values ?item1 ?item2)
(where (or (nil err) (false err)) (not (err:find "^[^\n]-__NOT_AN_ERROR\n")))
(if (os.getenv :TESTING)
(if (os.getenv :DEV)
(error (.. "\nYou have crashed fennel-ls (or the fennel " component ") with the following message\n:" err
"\n\n^^^ the error message above here is the root problem\n\n"))
(table.insert diagnostics

View File

@ -0,0 +1,8 @@
-- a fake external docset
return {translate = { binding = "translate",
metadata = {
["fls/itemKind"] = "Function",
["fnl/arglist"] = {"str", "from", "to"},
["fnl/docstring"] = "convert from one lanugage to another"
}
}}

View File

@ -3,8 +3,8 @@
(local {: create-client} (require :test.utils))
(local {: null} (require :dkjson))
(fn check [file-contents ?response-string]
(let [{: client : uri : cursor} (create-client file-contents)
(fn check [file-contents ?response-string ?opts]
(let [{: client : uri : cursor} (create-client file-contents nil ?opts)
[message] (client:hover uri cursor)]
(if (= (type ?response-string) :string)
(faith.= ?response-string (?. message :result :contents :value)
@ -178,6 +178,14 @@ except that it sets a new message handler `msgh`.")
#($:find "```fnl\n(quote x)\n```" 1 true))
nil)
(fn test-libraries []
(check "#(trac|e :hello)"
#($:find "a service function")
{:libraries {:tic80 true}})
(check "(trans|late \"hello\" :en :zh)"
#($:find "convert from one lanugage to another")
{:libraries {:external true}}))
{: test-literals
: test-builtins
: test-globals
@ -187,4 +195,5 @@ except that it sets a new message handler `msgh`.")
: test-crash
: test-multival
: test-macro
: test-reader}
: test-reader
: test-libraries}