mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Hooks
- Added a new on-launch-misbehave2 script that emits unexpected JSON.
This commit is contained in:
parent
3cce6c23f5
commit
bd785ffad5
3 changed files with 39 additions and 3 deletions
|
@ -402,6 +402,9 @@ bool Hooks::isJSON (const std::string& input) const
|
||||||
input[input.length () - 1] != '}')
|
input[input.length () - 1] != '}')
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
/*
|
||||||
|
I think this is not necessary, and a simple JSON test is all that is needed.
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
json::value* root = json::parse (input);
|
json::value* root = json::parse (input);
|
||||||
|
@ -419,6 +422,7 @@ bool Hooks::isJSON (const std::string& input) const
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -481,11 +485,11 @@ void Hooks::assertValidJSON (const std::vector <std::string>& input) const
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
void Hooks::assertNTasks (const std::vector <std::string>& json, int n) const
|
void Hooks::assertNTasks (const std::vector <std::string>& input, int n) const
|
||||||
{
|
{
|
||||||
if (json.size () != n)
|
if (input.size () != n)
|
||||||
{
|
{
|
||||||
context.error (format ("Hook Error: Expected {1} JSON task(s), found {2}", n, (int) json.size ()));
|
context.error (format ("Hook Error: Expected {1} JSON task(s), found {2}", n, (int) input.size ()));
|
||||||
throw 0;
|
throw 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,6 +83,20 @@ class TestHooksOnLaunch(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_onlaunch_builtin_misbehave2(self):
|
||||||
|
"""on-launch-misbehave2 - Hook emits unexpected JSON."""
|
||||||
|
hookname = 'on-launch-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-launch-misbehave2
Normal file
18
test/test_hooks/on-launch-misbehave2
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# The on-launch 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