-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from peterklijn/add-unit-tests
Add unit tests
- Loading branch information
Showing
7 changed files
with
335 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
FROM akorn/luarocks:lua5.4-alpine | ||
|
||
RUN apk add gcc musl-dev | ||
RUN luarocks install luacheck | ||
RUN apk add gcc musl-dev make | ||
|
||
RUN luarocks install luacheck \ | ||
&& luarocks install luaunit | ||
|
||
WORKDIR shiftit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,4 @@ services: | |
context: .. | ||
dockerfile: ./.docker/ci.Dockerfile | ||
volumes: | ||
- ..:/shifit | ||
- ..:/shiftit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,6 @@ jobs: | |
|
||
- name: Run linter | ||
run: make ci-lint | ||
|
||
- name: Run tests | ||
run: make ci-test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
test: | ||
find . -name "*_test.lua" | xargs sh -c 'lua $$0 -v' | ||
|
||
ci-init: | ||
docker-compose -f .docker/docker-compose.ci.yaml build | ||
|
||
ci-lint: | ||
docker-compose -f .docker/docker-compose.ci.yaml run hammerspoon-shiftit-ci luacheck --globals hs -- shifit/ | ||
docker-compose -f .docker/docker-compose.ci.yaml run hammerspoon-shiftit-ci luacheck --globals hs -- . | ||
|
||
ci-test: | ||
docker-compose -f .docker/docker-compose.ci.yaml run hammerspoon-shiftit-ci make test | ||
|
||
.PHONY: ci-init ci-lint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
local lu = require('luaunit') | ||
|
||
local hotkey = { | ||
bindings = {}, | ||
} | ||
|
||
local defaultScreenRect = { x = 0, y = 0, w = 1200, h = 800 } | ||
local defaultWindowRect = { x = 100, y = 100, w = 1000, h = 600 } | ||
|
||
function hotkey.bind(mods, key, fn) | ||
lu.assertNotNil(mods) | ||
lu.assertNotNil(key) | ||
lu.assertIsFunction(fn) | ||
table.insert(hotkey.bindings, { mods, key, fn }) | ||
end | ||
|
||
local screen = { | ||
rect = defaultScreenRect, | ||
} | ||
|
||
function screen:frame() | ||
return self.rect | ||
end | ||
|
||
local window = { | ||
rect = defaultWindowRect, | ||
_screen = screen, | ||
} | ||
|
||
function window.focusedWindow() | ||
return window | ||
end | ||
|
||
function window:frame() | ||
return self.rect | ||
end | ||
|
||
function window:screen() | ||
return self._screen | ||
end | ||
|
||
function window:move(rect, _, _, _) | ||
lu.assertIsNumber(rect.x) | ||
lu.assertIsNumber(rect.y) | ||
lu.assertIsNumber(rect.w) | ||
lu.assertIsNumber(rect.h) | ||
self.rect = rect | ||
end | ||
|
||
local mocks = { | ||
hotkey = hotkey, | ||
window = window, | ||
} | ||
|
||
function mocks:reset() | ||
self.hotkey.bindings = {} | ||
self.window.rect = defaultWindowRect | ||
self.window._screen.rect = defaultScreenRect | ||
end | ||
|
||
return mocks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.