diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..88cfe3d --- /dev/null +++ b/.editorconfig @@ -0,0 +1,15 @@ +root = true + +[*] +indent_style = space +indent_size = 4 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.{lua,tl,d.tl,rockspec,luacheckrc}] +indent_size = 3 + +[*.json] +indent_size = 2 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0084403 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +/luarocks +/lua +/lua_modules +/.luarocks +/build diff --git a/.luacheckrc b/.luacheckrc new file mode 100644 index 0000000..1e30a8e --- /dev/null +++ b/.luacheckrc @@ -0,0 +1,11 @@ +std = "lua54" +cache = true + +files[".luacheckrc"].std = "+luacheckrc" +files[".rockspec"].std = "+rockspec" + +include_files = { + "src/", + "*.rockspec", + "*.luacheckrc", +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..07b34a0 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,9 @@ +{ + "cSpell.words": ["fname", "luacheckrc", "rockspec", "traceback"], + "editor.formatOnPaste": true, + "editor.formatOnSave": true, + "files.associations": { + ".luacheckrc": "lua", + "*.rockspec": "lua" + } +} diff --git a/busted-tl-dev-1.rockspec b/busted-tl-dev-1.rockspec new file mode 100644 index 0000000..50d293c --- /dev/null +++ b/busted-tl-dev-1.rockspec @@ -0,0 +1,44 @@ +rockspec_format = "3.0" +package = "busted-tl" +version = "dev-1" + +source = { + url = "*** please add URL for source tarball, zip or repository here ***", +} + +description = { + homepage = "*** please enter a project homepage ***", + license = "*** please specify a license ***", +} + +dependencies = { + "lua >= 5.1", + "penlight >= 1.3.2", + "busted", + "tl", +} + +build_dependencies = { + "cyan", +} + +build = { + type = "command", + build_command = "cyan build", + install = { + lua = { + ["busted.modules.files.teal"] = "build/busted-tl/teal.lua", + }, + }, +} + +test_dependencies = { + "busted", +} + +test = { + type = "busted", + flags = { + "--loaders=teal", + }, +} diff --git a/spec/teal_spec.tl b/spec/teal_spec.tl new file mode 100644 index 0000000..2e4b0d7 --- /dev/null +++ b/spec/teal_spec.tl @@ -0,0 +1,20 @@ +global describe: function(string, function) +global it: function(string, function) + +-- Teal generates an empty table for record declaration. +-- For now we'll bypass any usage of the assert module and +-- use the global assert function instead. + +-- global record assert +-- are_equal: function(any, any) +-- end + +describe("Teal tests", function() + it("works", function() + -- This is a Teal specific syntax. + local a: number = 1 + + assert(a == 1, "This test uses Teal's syntax!") + -- assert.are_equal(a, 1) + end) +end) diff --git a/src/busted-tl/teal.tl b/src/busted-tl/teal.tl new file mode 100644 index 0000000..d3ac570 --- /dev/null +++ b/src/busted-tl/teal.tl @@ -0,0 +1,53 @@ +local file = require("pl.file") +local path = require("pl.path") + +local type Busted = record + publish: function +end + +local type Info = record + traceback: string + short_src: string +end + +local teal_available, tl = pcall(require, 'tl') + +local rewrite_filename = function(filename: string): string + return filename:match('string "(.+)"') or filename +end + +local rewriteMessage = function(_filename: string, message: string): string + local fname, line, msg = message:match('^([^\n]-):(%d+): (.*)') + if not fname then + return message + end + + fname = rewrite_filename(fname) + + return fname .. ':' .. tostring(line) .. ': ' .. msg +end + +local getTrace = function(_filename: string, info: Info): Info + local index = info.traceback:find('\n%s*%[C]') + info.traceback = info.traceback:sub(1, index) + info.short_src = rewrite_filename(info.short_src) + return info +end + +local record ret +end + +function ret.match(_busted: Busted, filename: string): boolean + return teal_available and path.extension(filename) == '.tl' +end + +function ret.load(busted: Busted, filename: string): function, function, function + local content = file.read(filename) + local program, err = tl.load(content, filename) + if not program then + busted.publish({ 'error', 'file' }, { descriptor = 'file', name = filename }, nil, err, {}) + end + return program, getTrace, rewriteMessage +end + +return ret diff --git a/stylua.toml b/stylua.toml new file mode 100644 index 0000000..3c5eb9c --- /dev/null +++ b/stylua.toml @@ -0,0 +1,6 @@ +column_width = 80 +line_endings = "Unix" +indent_type = "Spaces" +indent_width = 3 +quote_style = "AutoPreferDouble" +no_call_parentheses = true diff --git a/tlconfig.lua b/tlconfig.lua new file mode 100644 index 0000000..48fbdf1 --- /dev/null +++ b/tlconfig.lua @@ -0,0 +1,7 @@ +return { + build_dir = "build", + source_dir = "src", + include_dir = { + "types", + }, +} diff --git a/types/pl.d.tl b/types/pl.d.tl new file mode 100644 index 0000000..0e1cfa3 --- /dev/null +++ b/types/pl.d.tl @@ -0,0 +1,10 @@ +local record pl + record file + read: function(string): string + end + record path + extension: function(string): string + end +end + +return pl diff --git a/types/pl/file.d.tl b/types/pl/file.d.tl new file mode 100644 index 0000000..99048f6 --- /dev/null +++ b/types/pl/file.d.tl @@ -0,0 +1 @@ +return require("pl").file diff --git a/types/pl/path.d.tl b/types/pl/path.d.tl new file mode 100644 index 0000000..4b09f9d --- /dev/null +++ b/types/pl/path.d.tl @@ -0,0 +1 @@ +return require("pl").path \ No newline at end of file