-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unit Testing #106
Unit Testing #106
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome.
Made a small change to move pprint into |
@agzam Do you have a script to add the license\credits to each file or was that added manually? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few nitpicks, looks great over all.
docs/testing.org
Outdated
The testing library provides basic unit-testing capabilities to Spacehammer by | ||
running scripts against the hammerspoon CLI =hs=. | ||
|
||
Tests can be ran invoking the following shell command within the =~/.hammerspoon= directory: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be run
docs/testing.org
Outdated
|
||
*** Does =before= run before each =it=? | ||
|
||
Before runs before all =it= calls within a describe block. If you wanted |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for extra clarity, something like: Before runs once before all it
calls within a..
docs/testing.org
Outdated
|
||
* Todo List | ||
|
||
- [ ] Consider replacing describe and it with =testing= and =is= macros |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should file tickets for these, and we can link.
lib/functional.fnl
Outdated
@@ -237,6 +243,7 @@ | |||
:eq? eq? | |||
:filter filter | |||
:find find | |||
:first first |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can turn this table into the shorthand : first
version since you're touching it anyway.
lib/testing/test-runner.fnl
Outdated
|
||
(collect-tests) | ||
(run-all-tests) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hanging
408fa59
to
fd5421c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. A few times you use is.eq
instead of is.eq?
in docs.
docs/testing.org
Outdated
|
||
(it "Subtraction" | ||
(fn [] | ||
(is.eq (- 1 1) 0 "Did not result in 0"))))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is.eq?
vs is.eq
Co-authored-by: Grazfather <[email protected]>
Co-authored-by: Grazfather <[email protected]>
agzam#106 Removed unescaped chars from windows.fnl docstr Draft of testing libs Added testing docs and some initial tests Moved test/testing.org to docs/testing.org Fixed PR review comments Removed docstr test code from core.fnl Moved pprint into lib/globals.fnl Testing PR review changes from Graz Update docs/testing.org Co-authored-by: Grazfather <[email protected]> Update docs/testing.org Co-authored-by: Grazfather <[email protected]>
No, I don't have a script. Btw, would you like to discuss the licensing model, etc.? I think the file headers need a revamp. Maybe we should remove |
Great work @eccentric-j! This is quite nice. Now, what do you think, would it be very difficult to create a GitHub action and get them run before merging a PR? |
Thanks! @Grazfather asked a similar question the other day. That's definitely on my radar, touched on it a bit in #116. Options to make this work include:
Option #1 is my first choice given that it would run the full tests against hs API which does change from time to time which would be the most accurate. Option #2 would fix the performance issues, test consistency issues (at least during local development), and the state resetting issues (handled manually in the test definition using the Thinking something similar to the ;; In a test
(local mock mocking.spyOn(hs.window, 'focusWindowWest')
(mocking.impl mock (fn [] nil)) ;; Create a spy that can take a mock impl
(hs.window.focusWindowWest)
(is.eq? (length mock.calls) 1 "Expected mock function to be called one time")
;; In a suite
(after (fn [] (mocking.restore mock))) Another option is something like clojure's |
I agree with moving author and contributors to a separate file perhaps so there's less to maintain there. As for licensing what are your goals? Is it necessary to have the license in each file comments? Even the copyright year is already out of date. We could setup something like https://typicode.github.io/husky/#/ with some standard pre-commit hooks that could automatically remove the header if there is one, then generate an up-to-date one on every commit. Might create some noise though once per-year when it updates though. Although personally I'm curious if there's a viable compromise that doesn't require comments in every file, but automating it would be my second choice and at least we could use the fennel CLI or babashka to update the files in a git hook script. |
I'd rather have less "bureaucracy", even if it's conveniently semi-automated. Maybe let's remove the headers altogether, wdyt? |
100% on board |
#106 (comment) Suggested-by: Jay Zawrotny <[email protected]>
#106 (comment) Suggested-by: Jay Zawrotny <[email protected]>
When working on #72 for advising, it became apparent how important testing would be to get that feature in a shippable state.
I drafted a basic unit testing suite to run fennel test files against the hs CLI. It's primitive, but still pretty useful for confirming functionality and behaviors.
Docs are included in ./docs/testing.org, with a basic recipe for auto-running tests