#21 Move check for empty ID list

- Sharpen error message
- Add test
This commit is contained in:
Thomas Lauf 2018-05-12 19:17:04 +02:00 committed by lauft
parent db13bd403f
commit 784ecbbfd9
2 changed files with 12 additions and 6 deletions

View file

@ -39,12 +39,6 @@ int CmdTag (
{
// Gather IDs and TAGs.
std::set <int> ids = cli.getIds ();
if (ids.empty ())
{
throw std::string ("IDs must be specified. See 'timew help tag'.");
}
std::vector<std::string> tags = cli.getTags ();
// Load the data.
@ -75,6 +69,11 @@ int CmdTag (
}
}
if (ids.empty ())
{
throw std::string ("At least one ID must be specified. See 'timew help tag'.");
}
// Apply tags to ids.
for (auto& id : ids)
{

View file

@ -49,6 +49,13 @@ class TestTag(TestCase):
code, out, err = self.t("tag @1 foo")
self.assertIn('Added foo to @1', out)
def test_should_fail_on_missing_id_and_inactive_time_tracking(self):
"""Missing id on inactive time tracking is an error"""
self.t("track yesterday for 1hour")
code, out, err = self.t.runError("tag foo")
self.assertIn("At least one ID must be specified.", err)
def test_add_tag_to_closed_interval(self):
"""Add a tag to an closed interval"""
self.t("track yesterday for 1hour")