mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-07-07 20:06:39 +02:00
Refactor CmdDefault
- restore original command behaviour:return exit code 0 if tracking is active, 1 if not - show welcome screen on first run - add/update tests
This commit is contained in:
parent
ecb8aa447c
commit
f1b3b3bb72
4 changed files with 47 additions and 29 deletions
|
@ -34,16 +34,19 @@ int CmdDefault (Rules& rules, Database& database)
|
||||||
{
|
{
|
||||||
// Load the most recent interval, summarize and display.
|
// Load the most recent interval, summarize and display.
|
||||||
auto interval = getLatestInterval (database);
|
auto interval = getLatestInterval (database);
|
||||||
|
|
||||||
if (interval.range.is_open ())
|
if (interval.range.is_open ())
|
||||||
{
|
{
|
||||||
if (rules.getBoolean ("verbose"))
|
if (rules.getBoolean ("verbose"))
|
||||||
|
{
|
||||||
std::cout << intervalSummarize (database, rules, interval);
|
std::cout << intervalSummarize (database, rules, interval);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
return 0;
|
||||||
if (rules.getBoolean ("verbose"))
|
}
|
||||||
{
|
|
||||||
if (rules.getBoolean ("temp.shiny"))
|
if (rules.getBoolean ("temp.shiny"))
|
||||||
|
{
|
||||||
std::cout << '\n'
|
std::cout << '\n'
|
||||||
<< "Welcome to Timewarrior.\n"
|
<< "Welcome to Timewarrior.\n"
|
||||||
<< '\n'
|
<< '\n'
|
||||||
|
@ -55,12 +58,15 @@ int CmdDefault (Rules& rules, Database& database)
|
||||||
<< "There is a fully-detailed man page:\n"
|
<< "There is a fully-detailed man page:\n"
|
||||||
<< " man timew\n"
|
<< " man timew\n"
|
||||||
<< '\n';
|
<< '\n';
|
||||||
else
|
return 0;
|
||||||
std::cout << "There is no active time tracking.\n";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
if (rules.getBoolean ("verbose"))
|
||||||
|
{
|
||||||
|
std::cout << "There is no active time tracking.\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
16
test/cli.t
16
test/cli.t
|
@ -28,6 +28,7 @@
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
import unittest
|
import unittest
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
# Ensure python finds the local simpletap module
|
# Ensure python finds the local simpletap module
|
||||||
|
@ -57,16 +58,27 @@ class TestCLI(TestCase):
|
||||||
"""Executed before each test in the class"""
|
"""Executed before each test in the class"""
|
||||||
self.t = Timew()
|
self.t = Timew()
|
||||||
|
|
||||||
|
def test_initial_call_of_timew(self):
|
||||||
|
"""Verify that calling 'timew' the first time returns exit code 0"""
|
||||||
|
self.t.reset_env()
|
||||||
|
shutil.rmtree(self.t.env["TIMEWARRIORDB"])
|
||||||
|
|
||||||
|
code, out, err = self.t.runSuccess(":yes")
|
||||||
|
self.assertIn("Welcome to Timewarrior.\n", out)
|
||||||
|
|
||||||
|
assert os.path.isdir(self.t.env["TIMEWARRIORDB"])
|
||||||
|
assert os.path.exists(self.t.env["TIMEWARRIORDB"])
|
||||||
|
|
||||||
def test_TimeWarrior_without_command_without_active_time_tracking(self):
|
def test_TimeWarrior_without_command_without_active_time_tracking(self):
|
||||||
"""Call 'timew' without active time tracking"""
|
"""Call 'timew' without active time tracking"""
|
||||||
code, out, err = self.t()
|
code, out, err = self.t.runError()
|
||||||
self.assertIn("There is no active time tracking", out)
|
self.assertIn("There is no active time tracking", out)
|
||||||
|
|
||||||
def test_TimeWarrior_without_command_with_active_time_tracking(self):
|
def test_TimeWarrior_without_command_with_active_time_tracking(self):
|
||||||
"""Call 'timew' with active time tracking"""
|
"""Call 'timew' with active time tracking"""
|
||||||
self.t("start FOO")
|
self.t("start FOO")
|
||||||
code, out, err = self.t()
|
code, out, err = self.t()
|
||||||
self.assertIn("Tracking FOO", out)
|
self.assertIn("Tracking FOO\n", out)
|
||||||
|
|
||||||
def test_TimeWarrior_with_invalid_command(self):
|
def test_TimeWarrior_with_invalid_command(self):
|
||||||
"""Call a non-existing TimeWarrior command should be an error"""
|
"""Call a non-existing TimeWarrior command should be an error"""
|
||||||
|
|
10
test/clock.t
10
test/clock.t
|
@ -63,7 +63,7 @@ class TestClock(TestCase):
|
||||||
|
|
||||||
def test_start_new(self):
|
def test_start_new(self):
|
||||||
"""Verify that 'start' creates an open interval"""
|
"""Verify that 'start' creates an open interval"""
|
||||||
code, out, err = self.t("")
|
code, out, err = self.t.runError("")
|
||||||
self.assertIn("There is no active time tracking.", out)
|
self.assertIn("There is no active time tracking.", out)
|
||||||
|
|
||||||
code, out, err = self.t("start tag1 tag2")
|
code, out, err = self.t("start tag1 tag2")
|
||||||
|
@ -76,7 +76,7 @@ class TestClock(TestCase):
|
||||||
|
|
||||||
def test_start_stop(self):
|
def test_start_stop(self):
|
||||||
"""Verify that start/stop creates and closes an interval"""
|
"""Verify that start/stop creates and closes an interval"""
|
||||||
code, out, err = self.t("")
|
code, out, err = self.t.runError("")
|
||||||
self.assertIn("There is no active time tracking.", out)
|
self.assertIn("There is no active time tracking.", out)
|
||||||
|
|
||||||
code, out, err = self.t("start tag1 tag2")
|
code, out, err = self.t("start tag1 tag2")
|
||||||
|
@ -90,12 +90,12 @@ class TestClock(TestCase):
|
||||||
self.assertIn('"end":', out)
|
self.assertIn('"end":', out)
|
||||||
self.assertIn('"tags":["tag1","tag2"]', out)
|
self.assertIn('"tags":["tag1","tag2"]', out)
|
||||||
|
|
||||||
code, out, err = self.t("")
|
code, out, err = self.t.runError("")
|
||||||
self.assertIn("There is no active time tracking.", out)
|
self.assertIn("There is no active time tracking.", out)
|
||||||
|
|
||||||
def test_start_additional(self):
|
def test_start_additional(self):
|
||||||
"""Verify that 'start' closes an open interval and starts a new one"""
|
"""Verify that 'start' closes an open interval and starts a new one"""
|
||||||
code, out, err = self.t("")
|
code, out, err = self.t.runError("")
|
||||||
self.assertIn("There is no active time tracking.", out)
|
self.assertIn("There is no active time tracking.", out)
|
||||||
|
|
||||||
code, out, err = self.t("start tag1 tag2")
|
code, out, err = self.t("start tag1 tag2")
|
||||||
|
@ -114,7 +114,7 @@ class TestClock(TestCase):
|
||||||
self.assertIn('"tags":["tag1","tag2"]', out)
|
self.assertIn('"tags":["tag1","tag2"]', out)
|
||||||
self.assertIn('"tags":["tag3"]', out)
|
self.assertIn('"tags":["tag3"]', out)
|
||||||
|
|
||||||
code, out, err = self.t("")
|
code, out, err = self.t.runError("")
|
||||||
self.assertIn("There is no active time tracking.", out)
|
self.assertIn("There is no active time tracking.", out)
|
||||||
|
|
||||||
def test_start_subtract(self):
|
def test_start_subtract(self):
|
||||||
|
|
|
@ -58,10 +58,10 @@ class TestQuietMode(TestCase):
|
||||||
|
|
||||||
def test_default(self):
|
def test_default(self):
|
||||||
"""Default command should obey :quiet hint"""
|
"""Default command should obey :quiet hint"""
|
||||||
code, out, err = self.t("")
|
code, out, err = self.t.runError("")
|
||||||
self.assertIn('There is no active time tracking.', out)
|
self.assertIn('There is no active time tracking.', out)
|
||||||
|
|
||||||
code, out, err = self.t(":quiet")
|
code, out, err = self.t.runError(":quiet")
|
||||||
self.assertNotIn('There is no active time tracking.', out)
|
self.assertNotIn('There is no active time tracking.', out)
|
||||||
|
|
||||||
def test_stop(self):
|
def test_stop(self):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue