mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-23 05:27:47 +02:00
Unit Tests
- Added on-exit test for unexpected JSON output.
This commit is contained in:
parent
bd785ffad5
commit
ab41e005c9
2 changed files with 32 additions and 0 deletions
|
@ -83,6 +83,20 @@ class TestHooksOnExit(TestCase):
|
||||||
logs = self.t.hooks[hookname].get_logs()
|
logs = self.t.hooks[hookname].get_logs()
|
||||||
self.assertEqual(self.t.hooks[hookname].get_logs()["output"]["msgs"][0], "FEEDBACK")
|
self.assertEqual(self.t.hooks[hookname].get_logs()["output"]["msgs"][0], "FEEDBACK")
|
||||||
|
|
||||||
|
def test_onexit_builtin_misbehave2(self):
|
||||||
|
"""on-exit-misbehave2 - Emits unexpected JSON."""
|
||||||
|
hookname = 'on-exit-misbehave2'
|
||||||
|
self.t.hooks.add_default(hookname, log=True)
|
||||||
|
|
||||||
|
# Failing hook should prevent processing.
|
||||||
|
code, out, err = self.t.runError(("version",))
|
||||||
|
self.assertIn("Hook Error: Expected 0 JSON task(s), found 1", err)
|
||||||
|
self.t.hooks[hookname].assertTriggered()
|
||||||
|
self.t.hooks[hookname].assertTriggeredCount(1)
|
||||||
|
self.t.hooks[hookname].assertExitcode(0)
|
||||||
|
logs = self.t.hooks[hookname].get_logs()
|
||||||
|
self.assertEqual(self.t.hooks[hookname].get_logs()["output"]["msgs"][0], "FEEDBACK")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
from simpletap import TAPTestRunner
|
from simpletap import TAPTestRunner
|
||||||
unittest.main(testRunner=TAPTestRunner())
|
unittest.main(testRunner=TAPTestRunner())
|
||||||
|
|
18
test/test_hooks/on-exit-misbehave2
Normal file
18
test/test_hooks/on-exit-misbehave2
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# The on-exit event is triggered once, after initialization, before any
|
||||||
|
# processing occurs. This hooks script has no effect on processing.
|
||||||
|
|
||||||
|
# Input:
|
||||||
|
# - None
|
||||||
|
|
||||||
|
# Output:
|
||||||
|
# - Optional feedback/error.
|
||||||
|
echo '{"description":"extra","status":"pending"}'
|
||||||
|
echo 'FEEDBACK'
|
||||||
|
|
||||||
|
# Status:
|
||||||
|
# - 0: JSON ignored, non-JSON is feedback.
|
||||||
|
# - non-0: JSON ignored, non-JSON is error.
|
||||||
|
exit 0
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue