Harald Albrecht
5 years ago
8 changed files with 187 additions and 2 deletions
@ -0,0 +1,40 @@ |
|||
-- Configuration for "busted" TDD tool |
|||
|
|||
--[[ |
|||
Copyright 2019 Harald Albrecht |
|||
|
|||
Permission is hereby granted, free of charge, to any person obtaining a copy |
|||
of this software and associated documentation files (the "Software"), to deal |
|||
in the Software without restriction, including without limitation the rights |
|||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|||
copies of the Software, and to permit persons to whom the Software is |
|||
furnished to do so, subject to the following conditions: |
|||
|
|||
The above copyright notice and this permission notice shall be included in all |
|||
copies or substantial portions of the Software. |
|||
|
|||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|||
SOFTWARE. |
|||
]]-- |
|||
|
|||
return { |
|||
default = { |
|||
lpath = "./sdcard/?.lua;./mock/?.lua", |
|||
-- Provides an "insl" convenience replacement for busted's insulate() using |
|||
-- a fixed descriptive text ... or rather, icon. Please not that "insl" |
|||
-- not only rhymes with "insulation", but even more so with the German |
|||
-- "insel", meaning "island". And that's exactly what it does: splendid |
|||
-- isolation... |
|||
e = "INSL = '[⛔]';" |
|||
.. "_BUSTED = require('busted');" |
|||
.. "function insl(f) _BUSTED.insulate(_INSL, f) end;" |
|||
-- Automatically pulls in our multibow mocking. |
|||
.. "require('mockkeybow');", |
|||
verbose = true |
|||
} |
|||
} |
@ -0,0 +1,17 @@ |
|||
{ |
|||
// Use IntelliSense to learn about possible attributes. |
|||
// Hover to view descriptions of existing attributes. |
|||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 |
|||
"version": "0.2.0", |
|||
"configurations": [ |
|||
{ |
|||
"name": "attach", |
|||
"type": "lua", |
|||
"request": "attach", |
|||
"program": "", |
|||
"stopOnEntry": false, |
|||
"cwd": "${workspaceFolder}", |
|||
"debugServer" : 4278 |
|||
} |
|||
] |
|||
} |
@ -0,0 +1,13 @@ |
|||
local busted=require "busted" |
|||
|
|||
require "keybow" |
|||
busted.stub(keybow, "auto_lights") |
|||
busted.stub(keybow, "clear_lights") |
|||
busted.stub(keybow, "load_pattern") |
|||
busted.stub(keybow, "set_pixel") |
|||
busted.stub(keybow, "set_key") |
|||
busted.stub(keybow, "set_modifier") |
|||
busted.stub(keybow, "tap_key") |
|||
|
|||
busted.stub(keybow, "sleep") -- FIXME |
|||
busted.stub(keybow, "usleep") -- FIXME |
@ -0,0 +1,12 @@ |
|||
{ |
|||
"folders": [ |
|||
{ |
|||
"path": "." |
|||
} |
|||
], |
|||
"settings": { |
|||
"files.associations": { |
|||
".busted": "lua" |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,8 @@ |
|||
#!/bin/bash |
|||
# Installs the required libraries on Ubuntu ~18.10 LTS for Lua testing. |
|||
|
|||
#sudo apt-get remove lua* |
|||
sudo apt-get install --yes lua5.3 liblua5.3-dev |
|||
sudo update-alternatives --install /usr/bin/lua lua /usr/bin/lua5.3 10 |
|||
sudo apt-get install --yes luarocks |
|||
sudo luarocks install busted |
@ -0,0 +1,93 @@ |
|||
--[[ |
|||
Copyright 2019 Harald Albrecht |
|||
|
|||
Permission is hereby granted, free of charge, to any person obtaining a copy |
|||
of this software and associated documentation files (the "Software"), to deal |
|||
in the Software without restriction, including without limitation the rights |
|||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|||
copies of the Software, and to permit persons to whom the Software is |
|||
furnished to do so, subject to the following conditions: |
|||
|
|||
The above copyright notice and this permission notice shall be included in all |
|||
copies or substantial portions of the Software. |
|||
|
|||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|||
SOFTWARE. |
|||
]]-- |
|||
|
|||
require "mocked-keybow" |
|||
|
|||
describe("multibow", function() |
|||
|
|||
-- ensure to get a fresh multibow module instance each time we run |
|||
-- an isolated test... |
|||
local mb |
|||
|
|||
before_each(function() |
|||
require("keybow") |
|||
stub(keybow, "set_pixel") |
|||
mb = require("snippets/multibow") |
|||
end) |
|||
|
|||
insl(function() |
|||
it("adds permanent keyboard layout, but doesn't activate it", function() |
|||
local permkm = { |
|||
name="permanent", |
|||
permanent=true |
|||
} |
|||
assert.is_nil(mb.keymaps["permanent"]) |
|||
mb.register_keymap(permkm) |
|||
assert.is.equal(mb.keymaps["permanent"], permkm) |
|||
assert.is_nil(mb.current_keymap) |
|||
end) |
|||
end) |
|||
|
|||
insl(function() |
|||
it("checks multibow module is fresh again", function() |
|||
assert.is_nil(mb.keymaps["permanent"]) |
|||
end) |
|||
end) |
|||
|
|||
insl(function() |
|||
it("adds permanent, then two primary layouts, activates only first primary layout", function() |
|||
local permkm = { |
|||
name="permanent", |
|||
permanent=true |
|||
} |
|||
mb.register_keymap(permkm) |
|||
local prim1km = { name="bavaria-one" } |
|||
local prim2km = { name="primary-two" } |
|||
mb.register_keymap(prim1km) |
|||
mb.register_keymap(prim2km) |
|||
assert.is.equal(mb.current_keymap, prim1km) |
|||
end) |
|||
end) |
|||
|
|||
insl(function() |
|||
it("adds secondary, then primary layout, activates only primary layout", function() |
|||
local primkm = { name="berlin" } |
|||
local seckm = { name="munich", secondary=true } |
|||
mb.register_keymap(seckm) |
|||
mb.register_keymap(primkm) |
|||
assert.is.equal(mb.current_keymap, primkm) |
|||
end) |
|||
end) |
|||
|
|||
insl(function() |
|||
it("sets up multibow, activates lights", function() |
|||
local s = spy.on(_G, "setup") |
|||
_G.setup() |
|||
assert.spy(s).was.called(1) |
|||
|
|||
local al = spy.on(mb, "activate_leds") |
|||
_G.setup() |
|||
assert.spy(al).was.called(1) |
|||
end) |
|||
end) |
|||
|
|||
end) |
Loading…
Reference in new issue