aboutsummaryrefslogtreecommitdiff
path: root/modules/textadept
diff options
context:
space:
mode:
authormitchell <70453897+orbitalquark@users.noreply.github.com>2021-01-22 15:06:14 -0500
committermitchell <70453897+orbitalquark@users.noreply.github.com>2021-01-22 15:06:14 -0500
commitc5aa8f8dec9611828b6972bc1a72cc8571eab36a (patch)
tree378495ef33fcb848782e1a5b6492c9751affa262 /modules/textadept
parent3cca0f2b2af03e7df8ec28231582bb3bf08042fc (diff)
downloadtextadept-c5aa8f8dec9611828b6972bc1a72cc8571eab36a.tar.gz
textadept-c5aa8f8dec9611828b6972bc1a72cc8571eab36a.zip
Added `textadept.run.test()` and `textadept.run.test_commands`.
This enables the running of project tests.
Diffstat (limited to 'modules/textadept')
-rw-r--r--modules/textadept/keys.lua8
-rw-r--r--modules/textadept/menu.lua1
-rw-r--r--modules/textadept/run.lua60
3 files changed, 57 insertions, 12 deletions
diff --git a/modules/textadept/keys.lua b/modules/textadept/keys.lua
index c365191a..0e5e69d5 100644
--- a/modules/textadept/keys.lua
+++ b/modules/textadept/keys.lua
@@ -82,6 +82,7 @@ local M = {}
-- Ctrl+Shift+R |⌘⇧R |M-^R |Compile
-- Ctrl+Shift+A |⌘⇧A |None |Set Arguments...
-- Ctrl+Shift+B |⌘⇧B |M-^B |Build
+-- Ctrl+Shift+T |⌘⇧T |M-^T |Run tests
-- Ctrl+Shift+X |⌘⇧X |M-^X |Stop
-- Ctrl+Alt+E |^⌘E |M-X |Next Error
-- Ctrl+Alt+Shift+E|^⌘⇧E |M-S-X |Previous Error
@@ -221,7 +222,7 @@ module('textadept.keys')]]
-- Windows, Linux, and BSD key bindings.
--
-- Unassigned keys (~ denotes keys reserved by the operating system):
--- c: C H I Q T ~ V Y _ ) ] } +
+-- c: C H I Q ~ V Y _ ) ] } +
-- a: aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ_ ) ] } *+-/=\n\s
-- ca: aAbBcCdD F H jJkKlLmM N qQ t xXy zZ_"'()[]{}<>* / \n\s
--
@@ -234,7 +235,7 @@ module('textadept.keys')]]
-- macOS key bindings.
--
-- Unassigned keys (~ denotes keys reserved by the operating system):
--- m: C ~H I JkK ~M p ~ tT V yY _ ) ] } + ~~\n
+-- m: C ~H I JkK ~M p ~ t V yY _ ) ] } + ~~\n
-- c: cC D gG H J K L oO qQ xXyYzZ_ ) ] } * / \n
-- cm: aAbBcC~D F ~HiIjJkKlL~MnN p q~rRsStTuUvVwWxXyYzZ_"'()[]{}<>*+-/=\t\n
--
@@ -261,7 +262,7 @@ module('textadept.keys')]]
--
-- Unassigned keys (~ denotes keys reserved by the operating system):
-- c: g~~ l~ ~
--- cm: cd g~~ k ~ q t yz
+-- cm: cd g~~ k ~ q yz
-- m: e J qQ sS vVw yY _ +
-- Note: m[befhstv] may be used by Linux/BSD GUI terminals for menu access.
--
@@ -370,6 +371,7 @@ local bindings = {
[textadept.run.compile] = {'ctrl+R', 'cmd+R', 'ctrl+meta+r'},
[textadept.run.set_arguments] = {'ctrl+A', 'cmd+A', nil},
[textadept.run.build] = {'ctrl+B', 'cmd+B', 'ctrl+meta+b'},
+ [textadept.run.test] = {'ctrl+T', 'cmd+T', 'ctrl+meta+t'},
[textadept.run.stop] = {'ctrl+X', 'cmd+X', 'ctrl+meta+x'},
[m('Tools/Next Error')] = {'ctrl+alt+e', 'ctrl+cmd+e', 'meta+x'},
[m('Tools/Previous Error')] = {'ctrl+alt+E', 'ctrl+cmd+E', 'meta+X'},
diff --git a/modules/textadept/menu.lua b/modules/textadept/menu.lua
index 1ae2d909..b3ce1015 100644
--- a/modules/textadept/menu.lua
+++ b/modules/textadept/menu.lua
@@ -171,6 +171,7 @@ local default_menubar = {
{_L['Compile'], textadept.run.compile},
{_L['Set Arguments...'], textadept.run.set_arguments},
{_L['Build'], textadept.run.build},
+ {_L['Run tests'], textadept.run.test},
{_L['Stop'], textadept.run.stop},
{_L['Next Error'], function() textadept.run.goto_error(true) end},
{_L['Previous Error'], function() textadept.run.goto_error(false) end},
diff --git a/modules/textadept/run.lua b/modules/textadept/run.lua
index ba7526cf..f9f462f5 100644
--- a/modules/textadept/run.lua
+++ b/modules/textadept/run.lua
@@ -7,7 +7,8 @@ local M = {}
-- Compile and run source code files with Textadept.
-- [Language modules](#compile-and-run) may tweak the `compile_commands`,
-- `run_commands`, and `error_patterns` tables for particular languages.
--- The user may tweak `build_commands` for particular projects.
+-- The user may tweak `build_commands` and `test_commands` for particular
+-- projects.
-- @field run_in_background (bool)
-- Run shell commands silently in the background.
-- This only applies when the message buffer is open, though it does not have
@@ -43,6 +44,13 @@ local M = {}
-- Arguments:
--
-- * `output`: A line of string output from the command.
+-- @field _G.events.TEST_OUTPUT (string)
+-- Emitted when executing a project's shell command for running tests.
+-- By default, output is printed to the message buffer. In order to override
+-- this behavior, connect to the event with an index of `1` and return `true`.
+-- Arguments:
+--
+-- * `output`: A line of string output from the command.
module('textadept.run')]]
M.run_in_background = false
@@ -51,7 +59,9 @@ M.MARK_WARNING = _SCINTILLA.next_marker_number()
M.MARK_ERROR = _SCINTILLA.next_marker_number()
-- Events.
-local run_events = {'compile_output', 'run_output', 'build_output'}
+local run_events = {
+ 'compile_output', 'run_output', 'build_output', 'test_output'
+}
for _, v in ipairs(run_events) do events[v:upper()] = v end
-- Keep track of: the last process spawned in order to kill it if requested; the
@@ -92,10 +102,10 @@ local function scan_for_error(message, ext_or_lexer)
message:lower():find('warning') and not message:lower():find('error')
-- Compile and run commands specify the file extension or lexer name used
-- to determine the command, so the error patterns used are guaranteed to
- -- be correct. Build commands have no such context and instead iterate
- -- through all possible error patterns. Only consider the error/warning
- -- valid if the extracted filename's extension or lexer name matches the
- -- error pattern's extension or lexer name.
+ -- be correct. Build and test commands have no such context and instead
+ -- iterate through all possible error patterns. Only consider the
+ -- error/warning valid if the extracted filename's extension or lexer name
+ -- matches the error pattern's extension or lexer name.
if ext_or_lexer then return detail end
local ext = detail.filename:match('[^/\\.]+$')
local lexer_name = textadept.file_types.extensions[ext]
@@ -107,7 +117,7 @@ local function scan_for_error(message, ext_or_lexer)
return nil
end
--- Prints an output line from a compile, run, or build shell command.
+-- Prints an output line from a compile, run, build, or test shell command.
-- Assume output is UTF-8 unless there's a recognized warning or error message.
-- In that case assume it is encoded in _CHARSET and mark it.
-- All stdout and stderr from the command is printed silently.
@@ -129,8 +139,8 @@ local function print_line(line, ext_or_lexer)
end
local output_buffer
--- Prints the output from a compile, run, or build shell command as a series of
--- lines, performing buffering as needed.
+-- Prints the output from a compile, run, build, or test shell command as a
+-- series of lines, performing buffering as needed.
-- @param output The output to print, or `nil` to flush any buffered output.
-- @param ext_or_lexer Optional file extension or lexer name associated with the
-- executed command. This is used for better error detection in compile and
@@ -369,6 +379,38 @@ end
events.connect(events.BUILD_OUTPUT, print_output)
---
+-- Map of project root paths to their associated "test" shell command line
+-- strings or functions that return such strings.
+-- Functions may also return a working directory and process environment table
+-- to operate in. By default, the working directory is the project's root
+-- directory and the environment is Textadept's environment.
+-- @class table
+-- @name test_commands
+M.test_commands = {}
+
+---
+-- Runs tests for the project whose root path is *root_directory* or the current
+-- project using the shell command from the `test_commands` table.
+-- The current project is determined by either the buffer's filename or the
+-- current working directory.
+-- Emits `TEST_OUTPUT` events.
+-- @param root_directory The path to the project to run tests for. The default
+-- value is the current project.
+-- @see test_commands
+-- @see _G.events
+-- @name test
+function M.test(root_directory)
+ if not assert_type(root_directory, 'string/nil', 1) then
+ root_directory = io.get_project_root()
+ if not root_directory then return end
+ end
+ for i = 1, #_BUFFERS do _BUFFERS[i]:annotation_clear_all() end
+ run_command(
+ M.test_commands[root_directory], root_directory, events.TEST_OUTPUT)
+end
+events.connect(events.TEST_OUTPUT, print_output)
+
+---
-- Stops the currently running process, if any.
-- @name stop
function M.stop() if proc then proc:kill() end end