Skip to content

Commit

Permalink
#1222 Updates to async test library. NOT YET WORKING.
Browse files Browse the repository at this point in the history
  • Loading branch information
randomeizer committed Nov 23, 2018
1 parent feafeb5 commit 122676a
Show file tree
Hide file tree
Showing 20 changed files with 1,787 additions and 28 deletions.
47 changes: 47 additions & 0 deletions Makefile
@@ -0,0 +1,47 @@

SHELL = /bin/bash

# list of executables required for the makefile to run.
EXECUTABLES = defaults luarocks unlink busted
K := $(foreach exec,$(EXECUTABLES),\
$(if $(shell which $(exec)),some string,$(error No `$(exec)` in PATH)))

BundleID = org.latenitefilms.CommandPost
APP_SUPPORT_PATH = ~/Library/Application\ Support
CP_PATH = $(APP_SUPPORT_PATH)/CommandPost
BID_PATH = $(APP_SUPPORT_PATH)/$(BundleID)
EXT_PATH = $(CP_PATH)/Extensions
PLUGIN_PATH = $(CP_PATH)/Plugins
PREFS_PATH = ~/Library/Preferences
PREFS_FILE = $(PREFS_PATH)/$(BundleID).plist

CACHES_PATH = ~/Library/Caches
CACHES = $(CACHES_PATH)/$(BundleID) $(CACHES_PATH)/io.fabric.sdk.mac.data/$(BundleID) $(CACHES_PATH)/com.crashlytics.data/$(BundleID) $(CACHES_PATH)/com.apple.nsurlsessiond/Downloads/$(BundleID) ~/Library/WebKit/$(BundleID)

.PHONY: appscripts devscripts trashprefs trashsupport trashcaches

test:
@busted --help

devscripts: $(PLUGIN_PATH)
@defaults write $(BundleID) MJConfigFile "${PWD}/src/extensions/init.lua"
@echo "CommandPost will load extensions and plugins from GitHub '${PWD}/src' folders."

appscripts:
@defaults delete $(BundleID) MJConfigFile
@echo "CommandPost will load extensions and plugins from the bundled sources."

trashprefs:
@echo "Trashing CommandPost Preferences..."
@defaults delete $(PREFS_FILE)
@rm $(PREFS_FILE)

trashsupport:
@echo "Trashing CommandPost Application Support..."
#@rm -R $(CP_PATH)
#@rm -R $(BID_PATH)

trashcaches:
echo "Trashing Caches..."
$(foreach cache,$(CACHES),\
$(shell rm -R $(cache))
1 change: 1 addition & 0 deletions src/extensions/cp/app.lua
Expand Up @@ -436,6 +436,7 @@ function app.lazy.prop:version()
end

--- cp.app.displayName <cp.prop: string; read-only; live>
--- Field
--- The application display name as a string.
function app.lazy.prop:displayName()
return self.info:mutate(function(original)
Expand Down
61 changes: 33 additions & 28 deletions src/extensions/cp/developer/init.lua
Expand Up @@ -45,36 +45,28 @@ local config = require("cp.config")
--
--------------------------------------------------------------------------------
local dev = {}
--------------------------------------------------------------------------------
-- DESTROY DEVELOPER MODE:
--------------------------------------------------------------------------------
function _G.destroyDeveloperMode()
_G._plugins = nil
_G._fcp = nil
_G._findUnusedLanguageStrings = nil
_G._which = nil
_G._elementAtMouse = nil
_G._inspectAtMouse = nil
_G._inspect = nil
_G._inspectElement = nil
_G._highlight = nil
_G._highlightPoint = nil
_G._inspectElementAtMousePath = nil
_G._test = nil
_G.destroyDeveloper = nil
function dev.destroyDeveloperMode()
for k,_ in pairs(dev) do
_G[k] = nil
end
package.loaded["cp.developer"] = nil
end
--------------------------------------------------------------------------------
-- DEVELOPER SHORTCUTS FOR USE IN ERROR LOG:
--------------------------------------------------------------------------------
_G._plugins = require("cp.plugins")
_G._fcp = require("cp.apple.finalcutpro")
dev._plugins = require("cp.plugins")
dev._fcp = require("cp.apple.finalcutpro")
--------------------------------------------------------------------------------
-- FIND UNUSED LANGUAGES STRINGS:
--------------------------------------------------------------------------------
function _G._findUnusedLanguageStrings()
function dev._findUnusedLanguageStrings()
local path = config.languagePath .. "English.json"
local data = io.open(path, "r")
Expand Down Expand Up @@ -124,7 +116,7 @@ end
-- FIND TEXT:
--------------------------------------------------------------------------------
local whiches = {}
function _G._which(cmd)
function dev._which(cmd)
local path = whiches[cmd]
if not path then
local output, ok = hs.execute(string.format("which %q", cmd))
Expand All @@ -141,14 +133,14 @@ end
--------------------------------------------------------------------------------
-- ELEMENT AT MOUSE:
--------------------------------------------------------------------------------
function _G._elementAtMouse()
function dev._elementAtMouse()
return ax.systemElementAtPosition(mouse.getAbsolutePosition())
end
--------------------------------------------------------------------------------
-- INSPECT ELEMENT AT MOUSE:
--------------------------------------------------------------------------------
function _G._inspectAtMouse(options)
function dev._inspectAtMouse(options)
options = options or {}
local element = _G._elementAtMouse()
if options.parents then
Expand Down Expand Up @@ -176,7 +168,7 @@ end
--------------------------------------------------------------------------------
-- INSPECT:
--------------------------------------------------------------------------------
function _G._inspect(e, options)
function dev._inspect(e, options)
if e == nil then
return "<nil>"
elseif type(e) ~= "userdata" or not e.attributeValue then
Expand All @@ -203,8 +195,8 @@ end
--------------------------------------------------------------------------------
-- INSPECT ELEMENT:
--------------------------------------------------------------------------------
function _G._inspectElement(e, options)
_G._highlight(e)
function dev._inspectElement(e, options)
dev._highlight(e)
local depth = options and options.depth or 1
local out = "\n Role = " .. inspect(e:attributeValue("AXRole"))
Expand All @@ -225,7 +217,7 @@ end
--------------------------------------------------------------------------------
-- HIGHLIGHT ELEMENT:
--------------------------------------------------------------------------------
function _G._highlight(e)
function dev._highlight(e)
if not e or not e.frame then
return e
end
Expand Down Expand Up @@ -259,7 +251,7 @@ function _G._highlight(e)
end
local SIZE = 100
function _G._highlightPoint(point)
function dev._highlightPoint(point)
--------------------------------------------------------------------------------
-- Get Highlight Colour Preferences:
--------------------------------------------------------------------------------
Expand Down Expand Up @@ -291,7 +283,7 @@ end
--------------------------------------------------------------------------------
-- INSPECT ELEMENT AT MOUSE PATH:
--------------------------------------------------------------------------------
function _G._inspectElementAtMousePath()
function dev._inspectElementAtMousePath()
return inspect(_G._elementAtMouse():path())
end
Expand Down Expand Up @@ -319,7 +311,7 @@ end
--
-- Returns:
-- * A [cp.test] to execute.
function _G._test(id)
function dev._test(id)
id = id or ""
local testsRoot = config.testsPath
if not testsRoot then
Expand Down Expand Up @@ -352,4 +344,17 @@ function _G._test(id)
else
return result
end
end
end
function dev._debug(port)
port = port or 21110
dev.lrdb = require("lrdb_server")
dev.lrdb.activate(port)
end
-- apply dev functions to the global scope.
for k,v in pairs(dev) do
_G[k] = v
end
return dev
81 changes: 81 additions & 0 deletions src/extensions/cp/spec.lua
@@ -0,0 +1,81 @@
--- === cp.spec ===
---
--- An asynchronous test suite for Lua.
local require = require

local Handler = require "cp.spec.Handler"
local DefaultHandler = require "cp.spec.DefaultHandler"
local Result = require "cp.spec.Result"
local Run = require "cp.spec.Run"
local Definition = require "cp.spec.Definition"
local Where = require "cp.spec.Where"
local Scenario = require "cp.spec.Scenario"
local Specification = require "cp.spec.Specification"

--- cp.spec.describe(name) -> function(definitions) -> cp.spec.Specification
--- Function
--- Returns a `function` which will accept a list of test [Definitions](cp.spec.Definition.md),
--- or a `table` of [Definitions](cp.spec.Definition.md).
---
--- Parameters:
--- * name - The name of the test suite.
---
--- Returns:
--- * A `function` that must be called with the set of [Definitions](cp.spec.Definition.md) or [suites](cp.spec.Specification.md) to run.
local function describe(name)
return function(...)
return Specification(name):with(...)
end
end

--- cp.spec.describe(name) -> function(definitions) -> cp.spec.Specification
--- Function
--- Returns a `function` which will accept a list of test [definitions](cp.spec.Definition.md),
--- or a `table` of [definitions](cp.spec.Definition.md).
---
--- Parameters:
--- * name - The name of the test suite.
---
--- Returns:
--- * A `function` that must be called with the set of [definitions](cp.spec.Definition.md) or [suites](cp.spec.Specification.md) to run.
local context = describe

--- cp.spec.it(name[, ...]) -> cp.spec.Scenario
--- Function
--- Returns an [Scenario](cp.spec.Scenario.md) with the specified name and optional `doingFn` function.
--- If the function is not provided, it must be done via the [doing](#doing) method prior to running.
---
--- Parameters:
--- * name - The name of the scenario.
--- * doingFn - (optional) The `function` to call when doing the operation. Will be passed the [Run.This](cp.spec.Run.This.md)
--- instance for the definition.
---
--- Notes:
--- * See [doing](cp.spec.Scenario.md#doing) for more details regarding the function.
local function it(name, doingFn)
return Scenario("it " .. name, doingFn)
end

--- cp.spec(item) -> cp.spec.Run
local function run(item)
local spec = require(item .. "_spec")
return spec:run()
end

return setmetatable({
Handler = Handler,
DefaultHandler = DefaultHandler,
Result = Result,
Run = Run,
Definition = Definition,
Scenario = Scenario,
Where = Where,
Specification = Specification,
describe = describe,
context = context,
it = it,
}, {
__call = function(_, ...)
return run(...)
end
})

0 comments on commit 122676a

Please sign in to comment.