CmdStart: Do not silently fail if tags match

It was possible previously to start an interval with a filter earlier
than the current filter, and if the tags matched, the command would
report success without actually moving the start time.

Signed-off-by: Shaun Ruffell <sruffell@sruffell.net>
This commit is contained in:
Shaun Ruffell 2020-06-07 23:12:58 -05:00 committed by Thomas Lauf
parent 356f20c9de
commit 6a52a412ba
2 changed files with 11 additions and 1 deletions

View file

@ -48,12 +48,17 @@ int CmdStart (
journal.startTransaction ();
if (!filter.is_started ())
{
filter.start = now;
}
// If the latest interval is open, close it.
if (latest.is_open ())
{
// If the new interval tags match those of the currently open interval, then
// do nothing - the tags are already being tracked.
if (latest.tags () == filter.tags ())
if (latest.encloses (filter) && latest.tags () == filter.tags ())
{
if (verbose)
std::cout << intervalSummarize (database, rules, latest);

View file

@ -257,6 +257,11 @@ class TestStart(TestCase):
self.assertClosedInterval(j[0])
self.assertOpenInterval(j[1])
def test_start_will_not_silently_fail_to_adjust_with_same_tags(self):
"""Start will not silently fail when tags are the same and time is earlier"""
self.t("start 1h ago proja")
code, out, err = self.t.runError("start 2h ago proja")
self.assertIn("The end of a date range must be after the start.", err)
if __name__ == "__main__":
from simpletap import TAPTestRunner