From 23d4e2b3c98fc1c7d6627cb211fd322151c4d759 Mon Sep 17 00:00:00 2001 From: Renato Alves Date: Mon, 2 Mar 2015 22:16:14 +0000 Subject: [PATCH 01/20] Tests - rename bug.1023.t to feature.default.project.t and convert to python Also add testcase from TW-1287 and TW-1279 which are part of the same feature --- test/bug.1023.t | 76 --------- test/feature.default.project.t | 278 +++++++++++++++++++++++++++++++++ 2 files changed, 278 insertions(+), 76 deletions(-) delete mode 100755 test/bug.1023.t create mode 100755 test/feature.default.project.t diff --git a/test/bug.1023.t b/test/bug.1023.t deleted file mode 100755 index a9dc78036..000000000 --- a/test/bug.1023.t +++ /dev/null @@ -1,76 +0,0 @@ -#! /usr/bin/env perl -################################################################################ -## -## Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez. -## -## Permission is hereby granted, free of charge, to any person obtaining a copy -## of this software and associated documentation files (the "Software"), to deal -## in the Software without restriction, including without limitation the rights -## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -## copies of the Software, and to permit persons to whom the Software is -## furnished to do so, subject to the following conditions: -## -## The above copyright notice and this permission notice shall be included -## in all copies or substantial portions of the Software. -## -## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -## OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -## SOFTWARE. -## -## http://www.opensource.org/licenses/mit-license.php -## -################################################################################ - -use strict; -use warnings; -use Test::More tests => 9; - -# Ensure environment has no influence. -delete $ENV{'TASKDATA'}; -delete $ENV{'TASKRC'}; - -use File::Basename; -my $ut = basename ($0); -my $rc = $ut . '.rc'; - -# Create the rc file. -if (open my $fh, '>', $rc) -{ - print $fh "data.location=.\n", - "default.project=home\n"; - close $fh; -} - -# Bug 1023: rc.default.project gets applied during modify, and should not. -qx{../src/task rc:$rc add foo project:garden 2>&1}; -qx{../src/task rc:$rc add bar 2>&1}; -qx{../src/task rc:$rc add baz rc.default.project= 2>&1}; - -my $output = qx{../src/task rc:$rc 1 info 2>&1}; -like ($output, qr/Project\s*garden/, "$ut: default project not applied when otherwise specified."); - -$output = qx{../src/task rc:$rc 2 info 2>&1}; -like ($output, qr/Project\s*home/, "$ut: default project applied when blank."); - -$output = qx{../src/task rc:$rc 3 info 2>&1}; -like ($output, qr/^Description\s+baz$/m, "$ut: task baz shown."); -unlike ($output, qr/Project\s*home/, "$ut: no project applied when default project is blank."); - -$output = qx{../src/task rc:$rc 3 modify +tag 2>&1}; -like ($output, qr/^Modified 1 task.$/m, "$ut: task modified."); -unlike ($output, qr/Project\s*home/, "$ut: default project not applied on modification."); - -qx{../src/task rc:$rc 1 modify project: 2>&1}; -$output = qx{../src/task rc:$rc 1 info 2>&1}; -like ($output, qr/^Description\s+foo$/m, "$ut: task foo shown."); -unlike ($output, qr/Project\s*garden/, "$ut: default project not re-applied on attribute removal."); -unlike ($output, qr/Project\s*home/, "$ut: default project not re-applied on attribute removal."); - -# Cleanup. -unlink qw(pending.data completed.data undo.data backlog.data), $rc; -exit 0; - diff --git a/test/feature.default.project.t b/test/feature.default.project.t new file mode 100755 index 000000000..8577c6233 --- /dev/null +++ b/test/feature.default.project.t @@ -0,0 +1,278 @@ +#!/usr/bin/env python2.7 +# -*- coding: utf-8 -*- +############################################################################### +# +# Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# +# http://www.opensource.org/licenses/mit-license.php +# +############################################################################### + +import sys +import os +import unittest +# Ensure python finds the local simpletap module +sys.path.append(os.path.dirname(os.path.abspath(__file__))) + +from basetest import Task, TestCase, Taskd, ServerTestCase + + +class TestDefaultProject(TestCase): + """Bug 1023: rc.default.project gets applied during modify, and should not + """ + def setUp(self): + self.t = Task() + + def set_default_project(self): + self.default_project = "HOMEPROJ" + self.t.config("default.project", self.default_project) + + def test_with_project(self): + """default.project not applied when specified nor on attribute removal + """ + self.set_default_project() + + self.t(("add", "foobar", "project:garden")) + code, out, err = self.t("1", "info") + + self.assertIn("foobar", out) + + expected = "Project\s+garden" + self.assertRegexpMatches(out, expected) + + self.t(("1", "modify", "project:")) + code, out, err = self.t("1", "info") + + self.assertIn("foobar", out) + self.assertNotRegexpMatches(out, expected) + + notexpected = "Project\s+" + self.default_project + self.assertNotRegexpMatches(out, notexpected) + + def test_without_project(self): + """default.project applied when no project is specified""" + self.set_default_project() + + self.t(("add", "foobar")) + code, out, err = self.t("1", "info") + + self.assertIn("foobar", out) + + expected = "Project\s+" + self.default_project + self.assertRegexpMatches(out, expected) + + def test_default_project_inline_override(self): + """no project applied when default.project is overridden""" + self.set_default_project() + + self.t(("add", "foobar", "rc.default.project=")) + code, out, err = self.t("1", "info") + + self.assertIn("foobar", out) + self.assertNotIn("Project", out) + + def test_without_default_project(self): + """no project applied when default.project is blank""" + self.t(("add", "foobar")) + code, out, err = self.t("1", "info") + + self.assertIn("foobar", out) + self.assertNotIn("Project", out) + + def test_modify_default_project(self): + """default.project is not applied when modifying a task""" + self.t(("add", "foobar")) + code, out, err = self.t("1", "info") + + self.assertIn("foobar", out) + self.assertNotIn("Project", out) + + self.set_default_project() + + self.t(("1", "modify", "+tag")) + code, out, err = self.t("1", "info") + self.assertNotIn("Project", out) + + def test_annotate_default_project(self): + """default.project is not applied when annotating a task""" + self.t(("add", "foobar")) + code, out, err = self.t("1", "info") + + self.assertIn("foobar", out) + self.assertNotIn("Project", out) + + self.set_default_project() + + self.t(("1", "annotate", "Hello")) + code, out, err = self.t("1", "info") + + expected = "Description\s+foobar\n[0-9-: ]+ Hello" + self.assertRegexpMatches(out, expected) + self.assertNotIn("Project", out) + + def test_time_default_project(self): + """default.project is not applied when start/stop'ing a task""" + # Allow keeping track of time spent on task + self.t.config("journal.time", "yes") + + self.t(("add", "foobar")) + code, out, err = self.t("1", "info") + + self.assertIn("foobar", out) + self.assertNotIn("Project", out) + + self.set_default_project() + + self.t(("1", "start")) + self.t(("1", "stop")) + code, out, err = self.t("1", "info") + + self.assertIn("foobar", out) + self.assertNotIn("Project", out) + + def test_recurring_parent_default_project(self): + """default.project is applied on recurring parent tasks""" + self.set_default_project() + + DESC = "foobar" + self.t(("add", "recur:daily", "due:today", DESC)) + self.t() # Ensure creation of recurring children + code, out, err = self.t(("1", "info")) + + self.assertIn(DESC, out) + self.assertRegexpMatches(out, "Status\s+Recurring") # is a parent task + self.assertIn(self.default_project, out) + + self.t.faketime("+1d") + + self.t() # Ensure creation of recurring children + # Try to figure out the ID of last created task + code, out, err = self.t(("count",)) + + # Will fail if some other message is printed as part of "count" + id = out.split()[-1] + + try: + id = int(id) + except ValueError: + raise ValueError("Unexpected output when running 'task count', " + "expected int, got '{0}'".format(id)) + else: + # parent task is not considered when counting + id = str(id + 1) + + code, out, err = self.t(id, "info") + + self.assertIn(DESC, out) + self.assertIn("Parent task", out) # is a child task + self.assertIn(self.default_project, out) + + def test_recurring_default_project(self): + """no project is applied on recurring tasks""" + # NOTE - reported on TW-1279 + DESC = "foobar" + self.t(("add", "recur:daily", "due:today", DESC)) + code, out, err = self.t() + + self.assertIn(DESC, out) + self.assertNotIn("Project", out) + + self.set_default_project() + + self.t.faketime("+1d") + + code, out, err = self.t() + + self.assertIn(DESC, out) + self.assertNotIn("Project", out) + + def test_recurring_with_project_and_default_project(self): + """default.project is not applied to children if parent has a project + """ + # NOTE - reported on TW-1279 + self.set_default_project() + + DESC = "foobar" + self.t(("add", "recur:daily", "due:today", "project:HELLO", DESC)) + code, out, err = self.t() + + self.assertIn(DESC, out) + self.assertIn("HELLO", out) + + self.t.faketime("+1d") + + code, out, err = self.t() + + self.assertIn("foobar", out) + self.assertIn("HELLO", out) + self.assertNotIn(self.default_project, out) + + +class ServerTestDefaultProject(ServerTestCase): + @classmethod + def setUpClass(cls): + cls.taskd = Taskd() + # This takes a while... + cls.taskd.start() + + def setUp(self): + self.t1 = Task(taskd=self.taskd) + self.t2 = Task(taskd=self.taskd) + self.t3 = Task(taskd=self.taskd) + + def test_default_project_sync(self): + """default.project is not applied to projectless tasks during sync""" + # NOTE - reported on TW-1287 + desc = "Testing task" + self.t1(("add", desc)) + self.t1(("sync",)) + + code, out, err = self.t1() + + self.assertIn(desc, out) + + # Testing scenario - default.project is applied on task arrival + proj2 = "Client2" + self.t2.config("default.project", proj2) + self.t2(("sync",)) + + code, out, err = self.t2() + self.assertIn(desc, out) + self.assertNotIn(proj2, out) + + self.t2(("sync",)) + + # Testing scenario - default.project is applied on task delivery + proj3 = "Client3" + self.t3.config("default.project", proj3) + self.t3(("sync",)) + + code, out, err = self.t3() + self.assertIn(desc, out) + self.assertNotIn(proj2, out) + self.assertNotIn(proj3, out) + + +if __name__ == "__main__": + from simpletap import TAPTestRunner + unittest.main(testRunner=TAPTestRunner()) + +# vim: ai sts=4 et sw=4 From 180c382de27ea8ab4a2793168c88396fafeebf1d Mon Sep 17 00:00:00 2001 From: Renato Alves Date: Tue, 3 Mar 2015 01:46:53 +0000 Subject: [PATCH 02/20] Tests - Finer control on which binaries to look for on PATH * It is now possible to control whether taskw and/or taskd are looked up on the PATH by setting TASK_USE_PATH/TASKD_USE_PATH to "1" --- test/basetest/task.py | 6 +++--- test/basetest/taskd.py | 5 +++-- test/basetest/utils.py | 21 ++++++++++++++++++--- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/test/basetest/task.py b/test/basetest/task.py index 73c0d2af0..cf13465ce 100644 --- a/test/basetest/task.py +++ b/test/basetest/task.py @@ -5,8 +5,8 @@ import tempfile import shutil import atexit import unittest -from .utils import (run_cmd_wait, run_cmd_wait_nofail, which, binary_location, - ) +from .utils import (run_cmd_wait, run_cmd_wait_nofail, which, + task_binary_location) from .exceptions import CommandError from .hooks import Hooks @@ -22,7 +22,7 @@ class Task(object): A taskw client should not be used after being destroyed. """ - DEFAULT_TASK = binary_location("task") + DEFAULT_TASK = task_binary_location() def __init__(self, taskd=None, taskw=DEFAULT_TASK): """Initialize a Task warrior (client) that can interact with a taskd diff --git a/test/basetest/taskd.py b/test/basetest/taskd.py index 209ae7da8..50f56ac9f 100644 --- a/test/basetest/taskd.py +++ b/test/basetest/taskd.py @@ -8,7 +8,8 @@ import atexit from time import sleep from subprocess import Popen from .utils import (find_unused_port, release_port, port_used, run_cmd_wait, - which, parse_datafile, DEFAULT_CERT_PATH, binary_location) + which, parse_datafile, DEFAULT_CERT_PATH, + taskd_binary_location) from .exceptions import CommandError try: @@ -30,7 +31,7 @@ class Taskd(object): A server can be stopped and started multiple times, but should not be started or stopped after being destroyed. """ - DEFAULT_TASKD = binary_location("taskd") + DEFAULT_TASKD = taskd_binary_location() def __init__(self, taskd=DEFAULT_TASKD, certpath=None, address="localhost"): diff --git a/test/basetest/utils.py b/test/basetest/utils.py index b644ddd3f..8bc321158 100644 --- a/test/basetest/utils.py +++ b/test/basetest/utils.py @@ -41,13 +41,28 @@ DEFAULT_HOOK_PATH = os.path.abspath( TASKW_SKIP = os.environ.get("TASKW_SKIP", False) TASKD_SKIP = os.environ.get("TASKD_SKIP", False) # Environment flags to control use of PATH or in-tree binaries -USE_PATH = os.environ.get("USE_PATH", False) +TASK_USE_PATH = os.environ.get("TASK_USE_PATH", False) +TASKD_USE_PATH = os.environ.get("TASKD_USE_PATH", False) UUID_regex = ("[0-9A-Fa-f]{8}-" + ("[0-9A-Fa-f]{4}-" * 3) + "[0-9A-Fa-f]{12}") -def binary_location(cmd): - """If USE_PATH is set rely on PATH to look for task/taskd binaries. +def task_binary_location(cmd="task"): + """If TASK_USE_PATH is set rely on PATH to look for task binaries. + Otherwise ../src/ is used by default. + """ + return binary_location(cmd, TASK_USE_PATH) + + +def taskd_binary_location(cmd="taskd"): + """If TASKD_USE_PATH is set rely on PATH to look for taskd binaries. + Otherwise ../src/ is used by default. + """ + return binary_location(cmd, TASKD_USE_PATH) + + +def binary_location(cmd, USE_PATH=False): + """If USE_PATH is True rely on PATH to look for taskd binaries. Otherwise ../src/ is used by default. """ if USE_PATH: From b5da4acab977a8dafa9aebdbe27dc7b50bf3e5ce Mon Sep 17 00:00:00 2001 From: Renato Alves Date: Tue, 3 Mar 2015 01:50:57 +0000 Subject: [PATCH 03/20] Tests - run_all script now exports TASKD_USE_PATH=1 --- test/run_all.in | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/run_all.in b/test/run_all.in index a2bb06c68..635c9ace0 100755 --- a/test/run_all.in +++ b/test/run_all.in @@ -1,5 +1,8 @@ #! /bin/sh +# Look for taskd in $PATH instead of task/src/ +export TASKD_USE_PATH=1 + rc=0 if [ x"$1" = x"--verbose" ]; then From 7fa3c5ac84d7cc66832a38b7013ca08fe8672f07 Mon Sep 17 00:00:00 2001 From: Renato Alves Date: Wed, 4 Mar 2015 00:54:40 +0000 Subject: [PATCH 04/20] Tests - convert bug.1031.t to python --- test/bug.1031.t | 120 ++++++++++++++++++++++++++---------------------- 1 file changed, 65 insertions(+), 55 deletions(-) diff --git a/test/bug.1031.t b/test/bug.1031.t index c3aea00ad..958d19162 100755 --- a/test/bug.1031.t +++ b/test/bug.1031.t @@ -1,65 +1,75 @@ -#! /usr/bin/env perl -################################################################################ -## -## Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez. -## -## Permission is hereby granted, free of charge, to any person obtaining a copy -## of this software and associated documentation files (the "Software"), to deal -## in the Software without restriction, including without limitation the rights -## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -## copies of the Software, and to permit persons to whom the Software is -## furnished to do so, subject to the following conditions: -## -## The above copyright notice and this permission notice shall be included -## in all copies or substantial portions of the Software. -## -## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -## OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -## SOFTWARE. -## -## http://www.opensource.org/licenses/mit-license.php -## -################################################################################ +#!/usr/bin/env python2.7 +# -*- coding: utf-8 -*- +############################################################################### +# +# Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# +# http://www.opensource.org/licenses/mit-license.php +# +############################################################################### -use strict; -use warnings; -use Test::More tests => 3; +import sys +import os +import unittest +# Ensure python finds the local simpletap module +sys.path.append(os.path.dirname(os.path.abspath(__file__))) -# Ensure environment has no influence. -delete $ENV{'TASKDATA'}; -delete $ENV{'TASKRC'}; +from basetest import Task, TestCase -use File::Basename; -my $ut = basename ($0); -my $rc = $ut . '.rc'; -# Create the rc file. -if (open my $fh, '>', $rc) -{ - print $fh "data.location=.\n", - "alias.from=to\n"; - close $fh; -} +class TestBug1031(TestCase): + def setUp(self): + """Executed before each test in the class""" + # Used to initialize objects that should be re-initialized or + # re-created for each individual test + self.t = Task() -# Bug 1031: -- does not bypass aliasing -qx{../src/task rc:$rc add from 2>&1}; -qx{../src/task rc:$rc add from -- to 2>&1}; -qx{../src/task rc:$rc add to -- from 2>&1}; + self.t.config("alias.from", "to") -my $output = qx{../src/task rc:$rc 1 info 2>&1}; -like ($output, qr/Description\s+to$/ms, "$ut: 'from' --> 'to'"); + def test_alias_to(self): + """alias working as expected: 'from' -> 'to'""" + self.t(("add", "from")) + code, out, err = self.t(("1", "info")) -$output = qx{../src/task rc:$rc 2 info 2>&1}; -like ($output, qr/Description\s+to to$/ms, "$ut: 'from -- to' --> 'to to'"); + expected = "Description\s+to" + self.assertRegexpMatches(out, expected) -$output = qx{../src/task rc:$rc 3 info 2>&1}; -like ($output, qr/Description\s+to from$/ms, "$ut: 'to -- from' --> 'to from'"); + def test_alias_to_to(self): + """alias working as expected: 'from -- to' -> 'to to'""" + self.t(("add", "from", "--", "to")) + code, out, err = self.t(("1", "info")) -# Cleanup. -unlink qw(pending.data completed.data undo.data backlog.data), $rc; -exit 0; + expected = "Description\s+to to" + self.assertRegexpMatches(out, expected) + def test_alias_to_from(self): + """alias working as expected: 'to -- from' -> 'to from'""" + self.t(("add", "to", "--", "from")) + code, out, err = self.t(("1", "info")) + + expected = "Description\s+to from" + self.assertRegexpMatches(out, expected) + +if __name__ == "__main__": + from simpletap import TAPTestRunner + unittest.main(testRunner=TAPTestRunner()) + +# vim: ai sts=4 et sw=4 From 138360b7bc77c838aa62622ffde09ce2d027777a Mon Sep 17 00:00:00 2001 From: Wilhelm Schuermann Date: Thu, 5 Mar 2015 09:23:56 +0100 Subject: [PATCH 05/20] Hooks - Fixed on-modify hook regression which stopped hooks from modifying tasks. On a related note, more hooks tests are definitely needed. --- ChangeLog | 2 ++ src/Hooks.cpp | 1 + 2 files changed, 3 insertions(+) diff --git a/ChangeLog b/ChangeLog index 009c569ed..c6a422317 100644 --- a/ChangeLog +++ b/ChangeLog @@ -22,6 +22,8 @@ forks (thanks to Jens Erat). - Re-enabled hook script feedback when exiting with 0 exit status. - The 'info' command now shows virtual tags. +- Fixed major on-modify hooks regression where hooks could no longer modify + the tasks handed to them. ------ current release --------------------------- diff --git a/src/Hooks.cpp b/src/Hooks.cpp index f1f99d1c8..a2eb0cea8 100644 --- a/src/Hooks.cpp +++ b/src/Hooks.cpp @@ -358,6 +358,7 @@ void Hooks::onModify (const Task& before, Task& after) throw 0; // This is how hooks silently terminate processing. } } + after = Task (input[1]); } context.timer_hooks.stop (); From 5e8426f0cc69d7f5d027cc91852027a0c2ee8c0f Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Thu, 5 Mar 2015 18:26:43 -0500 Subject: [PATCH 06/20] Config MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - The 'next' report was not sㄡrted by urgency, which is wrong (thanks to Adam Coddington). --- src/Config.cpp | 2 +- src/Hooks.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Config.cpp b/src/Config.cpp index f13bb9168..05c8042f7 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -433,7 +433,7 @@ std::string Config::_defaults = "report.next.labels=ID,Active,Age,Deps,P,Project,Tag,Recur,S,Due,Until,Description,Urg\n" "report.next.columns=id,start.age,entry.age,depends,priority,project,tags,recur,scheduled.countdown,due.remaining,until.remaining,description,urgency\n" "report.next.filter=status:pending limit:page\n" - "report.next.sort=start-,urgency-\n" + "report.next.sort=urgency-\n" "\n" "report.ready.description=Most urgent actionable tasks\n" "report.ready.labels=ID,Active,Age,D,P,Project,Tags,R,S,Due,Until,Description,Urg\n" diff --git a/src/Hooks.cpp b/src/Hooks.cpp index a2eb0cea8..cad0f0c7d 100644 --- a/src/Hooks.cpp +++ b/src/Hooks.cpp @@ -358,6 +358,7 @@ void Hooks::onModify (const Task& before, Task& after) throw 0; // This is how hooks silently terminate processing. } } + after = Task (input[1]); } From 197815a3a788787882c9fb25bd73dedb2603caa6 Mon Sep 17 00:00:00 2001 From: Renato Alves Date: Fri, 6 Mar 2015 15:10:07 +0000 Subject: [PATCH 07/20] Tests - convert bug.1036.t to python --- test/bug.1036.t | 112 +++++++++++++++++++++++++----------------------- 1 file changed, 58 insertions(+), 54 deletions(-) diff --git a/test/bug.1036.t b/test/bug.1036.t index 2da7d19d0..579d91516 100755 --- a/test/bug.1036.t +++ b/test/bug.1036.t @@ -1,63 +1,67 @@ -#! /usr/bin/env perl -################################################################################ -## -## Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez. -## -## Permission is hereby granted, free of charge, to any person obtaining a copy -## of this software and associated documentation files (the "Software"), to deal -## in the Software without restriction, including without limitation the rights -## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -## copies of the Software, and to permit persons to whom the Software is -## furnished to do so, subject to the following conditions: -## -## The above copyright notice and this permission notice shall be included -## in all copies or substantial portions of the Software. -## -## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -## OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -## SOFTWARE. -## -## http://www.opensource.org/licenses/mit-license.php -## -################################################################################ +#!/usr/bin/env python2.7 +# -*- coding: utf-8 -*- +############################################################################### +# +# Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# +# http://www.opensource.org/licenses/mit-license.php +# +############################################################################### -use strict; -use warnings; -use Test::More tests => 2; +import sys +import os +import unittest +# Ensure python finds the local simpletap module +sys.path.append(os.path.dirname(os.path.abspath(__file__))) -# Ensure environment has no influence. -delete $ENV{'TASKDATA'}; -delete $ENV{'TASKRC'}; +from basetest import Task, TestCase -use File::Basename; -my $ut = basename ($0); -my $rc = $ut . '.rc'; -# Create the rc file. -if (open my $fh, '>', $rc) -{ - print $fh "data.location=.\n", - "dateformat=m/d/Y\n"; - close $fh; -} +class TestBug1036(TestCase): + "'until' attribute should be modifiable in non-recurring tasks" -# Bug #1036: prevents 'until' attributes to be modified for non-recurring -# tasks. + def setUp(self): + self.t = Task() -# Check that until attribute may be modified -qx{../src/task rc:$rc add test 2>&1}; -my $output = qx{../src/task rc:$rc 1 mod until:1/1/2020 2>&1}; -like ($output, qr/^Modifying task 1 'test'.$/ms, "$ut: 'until' attribute added"); + self.t.config("dateformat", "m/d/Y") -qx{../src/task rc:$rc add test until:1/1/2020 2>&1}; -$output = qx{../src/task rc:$rc 1 mod /test/Test/ 2>&1}; -like ($output, qr/^Modifying task 1 'Test'.$/ms, "$ut: Task with 'until' attribute modified"); + def test_until_may_modify(self): + """check that until attribute may be modified""" + self.t(("add", "test")) + code, out, err = self.t(("1", "mod", "until:1/1/2020")) -# Cleanup. -unlink qw(pending.data completed.data undo.data backlog.data), $rc; -exit 0; + expected = "Modifying task 1 'test'." + self.assertIn(expected, out) + def test_may_modify_on_until(self): + """check that task with until attribute set may be modified""" + self.t(("add", "test", "until:1/1/2020")) + code, out, err = self.t(("1", "mod", "/test/Hello/")) + + expected = "Modifying task 1 'Hello'." + self.assertIn(expected, out) + + +if __name__ == "__main__": + from simpletap import TAPTestRunner + unittest.main(testRunner=TAPTestRunner()) + +# vim: ai sts=4 et sw=4 From 276050ce0b84bf10ec59ef661126aab8c119642b Mon Sep 17 00:00:00 2001 From: Renato Alves Date: Fri, 6 Mar 2015 15:19:04 +0000 Subject: [PATCH 08/20] Tests - rename bug.1043.t to completion.t and convert to python --- test/bug.1043.t | 63 ----------------------------------------- test/completion.t | 71 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 63 deletions(-) delete mode 100755 test/bug.1043.t create mode 100755 test/completion.t diff --git a/test/bug.1043.t b/test/bug.1043.t deleted file mode 100755 index 7c394217f..000000000 --- a/test/bug.1043.t +++ /dev/null @@ -1,63 +0,0 @@ -#! /usr/bin/env perl -################################################################################ -## -## Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez. -## -## Permission is hereby granted, free of charge, to any person obtaining a copy -## of this software and associated documentation files (the "Software"), to deal -## in the Software without restriction, including without limitation the rights -## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -## copies of the Software, and to permit persons to whom the Software is -## furnished to do so, subject to the following conditions: -## -## The above copyright notice and this permission notice shall be included -## in all copies or substantial portions of the Software. -## -## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -## OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -## SOFTWARE. -## -## http://www.opensource.org/licenses/mit-license.php -## -################################################################################ - -use strict; -use warnings; -use Test::More tests => 5; - -# Ensure environment has no influence. -delete $ENV{'TASKDATA'}; -delete $ENV{'TASKRC'}; - -use File::Basename; -my $ut = basename ($0); -my $rc = $ut . '.rc'; - -# Create the rc file. -if (open my $fh, '>', $rc) -{ - print $fh "data.location=.\n"; - print $fh "alias.samplealias=long\n"; - - close $fh; -} - -# Bug - aliases should be listed by '_aliases' and not by '_commands' or '_zshcommands' -my $output = qx{../src/task rc:$rc _aliases 2>&1}; -like ($output, qr/samplealias/, "$ut: aliases are listed in _aliases"); - -$output = qx{../src/task rc:$rc _commands 2>&1}; -like ($output, qr/^information$/m, "$ut: info is listed in _commands"); -unlike ($output, qr/samplealias/, "$ut: aliases are not listed in _commands"); - -$output = qx{../src/task rc:$rc _zshcommands 2>&1}; -like ($output, qr/^information:/m, "$ut: info is listed in _zshcommands"); -unlike ($output, qr/samplealias/, "$ut: aliases are not listed in _zshcommands"); - -# Cleanup. -unlink qw(pending.data completed.data undo.data backlog.data), $rc; -exit 0; diff --git a/test/completion.t b/test/completion.t new file mode 100755 index 000000000..63def44c7 --- /dev/null +++ b/test/completion.t @@ -0,0 +1,71 @@ +#!/usr/bin/env python2.7 +# -*- coding: utf-8 -*- +############################################################################### +# +# Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# +# http://www.opensource.org/licenses/mit-license.php +# +############################################################################### + +import sys +import os +import unittest +# Ensure python finds the local simpletap module +sys.path.append(os.path.dirname(os.path.abspath(__file__))) + +from basetest import Task, TestCase + + +class TestAliasesCompletion(TestCase): + """Aliases should be listed by '_aliases' not '_commands' or '_zshcommands' + reported as bug 1043 + """ + def setUp(self): + self.t = Task() + self.t.config("alias.samplealias", "long") + + def test__aliases(self): + """samplealias in _aliases""" + code, out, err = self.t(("_aliases",)) + + self.assertIn("samplealias", out) + + def test__commands(self): + """samplealias not in _commands""" + code, out, err = self.t(("_commands",)) + + self.assertIn("information", out) + self.assertNotIn("samplealias", out) + + def test__zshcommands(self): + """samplealias not in _zshcommands""" + code, out, err = self.t(("_zshcommands",)) + + self.assertIn("information", out) + self.assertNotIn("samplealias", out) + + +if __name__ == "__main__": + from simpletap import TAPTestRunner + unittest.main(testRunner=TAPTestRunner()) + +# vim: ai sts=4 et sw=4 From ebd69774803ec6a0293f354407daf6d5226d2000 Mon Sep 17 00:00:00 2001 From: Renato Alves Date: Fri, 6 Mar 2015 16:44:28 +0000 Subject: [PATCH 09/20] Tests - merge bug.1044 into project.t and convert to python --- test/bug.1044.t | 62 -------------- test/project.t | 209 ++++++++++++++++++++++++++++-------------------- 2 files changed, 121 insertions(+), 150 deletions(-) delete mode 100755 test/bug.1044.t diff --git a/test/bug.1044.t b/test/bug.1044.t deleted file mode 100755 index 802cb8ebf..000000000 --- a/test/bug.1044.t +++ /dev/null @@ -1,62 +0,0 @@ -#! /usr/bin/env perl -################################################################################ -## -## Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez. -## -## Permission is hereby granted, free of charge, to any person obtaining a copy -## of this software and associated documentation files (the "Software"), to deal -## in the Software without restriction, including without limitation the rights -## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -## copies of the Software, and to permit persons to whom the Software is -## furnished to do so, subject to the following conditions: -## -## The above copyright notice and this permission notice shall be included -## in all copies or substantial portions of the Software. -## -## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -## OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -## SOFTWARE. -## -## http://www.opensource.org/licenses/mit-license.php -## -################################################################################ - -use strict; -use warnings; -use Test::More tests => 1; - -# Ensure environment has no influence. -delete $ENV{'TASKDATA'}; -delete $ENV{'TASKRC'}; - -use File::Basename; -my $ut = basename ($0); -my $rc = $ut . '.rc'; - -# Create the rc file. -if (open my $fh, '>', $rc) -{ - print $fh "data.location=.\n", - "confirmation=off\n"; - close $fh; -} - -# Bug #1044: 'task projects' considers newly deleted tasks and provides an -# incorrect summary - -# Check that until attribute may be modified -qx{../src/task rc:$rc add project:A 1 2>&1}; -qx{../src/task rc:$rc add project:B 2 2>&1}; -qx{../src/task rc:$rc add project:B 3 2>&1}; -qx{../src/task rc:$rc 3 delete 2>&1}; -my $output = qx{../src/task rc:$rc project:B projects 2>&1}; -like ($output, qr/^1 project \(1 task\)$/ms, "$ut: Summary filtered new deleted task 3 and project A"); - -# Cleanup. -unlink qw(pending.data completed.data undo.data backlog.data), $rc; -exit 0; - diff --git a/test/project.t b/test/project.t index c84e43c5c..a4e89dc1b 100755 --- a/test/project.t +++ b/test/project.t @@ -1,111 +1,144 @@ -#! /usr/bin/env perl -################################################################################ -## -## Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez. -## -## Permission is hereby granted, free of charge, to any person obtaining a copy -## of this software and associated documentation files (the "Software"), to deal -## in the Software without restriction, including without limitation the rights -## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -## copies of the Software, and to permit persons to whom the Software is -## furnished to do so, subject to the following conditions: -## -## The above copyright notice and this permission notice shall be included -## in all copies or substantial portions of the Software. -## -## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -## OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -## SOFTWARE. -## -## http://www.opensource.org/licenses/mit-license.php -## -################################################################################ +#!/usr/bin/env python2.7 +# -*- coding: utf-8 -*- +############################################################################### +# +# Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# +# http://www.opensource.org/licenses/mit-license.php +# +############################################################################### -use strict; -use warnings; -use Test::More tests => 16; +import sys +import os +import unittest +# Ensure python finds the local simpletap module +sys.path.append(os.path.dirname(os.path.abspath(__file__))) -# Ensure environment has no influence. -delete $ENV{'TASKDATA'}; -delete $ENV{'TASKRC'}; +from basetest import Task, TestCase -use File::Basename; -my $ut = basename ($0); -my $rc = $ut . '.rc'; -# Create the rc file. -if (open my $fh, '>', $rc) -{ - print $fh "data.location=.\n", - "confirmation=off\n"; - close $fh; -} +class TestProjects(TestCase): + def setUp(self): + self.t = Task() -# Test the project status numbers. -my $output = qx{../src/task rc:$rc add one pro:foo 2>&1 >/dev/null}; -like ($output, qr/The project 'foo' has changed\. Project 'foo' is 0% complete \(1 task remaining\)\./, "$ut: add one"); + self.STATUS = ("The project '{0}' has changed\. " + "Project '{0}' is {1} complete \({2} remaining\)\.") -$output = qx{../src/task rc:$rc add two pro:'foo' 2>&1 >/dev/null}; -like ($output, qr/The project 'foo' has changed\. Project 'foo' is 0% complete \(2 of 2 tasks remaining\)\./, "$ut: add two"); + def test_project_summary_count(self): + """'task projects' shouldn't consider deleted tasks in summary. + Reported in bug 1044 + """ + self.t(("add", "project:A", "1")) + self.t(("add", "project:B", "2")) + self.t(("add", "project:B", "3")) + self.t(("3", "delete")) + code, out, err = self.t(("project:B", "projects")) -$output = qx{../src/task rc:$rc add three pro:'foo' 2>&1 >/dev/null}; -like ($output, qr/The project 'foo' has changed\. Project 'foo' is 0% complete \(3 of 3 tasks remaining\)\./, "$ut: add three"); + expected = "1 project \(1 task\)" + self.assertRegexpMatches(out, expected) -$output = qx{../src/task rc:$rc add four pro:'foo' 2>&1 >/dev/null}; -like ($output, qr/The project 'foo' has changed\. Project 'foo' is 0% complete \(4 of 4 tasks remaining\)\./, "$ut: add four"); + def test_project_progress(self): + """project status/progress is shown and is up-to-date""" -$output = qx{../src/task rc:$rc 1 done 2>&1 >/dev/null}; -like ($output, qr/Project 'foo' is 25% complete \(3 of 4 tasks remaining\)\./, "$ut: done one"); + code, out, err = self.t(("add", "one", "pro:foo")) + self.assertRegexpMatches(err, self.STATUS.format("foo", "0%", + "1 task")) -$output = qx{../src/task rc:$rc 2 delete 2>&1 >/dev/null}; -like ($output, qr/The project 'foo' has changed\. Project 'foo' is 33% complete \(2 of 3 tasks remaining\)\./, "$ut: delete two"); + code, out, err = self.t(("add", "two", "pro:foo")) + self.assertRegexpMatches(err, self.STATUS.format("foo", "0%", + "2 of 2 tasks")) -$output = qx{../src/task rc:$rc 3 modify pro:bar 2>&1 >/dev/null}; -like ($output, qr/The project 'foo' has changed\. Project 'foo' is 50% complete \(1 of 2 tasks remaining\)\./, "$ut: change project"); -like ($output, qr/The project 'bar' has changed\. Project 'bar' is 0% complete \(1 task remaining\)\./, "$ut: change project"); + code, out, err = self.t(("add", "three", "pro:foo")) + self.assertRegexpMatches(err, self.STATUS.format("foo", "0%", + "3 of 3 tasks")) -# Test projects with spaces in them. -$output = qx{../src/task rc:$rc 3 modify pro:"foo bar" 2>&1 >/dev/null}; -like ($output, qr/The project 'foo bar' has changed\./, "$ut: project with spaces"); + code, out, err = self.t(("add", "four", "pro:foo")) + self.assertRegexpMatches(err, self.STATUS.format("foo", "0%", + "4 of 4 tasks")) -# Bug 1056: Project indentation. -# see also the tests of helper functions for CmdProjects in util.t.cpp -qx{../src/task rc:$rc add testing project:existingParent 2>&1 >/dev/null}; -qx{../src/task rc:$rc add testing project:existingParent.child 2>&1 >/dev/null}; -qx{../src/task rc:$rc add testing project:abstractParent.kid 2>&1 >/dev/null}; -qx{../src/task rc:$rc add testing project:.myProject 2>&1 >/dev/null}; -qx{../src/task rc:$rc add testing project:myProject. 2>&1 >/dev/null}; -qx{../src/task rc:$rc add testing project:.myProject. 2>&1 >/dev/null}; + code, out, err = self.t(("1", "done")) + self.assertRegexpMatches(err, self.STATUS.format("foo", "25%", + "3 of 4 tasks")) -$output = qx{../src/task rc:$rc projects 2>&1}; -my @lines = split ('\n',$output); + code, out, err = self.t(("2", "delete")) + self.assertRegexpMatches(err, self.STATUS.format("foo", "33%", + "2 of 3 tasks")) -my ($project_name_column) = $lines[4] =~ /^(\s*\S+)/; -like ($project_name_column, qr/^\.myProject$/, "$ut: '.myProject' not indented"); + code, out, err = self.t(("3", "modify", "pro:bar")) + self.assertRegexpMatches(err, self.STATUS.format("foo", "50%", + "1 of 2 tasks")) + self.assertRegexpMatches(err, self.STATUS.format("bar", "0%", + "1 task")) -($project_name_column) = $lines[5] =~ /^(\s*\S+)/; -like ($project_name_column, qr/^\.myProject\.$/, "$ut: '.myProject.' not indented"); + def test_project_spaces(self): + """projects with spaces are handled correctly""" -($project_name_column) = $lines[6] =~ /^(\s*\S+)/; -like ($project_name_column, qr/^abstractParent$/, "$ut: abstract parent not indented"); + self.t(("add", "hello", "pro:bob")) + code, out, err = self.t(("1", "mod", 'pro:"foo bar"')) + self.assertRegexpMatches(err, self.STATUS.format("foo bar", "0%", + "1 task")) -($project_name_column) = $lines[7] =~ /^(\s*\S+)/; -like ($project_name_column, qr/^ kid$/, "$ut: child indented and without parent name"); + def test_project_indentation(self): + """check project/subproject indentation -($project_name_column) = $lines[8] =~ /^(\s*\S+)/; -like ($project_name_column, qr/^existingParent$/, "$ut: existing parent not indented"); + Reported in bug 1056 -($project_name_column) = $lines[9] =~ /^(\s*\S+)/; -like ($project_name_column, qr/^ child$/, "$ut: child of existing parent indented and without parent name"); + See also the tests of helper functions for CmdProjects in util.t.cpp + """ + self.t(("add", "testing", "project:existingParent")) + self.t(("add", "testing", "project:existingParent.child")) + self.t(("add", "testing", "project:abstractParent.kid")) + self.t(("add", "testing", "project:.myProject")) + self.t(("add", "testing", "project:myProject")) + self.t(("add", "testing", "project:.myProject.")) -($project_name_column) = $lines[12] =~ /^(\s*\S+)/; -like ($project_name_column, qr/^myProject\.$/, "$ut: 'myProject.' not indented"); + code, out, err = self.t(("projects",)) -# Cleanup. -unlink qw(pending.data completed.data undo.data backlog.data), $rc; -exit 0; + order = ( + # NOTE all but abstractParent have 1 task hence the trailing space + ".myProject ", + ".myProject. ", + "abstractParent\n", + " kid ", + "existingParent ", + " child ", + "myProject ", + ) + lines = out.splitlines(True) # True = keep newlines + # position where project names start on the lines list + position = 3 + + for i, proj in enumerate(order): + pos = position + i + + self.assertTrue( + lines[pos].startswith(proj), + msg=("Project '{0}' is not in line #{1} or has an unexpected " + "indentation.{2}".format(proj, pos, out)) + ) + + +if __name__ == "__main__": + from simpletap import TAPTestRunner + unittest.main(testRunner=TAPTestRunner()) + +# vim: ai sts=4 et sw=4 From a2cae67644056cf4a93de4f35ecb61a1ab48115c Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 7 Mar 2015 11:11:18 -0500 Subject: [PATCH 10/20] Unit Tests - Converted filter-prefix.t to Python. Still needs a rename and possible merge with other tests. --- test/filter-prefix.t | 246 +++++++++++++++++++++++-------------------- 1 file changed, 130 insertions(+), 116 deletions(-) diff --git a/test/filter-prefix.t b/test/filter-prefix.t index 213ef63db..468d95bb3 100755 --- a/test/filter-prefix.t +++ b/test/filter-prefix.t @@ -1,130 +1,144 @@ -#! /usr/bin/env perl -################################################################################ -## -## Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez. -## -## Permission is hereby granted, free of charge, to any person obtaining a copy -## of this software and associated documentation files (the "Software"), to deal -## in the Software without restriction, including without limitation the rights -## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -## copies of the Software, and to permit persons to whom the Software is -## furnished to do so, subject to the following conditions: -## -## The above copyright notice and this permission notice shall be included -## in all copies or substantial portions of the Software. -## -## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -## OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -## SOFTWARE. -## -## http://www.opensource.org/licenses/mit-license.php -## -################################################################################ +#!/usr/bin/env python2.7 +# -*- coding: utf-8 -*- +############################################################################### +# +# Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# +# http://www.opensource.org/licenses/mit-license.php +# +############################################################################### -use strict; -use warnings; -use Test::More tests => 56; +import sys +import os +import unittest +from datetime import datetime +# Ensure python finds the local simpletap module +sys.path.append(os.path.dirname(os.path.abspath(__file__))) -# Ensure environment has no influence. -delete $ENV{'TASKDATA'}; -delete $ENV{'TASKRC'}; +from basetest import Task, TestCase -use File::Basename; -my $ut = basename ($0); -my $rc = $ut . '.rc'; -# Create the rc file. -if (open my $fh, '>', $rc) -{ - print $fh "data.location=.\n"; - close $fh; -} +class TestFilterPrefix(TestCase): + @classmethod + def setUpClass(cls): + """Executed once before any test in the class""" + cls.t = Task() + cls.t.config("verbose", "nothing") -# Test the filters. -qx{../src/task rc:$rc add project:foo.uno priority:H +tag one foo 2>&1}; -qx{../src/task rc:$rc add project:foo.dos priority:H two 2>&1}; -qx{../src/task rc:$rc add project:foo.tres three 2>&1}; -qx{../src/task rc:$rc add project:bar.uno priority:H four 2>&1}; -qx{../src/task rc:$rc add project:bar.dos +tag five 2>&1}; -qx{../src/task rc:$rc add project:bar.tres six foo 2>&1}; -qx{../src/task rc:$rc add project:bazuno seven bar foo 2>&1}; -qx{../src/task rc:$rc add project:bazdos eight bar foo 2>&1}; + cls.t(('add', 'project:foo.uno', 'priority:H', '+tag', 'one foo' )) + cls.t(('add', 'project:foo.dos', 'priority:H', 'two' )) + cls.t(('add', 'project:foo.tres', 'three' )) + cls.t(('add', 'project:bar.uno', 'priority:H', 'four' )) + cls.t(('add', 'project:bar.dos', '+tag', 'five' )) + cls.t(('add', 'project:bar.tres', 'six foo' )) + cls.t(('add', 'project:bazuno', 'seven bar foo')) + cls.t(('add', 'project:bazdos', 'eight bar foo')) -my $output = qx{../src/task rc:$rc list 2>&1}; -like ($output, qr/one/, 'a1'); -like ($output, qr/two/, 'a2'); -like ($output, qr/three/, 'a3'); -like ($output, qr/four/, 'a4'); -like ($output, qr/five/, 'a5'); -like ($output, qr/six/, 'a6'); -like ($output, qr/seven/, 'a7'); -like ($output, qr/eight/, 'a8'); + def test_list_all(self): + """No filter shows all tasks.""" + code, out, err = self.t(('list',)) + self.assertIn('one', out) + self.assertIn('two', out) + self.assertIn('three', out) + self.assertIn('four', out) + self.assertIn('five', out) + self.assertIn('six', out) + self.assertIn('seven', out) + self.assertIn('eight', out) -$output = qx{../src/task rc:$rc list project:foo 2>&1}; -like ($output, qr/one/, 'b1'); -like ($output, qr/two/, 'b2'); -like ($output, qr/three/, 'b3'); -unlike ($output, qr/four/, 'b4'); -unlike ($output, qr/five/, 'b5'); -unlike ($output, qr/six/, 'b6'); -unlike ($output, qr/seven/, 'b7'); -unlike ($output, qr/eight/, 'b8'); + def test_list_project_foo(self): + """No filter shows all tasks.""" + code, out, err = self.t(('list', 'project:foo')) + self.assertIn('one', out) + self.assertIn('two', out) + self.assertIn('three', out) + self.assertNotIn('four', out) + self.assertNotIn('five', out) + self.assertNotIn('six', out) + self.assertNotIn('seven', out) + self.assertNotIn('eight', out) -$output = qx{../src/task rc:$rc list project.not:foo 2>&1}; -unlike ($output, qr/one/, 'c1'); -unlike ($output, qr/two/, 'c2'); -unlike ($output, qr/three/, 'c3'); -like ($output, qr/four/, 'c4'); -like ($output, qr/five/, 'c5'); -like ($output, qr/six/, 'c6'); -like ($output, qr/seven/, 'c7'); -like ($output, qr/eight/, 'c8'); + def test_list_project_not_foo(self): + """No filter shows all tasks.""" + code, out, err = self.t(('list', 'project.not:foo')) + self.assertNotIn('one', out) + self.assertNotIn('two', out) + self.assertNotIn('three', out) + self.assertIn('four', out) + self.assertIn('five', out) + self.assertIn('six', out) + self.assertIn('seven', out) + self.assertIn('eight', out) -$output = qx{../src/task rc:$rc list project.startswith:bar 2>&1}; -unlike ($output, qr/one/, 'd1'); -unlike ($output, qr/two/, 'd2'); -unlike ($output, qr/three/, 'd3'); -like ($output, qr/four/, 'd4'); -like ($output, qr/five/, 'd5'); -like ($output, qr/six/, 'd6'); -unlike ($output, qr/seven/, 'd7'); -unlike ($output, qr/eight/, 'd8'); + def test_list_project_startwsith_bar(self): + """No filter shows all tasks.""" + code, out, err = self.t(('list', 'project.startswith:bar')) + self.assertNotIn('one', out) + self.assertNotIn('two', out) + self.assertNotIn('three', out) + self.assertIn('four', out) + self.assertIn('five', out) + self.assertIn('six', out) + self.assertNotIn('seven', out) + self.assertNotIn('eight', out) -$output = qx{../src/task rc:$rc list project:ba 2>&1}; -unlike ($output, qr/one/, 'f1'); -unlike ($output, qr/two/, 'f2'); -unlike ($output, qr/three/, 'f3'); -like ($output, qr/four/, 'f4'); -like ($output, qr/five/, 'f5'); -like ($output, qr/six/, 'f6'); -like ($output, qr/seven/, 'f7'); -like ($output, qr/eight/, 'f8'); + def test_list_project_ba(self): + """No filter shows all tasks.""" + code, out, err = self.t(('list', 'project:ba')) + self.assertNotIn('one', out) + self.assertNotIn('two', out) + self.assertNotIn('three', out) + self.assertIn('four', out) + self.assertIn('five', out) + self.assertIn('six', out) + self.assertIn('seven', out) + self.assertIn('eight', out) -$output = qx{../src/task rc:$rc list project.not:ba 2>&1}; -like ($output, qr/one/, 'g1'); -like ($output, qr/two/, 'g2'); -like ($output, qr/three/, 'g3'); -unlike ($output, qr/four/, 'g4'); -unlike ($output, qr/five/, 'g5'); -unlike ($output, qr/six/, 'g6'); -unlike ($output, qr/seven/, 'g7'); -unlike ($output, qr/eight/, 'g8'); + def test_list_project_not_ba(self): + """No filter shows all tasks.""" + code, out, err = self.t(('list', 'project.not:ba')) + self.assertIn('one', out) + self.assertIn('two', out) + self.assertIn('three', out) + self.assertNotIn('four', out) + self.assertNotIn('five', out) + self.assertNotIn('six', out) + self.assertNotIn('seven', out) + self.assertNotIn('eight', out) -$output = qx{../src/task rc:$rc list description.has:foo 2>&1}; -like ($output, qr/one/, 'i1'); -unlike ($output, qr/two/, 'i2'); -unlike ($output, qr/three/, 'i3'); -unlike ($output, qr/four/, 'i4'); -unlike ($output, qr/five/, 'i5'); -like ($output, qr/six/, 'i6'); -like ($output, qr/seven/, 'i7'); -like ($output, qr/eight/, 'i8'); + def test_list_descrtiption_has_foo(self): + """No filter shows all tasks.""" + code, out, err = self.t(('list', 'description.has:foo')) + self.assertIn('one', out) + self.assertNotIn('two', out) + self.assertNotIn('three', out) + self.assertNotIn('four', out) + self.assertNotIn('five', out) + self.assertIn('six', out) + self.assertIn('seven', out) + self.assertIn('eight', out) -# Cleanup. -unlink qw(pending.data completed.data undo.data backlog.data), $rc; -exit 0; +if __name__ == "__main__": + from simpletap import TAPTestRunner + unittest.main(testRunner=TAPTestRunner()) + +# vim: ai sts=4 et sw=4 From d390f99fc5c9a7a3178a65e9b3de02b80ed34390 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 7 Mar 2015 11:35:48 -0500 Subject: [PATCH 11/20] Unit Tests - Simplified the msg.t.cpp tests. --- test/msg.t.cpp | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/test/msg.t.cpp b/test/msg.t.cpp index da19d9bc2..1f630c2ca 100644 --- a/test/msg.t.cpp +++ b/test/msg.t.cpp @@ -25,8 +25,6 @@ //////////////////////////////////////////////////////////////////////////////// #include -#include -#include #include #include #include @@ -38,10 +36,6 @@ int main (int argc, char** argv) { UnitTest t (12); - // Ensure environment has no influence. - unsetenv ("TASKDATA"); - unsetenv ("TASKRC"); - Msg m; t.is (m.serialize (), std::string ("client: ") + PACKAGE_STRING + "\n\n\n", "Msg::serialize '' --> '\\n\\n'"); @@ -55,16 +49,17 @@ int main (int argc, char** argv) t.is (m.serialize (), std::string ("client: ") + PACKAGE_STRING + "\nfoo: bar\nname: value\n\npayload\n", "Msg::serialize 2 vars + payload"); Msg m2; - t.ok (m2.parse ("foo: bar\nname: value\n\npayload\n"), "Msg::parse ok"); - t.is (m2.get ("foo"), "bar", "Msg::get"); - t.is (m2.get ("name"), "value", "Msg::get"); - t.is (m2.getPayload (), "payload\n", "Msg::getPayload"); + t.ok (m2.parse ("foo: bar\nname: value\n\npayload\n"), "Msg::parse ok"); + t.is (m2.get ("foo"), "bar", "Msg::get"); + t.is (m2.get ("name"), "value", "Msg::get"); + t.is (m2.getPayload (), "payload\n", "Msg::getPayload"); Msg m3; t.ok (m3.parse ("foo:bar\nname: value\n\npayload\n"), "Msg::parse ok"); - t.is (m3.get ("foo"), "bar", "Msg::get"); - t.is (m3.get ("name"), "value", "Msg::get"); - t.is (m3.getPayload (), "payload\n", "Msg::getPayload"); + t.is (m3.get ("foo"), "bar", "Msg::get"); + t.is (m3.get ("name"), "value", "Msg::get"); + t.is (m3.getPayload (), "payload\n", "Msg::getPayload"); + return 0; } From 3cf7a701c83f32f0ecffcddae04464ca046d1967 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 7 Mar 2015 11:38:52 -0500 Subject: [PATCH 12/20] Conversion - Updated script for BSD. --- test/conversion | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/conversion b/test/conversion index ae8bd200e..f5e98580e 100755 --- a/test/conversion +++ b/test/conversion @@ -4,7 +4,7 @@ printf "C++: %5d\n" $(ls *.t.cpp | wc -l) printf "Python: %5d\n" $(head -n1 *.t | grep -a '\bpython' | wc -l) printf "Perl: %5d\n" $(head -n1 *.t | grep -a '\bperl\b' | wc -l) if [ "$1" = "-v" ]; then - echo -n "Perl left: "; echo $(grep -l '^#\! \?/usr/bin/env perl\b' *.t) + echo "Perl left: " $(grep -l '^#\! \?/usr/bin/env perl\b' *.t) fi echo printf "Feature %5d\n" $(ls feature.*.t | wc -l) From 44ed974fa2c0f7e9b2697e0357557a7db829c291 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 7 Mar 2015 11:44:44 -0500 Subject: [PATCH 13/20] Unit Tests - Fixed all the test descriptions. --- test/filter-prefix.t | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/filter-prefix.t b/test/filter-prefix.t index 468d95bb3..00e9f62ae 100755 --- a/test/filter-prefix.t +++ b/test/filter-prefix.t @@ -65,7 +65,7 @@ class TestFilterPrefix(TestCase): self.assertIn('eight', out) def test_list_project_foo(self): - """No filter shows all tasks.""" + """Filter on project name.""" code, out, err = self.t(('list', 'project:foo')) self.assertIn('one', out) self.assertIn('two', out) @@ -77,7 +77,7 @@ class TestFilterPrefix(TestCase): self.assertNotIn('eight', out) def test_list_project_not_foo(self): - """No filter shows all tasks.""" + """Filter on not project name.""" code, out, err = self.t(('list', 'project.not:foo')) self.assertNotIn('one', out) self.assertNotIn('two', out) @@ -89,7 +89,7 @@ class TestFilterPrefix(TestCase): self.assertIn('eight', out) def test_list_project_startwsith_bar(self): - """No filter shows all tasks.""" + """Filter on project name start.""" code, out, err = self.t(('list', 'project.startswith:bar')) self.assertNotIn('one', out) self.assertNotIn('two', out) @@ -101,7 +101,7 @@ class TestFilterPrefix(TestCase): self.assertNotIn('eight', out) def test_list_project_ba(self): - """No filter shows all tasks.""" + """Filter on project partial match.""" code, out, err = self.t(('list', 'project:ba')) self.assertNotIn('one', out) self.assertNotIn('two', out) @@ -113,7 +113,7 @@ class TestFilterPrefix(TestCase): self.assertIn('eight', out) def test_list_project_not_ba(self): - """No filter shows all tasks.""" + """Filter on project partial non-match.""" code, out, err = self.t(('list', 'project.not:ba')) self.assertIn('one', out) self.assertIn('two', out) @@ -125,7 +125,7 @@ class TestFilterPrefix(TestCase): self.assertNotIn('eight', out) def test_list_descrtiption_has_foo(self): - """No filter shows all tasks.""" + """Filter on description pattern.""" code, out, err = self.t(('list', 'description.has:foo')) self.assertIn('one', out) self.assertNotIn('two', out) From 9d1c4101c230fd95ab1183569928b89eb1e315e0 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 7 Mar 2015 11:48:42 -0500 Subject: [PATCH 14/20] Unit Tests - Renamed feature.exit.t to shell.t so that this test script is known to contain shell-interaction tests. - Converted to Python. --- test/feature.exit.t | 57 ------------------------------------------ test/shell.t | 60 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 57 deletions(-) delete mode 100755 test/feature.exit.t create mode 100755 test/shell.t diff --git a/test/feature.exit.t b/test/feature.exit.t deleted file mode 100755 index 0f32d68fc..000000000 --- a/test/feature.exit.t +++ /dev/null @@ -1,57 +0,0 @@ -#! /usr/bin/env perl -################################################################################ -## -## Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez. -## -## Permission is hereby granted, free of charge, to any person obtaining a copy -## of this software and associated documentation files (the "Software"), to deal -## in the Software without restriction, including without limitation the rights -## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -## copies of the Software, and to permit persons to whom the Software is -## furnished to do so, subject to the following conditions: -## -## The above copyright notice and this permission notice shall be included -## in all copies or substantial portions of the Software. -## -## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -## OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -## SOFTWARE. -## -## http://www.opensource.org/licenses/mit-license.php -## -################################################################################ - -use strict; -use warnings; -use Test::More tests => 2; - -# Ensure environment has no influence. -delete $ENV{'TASKDATA'}; -delete $ENV{'TASKRC'}; - -use File::Basename; -my $ut = basename ($0); -my $rc = $ut . '.rc'; - -# Create the rc file. -if (open my $fh, '>', $rc) -{ - print $fh "data.location=.\n", - "confirmation=no\n"; - close $fh; -} - -qx{../src/task rc:$rc add foo 2>&1}; -my $exit_good = system ("../src/task rc:$rc ls /foo/ >/dev/null 2>&1") >> 8; -is ($exit_good, 0, "$ut: task returns 0 on success"); -my $exit_bad = system ("../src/task rc:$rc ls /bar/ >/dev/null 2>&1") >> 8; -isnt ($exit_bad, 0, "$ut: task returns non-zero on failure"); - -# Cleanup. -unlink qw(pending.data completed.data undo.data backlog.data), $rc; -exit 0; - diff --git a/test/shell.t b/test/shell.t new file mode 100755 index 000000000..217a4b539 --- /dev/null +++ b/test/shell.t @@ -0,0 +1,60 @@ +#!/usr/bin/env python2.7 +# -*- coding: utf-8 -*- +############################################################################### +# +# Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# +# http://www.opensource.org/licenses/mit-license.php +# +############################################################################### + +import sys +import os +import unittest +from datetime import datetime +# Ensure python finds the local simpletap module +sys.path.append(os.path.dirname(os.path.abspath(__file__))) + +from basetest import Task, TestCase + + +class TestFilterPrefix(TestCase): + @classmethod + def setUpClass(cls): + """Executed once before any test in the class""" + cls.t = Task() + cls.t.config("verbose", "nothing") + cls.t(('add', 'foo')) + + def test_success(self): + """Test successful search returns zero.""" + code, out, err = self.t(('list', '/foo/')) + + def test_failure(self): + """Test failed search returns non-zero.""" + code, out, err = self.t.runError(('list', '/bar/')) + + +if __name__ == "__main__": + from simpletap import TAPTestRunner + unittest.main(testRunner=TAPTestRunner()) + +# vim: ai sts=4 et sw=4 From 70c3d9845c20ff887d83621e1f544660bac1ff89 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 7 Mar 2015 11:59:37 -0500 Subject: [PATCH 15/20] =?UTF-8?q?Un=D1=96t=20Tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Merged width.t.cpp into utf8.t.cpp. --- test/.gitignore | 1 - test/CMakeLists.txt | 4 +-- test/utf8.t.cpp | 60 +++++++++++++++++++++++++----------------- test/width.t.cpp | 63 --------------------------------------------- 4 files changed, 38 insertions(+), 90 deletions(-) delete mode 100644 test/width.t.cpp diff --git a/test/.gitignore b/test/.gitignore index b04d2bb3e..ce5e6d22e 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -53,7 +53,6 @@ variant_partial.t variant_subtract.t variant_xor.t view.t -width.t json_test diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f4c2c810f..48ac35060 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -8,8 +8,8 @@ include_directories (${CMAKE_SOURCE_DIR} set (test_SRCS autocomplete.t color.t config.t date.t directory.t dom.t file.t i18n.t json.t list.t msg.t nibbler.t path.t rx.t t.t t2.t - t3.t tdb2.t text.t utf8.t util.t view.t width.t json_test - iso8601d.t iso8601p.t duration.t lexer.t variant_add.t + t3.t tdb2.t text.t utf8.t util.t view.t json_test lexer.t + iso8601d.t iso8601p.t duration.t variant_add.t variant_and.t variant_cast.t variant_divide.t variant_equal.t variant_exp.t variant_gt.t variant_gte.t variant_inequal.t variant_lt.t variant_lte.t variant_match.t variant_math.t diff --git a/test/utf8.t.cpp b/test/utf8.t.cpp index 893ac45b9..b191a0ce9 100644 --- a/test/utf8.t.cpp +++ b/test/utf8.t.cpp @@ -25,45 +25,39 @@ //////////////////////////////////////////////////////////////////////////////// #include -#include -#include #include #include //////////////////////////////////////////////////////////////////////////////// int main (int argc, char** argv) { - UnitTest t (17); + UnitTest t (33); - // Ensure environment has no influence. - unsetenv ("TASKDATA"); - unsetenv ("TASKRC"); - - std::string ascii_text = "This is a test"; - std::string utf8_text = "más sábado miércoles"; - std::string utf8_wide_text = "改变各种颜色"; + std::string ascii_text = "This is a test"; + std::string utf8_text = "más sábado miércoles"; + std::string utf8_wide_text = "改变各种颜色"; std::string ascii_text_color = "This is a test"; std::string utf8_text_color = "más sábado miércoles"; std::string utf8_wide_text_color = "改变各种颜色"; // unsigned int utf8_codepoint (const std::string&); - t.is ((int) utf8_codepoint ("\\u0020"), 32, "\\u0020 --> ' '"); - t.is ((int) utf8_codepoint ("U+0020"), 32, "U+0020 --> ' '"); + t.is ((int) utf8_codepoint ("\\u0020"), 32, "\\u0020 --> ' '"); + t.is ((int) utf8_codepoint ("U+0020"), 32, "U+0020 --> ' '"); // TODO unsigned int utf8_next_char (const std::string&, std::string::size_type&); // TODO std::string utf8_character (unsigned int); // TODO int utf8_sequence (unsigned int); // unsigned int utf8_length (const std::string&); - t.is ((int) utf8_length (ascii_text), 14, "ASCII utf8_length"); - t.is ((int) utf8_length (utf8_text), 20, "UTF8 utf8_length"); - t.is ((int) utf8_length (utf8_wide_text), 6, "UTF8 wide utf8_length"); + t.is ((int) utf8_length (ascii_text), 14, "ASCII utf8_length"); + t.is ((int) utf8_length (utf8_text), 20, "UTF8 utf8_length"); + t.is ((int) utf8_length (utf8_wide_text), 6, "UTF8 wide utf8_length"); // unsigned int utf8_width (const std::string&); - t.is ((int) utf8_width (ascii_text), 14, "ASCII utf8_width"); - t.is ((int) utf8_width (utf8_text), 20, "UTF8 utf8_width"); - t.is ((int) utf8_width (utf8_wide_text), 12, "UTF8 wide utf8_width"); + t.is ((int) utf8_width (ascii_text), 14, "ASCII utf8_width"); + t.is ((int) utf8_width (utf8_text), 20, "UTF8 utf8_width"); + t.is ((int) utf8_width (utf8_wide_text), 12, "UTF8 wide utf8_width"); // unsigned int utf8_text_length (const std::string&); t.is ((int) utf8_text_length (ascii_text_color), 14, "ASCII utf8_text_length"); @@ -71,14 +65,32 @@ int main (int argc, char** argv) t.is ((int) utf8_text_length (utf8_wide_text_color), 6, "UTF8 wide utf8_text_length"); // unsigned int utf8_text_width (const std::string&); - t.is ((int) utf8_text_width (ascii_text_color), 14, "ASCII utf8_text_width"); - t.is ((int) utf8_text_width (utf8_text_color), 20, "UTF8 utf8_text_width"); - t.is ((int) utf8_text_width (utf8_wide_text_color), 12, "UTF8 wide utf8_text_width"); + t.is ((int) utf8_text_width (ascii_text_color), 14, "ASCII utf8_text_width"); + t.is ((int) utf8_text_width (utf8_text_color), 20, "UTF8 utf8_text_width"); + t.is ((int) utf8_text_width (utf8_wide_text_color), 12, "UTF8 wide utf8_text_width"); // const std::string utf8_substr (const std::string&, unsigned int, unsigned int length = 0); - t.is (utf8_substr (ascii_text, 0, 2), "Th", "ASCII utf8_substr"); - t.is (utf8_substr (utf8_text, 0, 2), "má", "UTF8 utf8_substr"); - t.is (utf8_substr (utf8_wide_text, 0, 2), "改变", "UTF8 wide utf8_substr"); + t.is (utf8_substr (ascii_text, 0, 2), "Th", "ASCII utf8_substr"); + t.is (utf8_substr (utf8_text, 0, 2), "má", "UTF8 utf8_substr"); + t.is (utf8_substr (utf8_wide_text, 0, 2), "改变", "UTF8 wide utf8_substr"); + + // int mk_wcwidth (wchar_t); + t.is (mk_wcwidth ('a'), 1, "mk_wcwidth U+0061 --> 1"); + t.is (mk_wcwidth (0x5149), 2, "mk_wcwidth U+5149 --> 2"); + t.is (mk_wcwidth (0x9a8c), 2, "mk_wcwidth U+9a8c --> 2"); + t.is (mk_wcwidth (0x4e70), 2, "mk_wcwidth U+4e70 --> 2"); + t.is (mk_wcwidth (0x94b1), 2, "mk_wcwidth U+94b1 --> 2"); + t.is (mk_wcwidth (0x5305), 2, "mk_wcwidth U+5305 --> 2"); + t.is (mk_wcwidth (0x91cd), 2, "mk_wcwidth U+91cd --> 2"); + t.is (mk_wcwidth (0x65b0), 2, "mk_wcwidth U+65b0 --> 2"); + t.is (mk_wcwidth (0x8bbe), 2, "mk_wcwidth U+8bbe --> 2"); + t.is (mk_wcwidth (0x8ba1), 2, "mk_wcwidth U+8ba1 --> 2"); + t.is (mk_wcwidth (0x5411), 2, "mk_wcwidth U+5411 --> 2"); + t.is (mk_wcwidth (0x4e0a), 2, "mk_wcwidth U+4e0a --> 2"); + t.is (mk_wcwidth (0x4e0b), 2, "mk_wcwidth U+4e0b --> 2"); + t.is (mk_wcwidth (0x7bad), 2, "mk_wcwidth U+7bad --> 2"); + t.is (mk_wcwidth (0x5934), 2, "mk_wcwidth U+5934 --> 2"); + t.is (mk_wcwidth (0xff0c), 2, "mk_wcwidth U+ff0c --> 2"); // comma return 0; } diff --git a/test/width.t.cpp b/test/width.t.cpp deleted file mode 100644 index 23616b8b7..000000000 --- a/test/width.t.cpp +++ /dev/null @@ -1,63 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez. -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -// -// http://www.opensource.org/licenses/mit-license.php -// -//////////////////////////////////////////////////////////////////////////////// - -#include -#include -#include -#include -#include - -//////////////////////////////////////////////////////////////////////////////// -int main (int argc, char** argv) -{ - UnitTest t (16); - - // Ensure environment has no influence. - unsetenv ("TASKDATA"); - unsetenv ("TASKRC"); - - t.is (mk_wcwidth ('a'), 1, "U+0061 --> 1"); - - t.is (mk_wcwidth (0x5149), 2, "U+5149 --> 2"); - t.is (mk_wcwidth (0x9a8c), 2, "U+9a8c --> 2"); - t.is (mk_wcwidth (0x4e70), 2, "U+4e70 --> 2"); - t.is (mk_wcwidth (0x94b1), 2, "U+94b1 --> 2"); - t.is (mk_wcwidth (0x5305), 2, "U+5305 --> 2"); - t.is (mk_wcwidth (0x91cd), 2, "U+91cd --> 2"); - t.is (mk_wcwidth (0x65b0), 2, "U+65b0 --> 2"); - t.is (mk_wcwidth (0x8bbe), 2, "U+8bbe --> 2"); - t.is (mk_wcwidth (0x8ba1), 2, "U+8ba1 --> 2"); - t.is (mk_wcwidth (0x5411), 2, "U+5411 --> 2"); - t.is (mk_wcwidth (0x4e0a), 2, "U+4e0a --> 2"); - t.is (mk_wcwidth (0x4e0b), 2, "U+4e0b --> 2"); - t.is (mk_wcwidth (0x7bad), 2, "U+7bad --> 2"); - t.is (mk_wcwidth (0x5934), 2, "U+5934 --> 2"); - t.is (mk_wcwidth (0xff0c), 2, "U+ff0c --> 2"); // comma - - return 0; -} - -//////////////////////////////////////////////////////////////////////////////// From e3ec52f6cac4b06d84b01dc3b9ecb947639b648b Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 7 Mar 2015 12:14:39 -0500 Subject: [PATCH 16/20] Unit Tests - Cleaned up color.t.cpp. --- test/color.t.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/test/color.t.cpp b/test/color.t.cpp index 38f29c36a..b2f8e420d 100644 --- a/test/color.t.cpp +++ b/test/color.t.cpp @@ -36,11 +36,7 @@ Context context; //////////////////////////////////////////////////////////////////////////////// int main (int argc, char** argv) { - UnitTest t (1036); - - // Ensure environment has no influence. - unsetenv ("TASKDATA"); - unsetenv ("TASKRC"); + UnitTest t (40 + 256 + 256 + 6*6*6 + 6*6*6 + 1 + 24 + 24 + 3); // Names matched to values. t.is ((int) Color (""), (int) Color (Color::nocolor), "'' == Color::nocolor"); From 87e95786669c2cd529d98c9e776d17771bb8637a Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 7 Mar 2015 13:29:59 -0500 Subject: [PATCH 17/20] Unit Tests - Combined all the separate color rule tests into one script, and converted it to Python. --- test/color.active.t | 57 ----------- test/color.blocked.t | 58 ----------- test/color.disable.t | 62 ------------ test/color.due.t | 57 ----------- test/color.err.t | 62 ------------ test/color.keyword.t | 66 ------------ test/color.overdue.t | 57 ----------- test/color.pri.t | 64 ------------ test/color.project.t | 58 ----------- test/color.recurring.t | 57 ----------- test/color.rules.t | 222 +++++++++++++++++++++++++++++++++++++++++ test/color.tag.t | 62 ------------ test/color.tagged.t | 60 ----------- test/color.uda.t | 63 ------------ 14 files changed, 222 insertions(+), 783 deletions(-) delete mode 100755 test/color.active.t delete mode 100755 test/color.blocked.t delete mode 100755 test/color.disable.t delete mode 100755 test/color.due.t delete mode 100755 test/color.err.t delete mode 100755 test/color.keyword.t delete mode 100755 test/color.overdue.t delete mode 100755 test/color.pri.t delete mode 100755 test/color.project.t delete mode 100755 test/color.recurring.t create mode 100755 test/color.rules.t delete mode 100755 test/color.tag.t delete mode 100755 test/color.tagged.t delete mode 100755 test/color.uda.t diff --git a/test/color.active.t b/test/color.active.t deleted file mode 100755 index 5dcdf0511..000000000 --- a/test/color.active.t +++ /dev/null @@ -1,57 +0,0 @@ -#! /usr/bin/env perl -################################################################################ -## -## Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez. -## -## Permission is hereby granted, free of charge, to any person obtaining a copy -## of this software and associated documentation files (the "Software"), to deal -## in the Software without restriction, including without limitation the rights -## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -## copies of the Software, and to permit persons to whom the Software is -## furnished to do so, subject to the following conditions: -## -## The above copyright notice and this permission notice shall be included -## in all copies or substantial portions of the Software. -## -## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -## OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -## SOFTWARE. -## -## http://www.opensource.org/licenses/mit-license.php -## -################################################################################ - -use strict; -use warnings; -use Test::More tests => 2; - -# Ensure environment has no influence. -delete $ENV{'TASKDATA'}; -delete $ENV{'TASKRC'}; - -# Create the rc file. -if (open my $fh, '>', 'color.rc') -{ - print $fh "data.location=.\n", - "color.active=red\n", - "_forcecolor=1\n"; - close $fh; -} - -# Test the add command. -qx{../src/task rc:color.rc add nothing 2>&1}; -qx{../src/task rc:color.rc add red 2>&1}; -qx{../src/task rc:color.rc 2 start 2>&1}; -my $output = qx{../src/task rc:color.rc list 2>&1}; - -like ($output, qr/ (?!<\033\[\d\dm) .* nothing .* (?!>\033\[0m) /x, 'none'); -like ($output, qr/ \033\[31m .* red .* \033\[0m /x, 'color.active'); - -# Cleanup. -unlink qw(pending.data completed.data undo.data backlog.data color.rc); -exit 0; - diff --git a/test/color.blocked.t b/test/color.blocked.t deleted file mode 100755 index 6d32c845d..000000000 --- a/test/color.blocked.t +++ /dev/null @@ -1,58 +0,0 @@ -#! /usr/bin/env perl -################################################################################ -## -## Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez. -## -## Permission is hereby granted, free of charge, to any person obtaining a copy -## of this software and associated documentation files (the "Software"), to deal -## in the Software without restriction, including without limitation the rights -## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -## copies of the Software, and to permit persons to whom the Software is -## furnished to do so, subject to the following conditions: -## -## The above copyright notice and this permission notice shall be included -## in all copies or substantial portions of the Software. -## -## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -## OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -## SOFTWARE. -## -## http://www.opensource.org/licenses/mit-license.php -## -################################################################################ - -use strict; -use warnings; -use Test::More tests => 2; - -# Ensure environment has no influence. -delete $ENV{'TASKDATA'}; -delete $ENV{'TASKRC'}; - -# Create the rc file. -if (open my $fh, '>', 'color.rc') -{ - print $fh "data.location=.\n", - "color.blocked=red\n", - "color.alternate=\n", - "_forcecolor=1\n"; - close $fh; -} - -# Test the add command. -qx{../src/task rc:color.rc add red 2>&1}; -qx{../src/task rc:color.rc add nothing 2>&1}; -qx{../src/task rc:color.rc 1 modify depends:2 2>&1}; -my $output = qx{../src/task rc:color.rc list 2>&1}; - -like ($output, qr/ (?!<\033\[\d\dm) .* nothing .* (?!>\033\[0m) /x, 'none'); -like ($output, qr/ \033\[31m .* red .* \033\[0m /x, 'color.blocked'); - -# Cleanup. -unlink qw(pending.data completed.data undo.data backlog.data color.rc); -exit 0; - diff --git a/test/color.disable.t b/test/color.disable.t deleted file mode 100755 index ca6d3dd4c..000000000 --- a/test/color.disable.t +++ /dev/null @@ -1,62 +0,0 @@ -#! /usr/bin/env perl -################################################################################ -## -## Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez. -## -## Permission is hereby granted, free of charge, to any person obtaining a copy -## of this software and associated documentation files (the "Software"), to deal -## in the Software without restriction, including without limitation the rights -## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -## copies of the Software, and to permit persons to whom the Software is -## furnished to do so, subject to the following conditions: -## -## The above copyright notice and this permission notice shall be included -## in all copies or substantial portions of the Software. -## -## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -## OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -## SOFTWARE. -## -## http://www.opensource.org/licenses/mit-license.php -## -################################################################################ - -use strict; -use warnings; -use Test::More tests => 3; - -# Ensure environment has no influence. -delete $ENV{'TASKDATA'}; -delete $ENV{'TASKRC'}; - -use File::Basename; -my $ut = basename ($0); -my $rc = $ut . '.rc'; - -# Create the rc file. -if (open my $fh, '>', $rc) -{ - print $fh "data.location=.\n", - "color.pri.H=red\n", - "color.label=\n", - "color.label.sort=\n", - "fontunderline=no\n"; - close $fh; -} - -# Test the add command. -qx{../src/task rc:$rc add priority:H red 2>&1}; -my $output = qx{../src/task rc:$rc list 2>&1}; - -like ($output, qr/red/, "$ut: color.disable - found red"); -unlike ($output, qr/\033\[31m/, "$ut: color.disable - no color red"); -unlike ($output, qr/\033\[0m/, "$ut: color.disable - no color reset"); - -# Cleanup. -unlink qw(pending.data completed.data undo.data backlog.data), $rc; -exit 0; - diff --git a/test/color.due.t b/test/color.due.t deleted file mode 100755 index e22259a7a..000000000 --- a/test/color.due.t +++ /dev/null @@ -1,57 +0,0 @@ -#! /usr/bin/env perl -################################################################################ -## -## Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez. -## -## Permission is hereby granted, free of charge, to any person obtaining a copy -## of this software and associated documentation files (the "Software"), to deal -## in the Software without restriction, including without limitation the rights -## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -## copies of the Software, and to permit persons to whom the Software is -## furnished to do so, subject to the following conditions: -## -## The above copyright notice and this permission notice shall be included -## in all copies or substantial portions of the Software. -## -## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -## OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -## SOFTWARE. -## -## http://www.opensource.org/licenses/mit-license.php -## -################################################################################ - -use strict; -use warnings; -use Test::More tests => 2; - -# Ensure environment has no influence. -delete $ENV{'TASKDATA'}; -delete $ENV{'TASKRC'}; - -# Create the rc file. -if (open my $fh, '>', 'color.rc') -{ - print $fh "data.location=.\n", - "color.due=red\n", - "_forcecolor=1\n", - "dateformat=m/d/Y\n"; - close $fh; -} - -# Test the add command. -qx{../src/task rc:color.rc add due:someday nothing 2>&1}; -qx{../src/task rc:color.rc add due:tomorrow red 2>&1}; -my $output = qx{../src/task rc:color.rc list 2>&1}; - -like ($output, qr/ (?!<\033\[\d\dm) \d{1,2}\/\d{1,2}\/\d{4} (?!>\033\[0m) .* nothing /x, 'none'); -like ($output, qr/ \033\[31m .* red .* \033\[0m/x, 'color.due'); - -# Cleanup. -unlink qw(pending.data completed.data undo.data backlog.data color.rc); -exit 0; - diff --git a/test/color.err.t b/test/color.err.t deleted file mode 100755 index 22f14b7dc..000000000 --- a/test/color.err.t +++ /dev/null @@ -1,62 +0,0 @@ -#! /usr/bin/env perl -################################################################################ -## -## Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez. -## -## Permission is hereby granted, free of charge, to any person obtaining a copy -## of this software and associated documentation files (the "Software"), to deal -## in the Software without restriction, including without limitation the rights -## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -## copies of the Software, and to permit persons to whom the Software is -## furnished to do so, subject to the following conditions: -## -## The above copyright notice and this permission notice shall be included -## in all copies or substantial portions of the Software. -## -## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -## OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -## SOFTWARE. -## -## http://www.opensource.org/licenses/mit-license.php -## -################################################################################ - -use strict; -use warnings; -use Test::More tests => 4; - -use File::Basename; -my $ut = basename ($0); -my $rc = $ut . '.rc'; - -# Ensure environment has no influence. -delete $ENV{'TASKDATA'}; -delete $ENV{'TASKRC'}; - -# Create the rc file. -if (open my $fh, '>', $rc) -{ - print $fh "data.location=.\n", - "color.header=blue\n", - "color.footnote=red\n", - "color.error=yellow\n", - "color.debug=green\n", - "_forcecolor=1\n"; - close $fh; -} - -# Test the errors colors -my $output = qx{../src/task rc:$rc rc.debug:on add foo priority:X 2>&1 >/dev/null}; -like ($output, qr/^\033\[33mThe 'priority' attribute does not allow a value of 'X'\./ms, "$ut: color.error"); -like ($output, qr/^\033\[32mTimer Config::load \(.*?$rc\)/ms, "$ut: color.debug"); -like ($output, qr/^\033\[34mUsing alternate \.taskrc file/ms, "$ut: color.header"); -like ($output, qr/^\033\[31mConfiguration override rc\.debug:on/ms, "$ut: color.footnote"); - -# Cleanup. -unlink qw(pending.data completed.data undo.data backlog.data), $rc; -exit 0; - diff --git a/test/color.keyword.t b/test/color.keyword.t deleted file mode 100755 index 17c15511b..000000000 --- a/test/color.keyword.t +++ /dev/null @@ -1,66 +0,0 @@ -#! /usr/bin/env perl -################################################################################ -## -## Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez. -## -## Permission is hereby granted, free of charge, to any person obtaining a copy -## of this software and associated documentation files (the "Software"), to deal -## in the Software without restriction, including without limitation the rights -## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -## copies of the Software, and to permit persons to whom the Software is -## furnished to do so, subject to the following conditions: -## -## The above copyright notice and this permission notice shall be included -## in all copies or substantial portions of the Software. -## -## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -## OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -## SOFTWARE. -## -## http://www.opensource.org/licenses/mit-license.php -## -################################################################################ - -use strict; -use warnings; -use Test::More tests => 4; - -# Ensure environment has no influence. -delete $ENV{'TASKDATA'}; -delete $ENV{'TASKRC'}; - -# Create the rc file. -if (open my $fh, '>', 'color.rc') -{ - print $fh "data.location=.\n", - "search.case.sensitive=yes\n", - "color=on\n", - "color.alternate=\n", - "color.keyword.red=red\n", - "color.keyword.green=green\n", - "color.keyword.yellow=yellow\n", - "_forcecolor=1\n"; - close $fh; -} - -# Test the add command. -qx{../src/task rc:color.rc add nothing 2>&1}; -qx{../src/task rc:color.rc add red 2>&1}; -qx{../src/task rc:color.rc add green 2>&1}; -qx{../src/task rc:color.rc add -- annotation 2>&1}; -qx{../src/task rc:color.rc 4 annotate yellow 2>&1}; -my $output = qx{../src/task rc:color.rc list 2>&1}; - -like ($output, qr/ (?!<\033\[\d\dm) .* nothing .* (?!>\033\[0m) /x, 'none'); -like ($output, qr/ \033\[31m .* red .* \033\[0m /x, 'color.keyword.red'); -like ($output, qr/ \033\[32m .* green .* \033\[0m /x, 'color.keyword.green'); -like ($output, qr/ \033\[33m .* annotation .* \033\[0m /x, 'color.keyword.yellow (annotation)'); - -# Cleanup. -unlink qw(pending.data completed.data undo.data backlog.data color.rc); -exit 0; - diff --git a/test/color.overdue.t b/test/color.overdue.t deleted file mode 100755 index a88233f14..000000000 --- a/test/color.overdue.t +++ /dev/null @@ -1,57 +0,0 @@ -#! /usr/bin/env perl -################################################################################ -## -## Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez. -## -## Permission is hereby granted, free of charge, to any person obtaining a copy -## of this software and associated documentation files (the "Software"), to deal -## in the Software without restriction, including without limitation the rights -## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -## copies of the Software, and to permit persons to whom the Software is -## furnished to do so, subject to the following conditions: -## -## The above copyright notice and this permission notice shall be included -## in all copies or substantial portions of the Software. -## -## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -## OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -## SOFTWARE. -## -## http://www.opensource.org/licenses/mit-license.php -## -################################################################################ - -use strict; -use warnings; -use Test::More tests => 2; - -# Ensure environment has no influence. -delete $ENV{'TASKDATA'}; -delete $ENV{'TASKRC'}; - -# Create the rc file. -if (open my $fh, '>', 'color.rc') -{ - print $fh "data.location=.\n", - "color.overdue=red\n", - "_forcecolor=1\n", - "dateformat=m/d/Y\n"; - close $fh; -} - -# Test the add command. -qx{../src/task rc:color.rc add due:tomorrow nothing 2>&1}; -qx{../src/task rc:color.rc add due:yesterday red 2>&1}; -my $output = qx{../src/task rc:color.rc list 2>&1}; - -like ($output, qr/ (?!<\033\[\d\dm) \d{1,2}\/\d{1,2}\/\d{4} (?!>\033\[0m) .* nothing /x, 'none'); -like ($output, qr/ \033\[31m .* red .* \033\[0m/x, 'color.overdue'); - -# Cleanup. -unlink qw(pending.data completed.data undo.data backlog.data color.rc); -exit 0; - diff --git a/test/color.pri.t b/test/color.pri.t deleted file mode 100755 index a6071f303..000000000 --- a/test/color.pri.t +++ /dev/null @@ -1,64 +0,0 @@ -#! /usr/bin/env perl -################################################################################ -## -## Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez. -## -## Permission is hereby granted, free of charge, to any person obtaining a copy -## of this software and associated documentation files (the "Software"), to deal -## in the Software without restriction, including without limitation the rights -## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -## copies of the Software, and to permit persons to whom the Software is -## furnished to do so, subject to the following conditions: -## -## The above copyright notice and this permission notice shall be included -## in all copies or substantial portions of the Software. -## -## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -## OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -## SOFTWARE. -## -## http://www.opensource.org/licenses/mit-license.php -## -################################################################################ - -use strict; -use warnings; -use Test::More tests => 4; - -# Ensure environment has no influence. -delete $ENV{'TASKDATA'}; -delete $ENV{'TASKRC'}; - -# Create the rc file. -if (open my $fh, '>', 'color.rc') -{ - print $fh "data.location=.\n", - "color.pri.H=red\n", - "color.pri.M=green\n", - "color.pri.L=blue\n", - "color.pri.none=yellow\n", - "color.alternate=\n", - "_forcecolor=1\n"; - close $fh; -} - -# Test the add command. -qx{../src/task rc:color.rc add priority:H red 2>&1}; -qx{../src/task rc:color.rc add priority:M green 2>&1}; -qx{../src/task rc:color.rc add priority:L blue 2>&1}; -qx{../src/task rc:color.rc add yellow 2>&1}; -my $output = qx{../src/task rc:color.rc list 2>&1}; - -like ($output, qr/ \033\[31m .* red .* \033\[0m /x, 'color.pri.H'); -like ($output, qr/ \033\[32m .* green .* \033\[0m /x, 'color.pri.M'); -like ($output, qr/ \033\[34m .* blue .* \033\[0m /x, 'color.pri.L'); -like ($output, qr/ \033\[33m .* yellow .* \033\[0m /x, 'color.pri.none'); - -# Cleanup. -unlink qw(pending.data completed.data undo.data backlog.data color.rc); -exit 0; - diff --git a/test/color.project.t b/test/color.project.t deleted file mode 100755 index 3f80d6873..000000000 --- a/test/color.project.t +++ /dev/null @@ -1,58 +0,0 @@ -#! /usr/bin/env perl -################################################################################ -## -## Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez. -## -## Permission is hereby granted, free of charge, to any person obtaining a copy -## of this software and associated documentation files (the "Software"), to deal -## in the Software without restriction, including without limitation the rights -## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -## copies of the Software, and to permit persons to whom the Software is -## furnished to do so, subject to the following conditions: -## -## The above copyright notice and this permission notice shall be included -## in all copies or substantial portions of the Software. -## -## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -## OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -## SOFTWARE. -## -## http://www.opensource.org/licenses/mit-license.php -## -################################################################################ - -use strict; -use warnings; -use Test::More tests => 2; - -# Ensure environment has no influence. -delete $ENV{'TASKDATA'}; -delete $ENV{'TASKRC'}; - -# Create the rc file. -if (open my $fh, '>', 'color.rc') -{ - print $fh "data.location=.\n", - "color.project.x=red\n", - "color.project.none=green\n", - "color.alternate=\n", - "_forcecolor=1\n"; - close $fh; -} - -# Test the add command. -qx{../src/task rc:color.rc add nothing 2>&1}; -qx{../src/task rc:color.rc add project:x red 2>&1}; -my $output = qx{../src/task rc:color.rc list 2>&1}; - -like ($output, qr/ \033\[32m .* nothing .* \033\[0m /x, 'color.project.none'); -like ($output, qr/ \033\[31m .* red .* \033\[0m /x, 'color.project.red'); - -# Cleanup. -unlink qw(pending.data completed.data undo.data backlog.data color.rc); -exit 0; - diff --git a/test/color.recurring.t b/test/color.recurring.t deleted file mode 100755 index 9a4cda1b4..000000000 --- a/test/color.recurring.t +++ /dev/null @@ -1,57 +0,0 @@ -#! /usr/bin/env perl -################################################################################ -## -## Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez. -## -## Permission is hereby granted, free of charge, to any person obtaining a copy -## of this software and associated documentation files (the "Software"), to deal -## in the Software without restriction, including without limitation the rights -## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -## copies of the Software, and to permit persons to whom the Software is -## furnished to do so, subject to the following conditions: -## -## The above copyright notice and this permission notice shall be included -## in all copies or substantial portions of the Software. -## -## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -## OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -## SOFTWARE. -## -## http://www.opensource.org/licenses/mit-license.php -## -################################################################################ - -use strict; -use warnings; -use Test::More tests => 2; - -# Ensure environment has no influence. -delete $ENV{'TASKDATA'}; -delete $ENV{'TASKRC'}; - -# Create the rc file. -if (open my $fh, '>', 'color.rc') -{ - print $fh "data.location=.\n", - "color.recurring=red\n", - "color.due=\n", - "_forcecolor=1\n"; - close $fh; -} - -# Test the add command. -qx{../src/task rc:color.rc add nothing 2>&1}; -qx{../src/task rc:color.rc add due:tomorrow recur:1w red 2>&1}; -my $output = qx{../src/task rc:color.rc list 2>&1}; - -like ($output, qr/ (?!<\033\[\d\dm) .* nothing .* (?!>\033\[0m) /x, 'none'); -like ($output, qr/ \033\[31m .* red .* \033\[0m /x, 'color.recurring'); - -# Cleanup. -unlink qw(pending.data completed.data undo.data backlog.data color.rc); -exit 0; - diff --git a/test/color.rules.t b/test/color.rules.t new file mode 100755 index 000000000..8e9f121fa --- /dev/null +++ b/test/color.rules.t @@ -0,0 +1,222 @@ +#!/usr/bin/env python2.7 +# -*- coding: utf-8 -*- +############################################################################### +# +# Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# +# http://www.opensource.org/licenses/mit-license.php +# +############################################################################### + +import sys +import os +import unittest +from datetime import datetime +# Ensure python finds the local simpletap module +sys.path.append(os.path.dirname(os.path.abspath(__file__))) + +from basetest import Task, TestCase + + +class TestColorRules(TestCase): + @classmethod + def setUpClass(cls): + """Executed once before any test in the class""" + cls.t = Task() + + # Controlling peripheral color. + cls.t.config('_forcecolor', 'on') + cls.t.config('fontunderline', 'off') # label underlining complicates the tests. + cls.t.config('color.alternate', '') # alternating color complicateѕ the tests. + cls.t.config('default.command', 'list') + cls.t.config('uda.xxx.type', 'numeric') + cls.t.config('uda.xxx.label', 'XXX') + + # Color rules. + cls.t.config('color.active', 'red') + cls.t.config('color.blocked', 'red') + cls.t.config('color.blocking', 'blue') + cls.t.config('color.due', 'red') + cls.t.config('color.overdue', 'blue') + cls.t.config('color.error', 'blue') + cls.t.config('color.header', 'blue') + cls.t.config('color.footnote', 'red') + cls.t.config('color.debug', 'green') + cls.t.config('color.project.x', 'red') + cls.t.config('color.pri.H', 'red') + cls.t.config('color.pri.M', 'blue') + cls.t.config('color.pri.L', 'green') + cls.t.config('color.keyword.keyword', 'red') + cls.t.config('color.tag.x', 'red') + cls.t.config('color.recurring', 'red') + cls.t.config('color.uda.xxx', 'red') + cls.t.config('color.uda.xxx.4', 'blue') + + cls.t(('add', 'control task')) # 1 + cls.t(('add', 'active task')) # 2 + cls.t(('2', 'start')) + cls.t(('add', 'blocked task')) # 3 + cls.t(('add', 'blocking task')) # 4 + cls.t(('3', 'modify', 'depends:4')) + cls.t(('add', 'tomorrow', 'due:tomorrow')) # 5 + cls.t(('add', 'yesterday', 'due:yesterday')) # 6 + cls.t(('add', 'someday', 'due:yesterday')) # 7 + cls.t(('add', 'project_x', 'project:x')) # 8 + cls.t(('add', 'pri_h', 'priority:H')) # 9 + cls.t(('add', 'pri_m', 'priority:M')) # 10 + cls.t(('add', 'pri_l', 'priority:L')) # 11 + cls.t(('add', 'keyword')) # 12 + cls.t(('add', 'tag_x', '+x')) # 13 + cls.t(('add', 'uda_xxx_1', 'xxx:1')) # 14 + cls.t(('add', 'uda_xxx_4', 'xxx:4')) # 15 + cls.t(('add', 'recurring', 'due:tomorrow', 'recur:1week')) # 16 # Keep this last + + def test_control(self): + """No color on control task.""" + code, out, err = self.t(('1', 'info')) + self.assertNotIn('\x1b[', out) + + def test_disable_in_pipe(self): + """No color in pipe unless forced.""" + code, out, err = self.t(('2', 'info', 'rc._forcecolor:off')) + self.assertNotIn('\x1b[', out) + + def test_active(self): + """Active color rule.""" + code, out, err = self.t(('/active/', 'info')) + self.assertIn('\x1b[31m', out) + + def test_blocked(self): + """Blocked color rule.""" + code, out, err = self.t(('/blocked/', 'info')) + self.assertIn('\x1b[31m', out) + + def test_blocking(self): + """Blocking color rule.""" + code, out, err = self.t(('/blocking/', 'info')) + self.assertIn('\x1b[34m', out) + + def test_due_yesterday(self): + """Overdue color rule.""" + code, out, err = self.t(('/yesterday/', 'info')) + self.assertIn('\x1b[34m', out) + + def test_due_tomorrow(self): + """Due tomorrow color rule.""" + code, out, err = self.t(('/tomorrow/', 'info')) + self.assertIn('\x1b[31m', out) + + def test_due_someday(self): + """Due someday color rule.""" + code, out, err = self.t(('/someday/', 'info')) + self.assertIn('\x1b[', out) + + def test_color_error(self): + """Error color.""" + code, out, err = self.t.runError(('add', 'error', 'priority:X')) + self.assertIn('\x1b[34m', err) + + def test_color_header(self): + """Header color.""" + code, out, err = self.t(('rc.verbose=header', '/control/')) + self.assertIn('\x1b[34m', err) + + def test_color_footnote(self): + """Footnote color.""" + code, out, err = self.t(('rc.verbose=footnote', '/control/')) + self.assertIn('\x1b[31mConfiguration override', err) + + def test_color_debug(self): + """Debug color.""" + code, out, err = self.t(('rc.debug=1', '/control/')) + self.assertIn('\x1b[32mTimer', err) + + def test_project_x(self): + """Project x color rule.""" + code, out, err = self.t(('/project_x/', 'info')) + self.assertIn('\x1b[31m', out) + + def test_project_none(self): + """Project none color rule.""" + code, out, err = self.t(('/control/', 'rc.color.project.none=red', 'info')) + self.assertIn('\x1b[31m', out) + + def test_priority_h(self): + """Priority H color rule.""" + code, out, err = self.t(('/pri_h/', 'info')) + self.assertIn('\x1b[31m', out) + + def test_priority_m(self): + """Priority M color rule.""" + code, out, err = self.t(('/pri_m/', 'info')) + self.assertIn('\x1b[34m', out) + + def test_priority_l(self): + """Priority L color rule.""" + code, out, err = self.t(('/pri_l/', 'info')) + self.assertIn('\x1b[32m', out) + + def test_priority_none(self): + """Priority none color rule.""" + code, out, err = self.t(('/control/', 'rc.color.pri.none=red', 'info')) + self.assertIn('\x1b[31m', out) + + def test_keyword(self): + """Keyword color rule.""" + code, out, err = self.t(('/keyword/', 'info')) + self.assertIn('\x1b[31m', out) + + def test_tag_x(self): + """Tag x color rule.""" + code, out, err = self.t(('/tag_x/', 'info')) + self.assertIn('\x1b[31m', out) + + def test_tag_none(self): + """Tag none color rule.""" + code, out, err = self.t(('/control/', 'rc.color.tag.none=red', 'info')) + self.assertIn('\x1b[31m', out) + + def test_tagged(self): + """Tagged color rule.""" + code, out, err = self.t(('/tag_x/', 'rc.color.tag.x=', 'rc.color.tagged=blue', 'info')) + self.assertIn('\x1b[34m', out) + + def test_recurring(self): + """Recurring color rule.""" + code, out, err = self.t(('/recurring/', 'info')) + self.assertIn('\x1b[31m', out) + + def test_uda(self): + """UDA color rule.""" + code, out, err = self.t(('/uda_xxx_1/', 'info')) + self.assertIn('\x1b[31m', out) + + def test_uda_value(self): + """UDA Value color rule.""" + code, out, err = self.t(('/uda_xxx_4/', 'rc.color.uda.xxx=', 'info')) + self.assertIn('\x1b[34m', out) + + +if __name__ == "__main__": + from simpletap import TAPTestRunner + unittest.main(testRunner=TAPTestRunner()) + +# vim: ai sts=4 et sw=4 diff --git a/test/color.tag.t b/test/color.tag.t deleted file mode 100755 index 8fe8b919f..000000000 --- a/test/color.tag.t +++ /dev/null @@ -1,62 +0,0 @@ -#! /usr/bin/env perl -################################################################################ -## -## Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez. -## -## Permission is hereby granted, free of charge, to any person obtaining a copy -## of this software and associated documentation files (the "Software"), to deal -## in the Software without restriction, including without limitation the rights -## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -## copies of the Software, and to permit persons to whom the Software is -## furnished to do so, subject to the following conditions: -## -## The above copyright notice and this permission notice shall be included -## in all copies or substantial portions of the Software. -## -## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -## OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -## SOFTWARE. -## -## http://www.opensource.org/licenses/mit-license.php -## -################################################################################ - -use strict; -use warnings; -use Test::More tests => 3; - -# Ensure environment has no influence. -delete $ENV{'TASKDATA'}; -delete $ENV{'TASKRC'}; - -# Create the rc file. -if (open my $fh, '>', 'color.rc') -{ - print $fh "data.location=.\n", - "color.tagged=\n", - "color.alternate=\n", - "color.tag.none=yellow\n", - "color.tag.red=red\n", - "color.tag.green=green\n", - "_forcecolor=1\n"; - close $fh; -} - -# Test the add command. -qx{../src/task rc:color.rc add nothing 2>&1}; -qx{../src/task rc:color.rc add +red red 2>&1}; -qx{../src/task rc:color.rc add +green green 2>&1}; -my $output = qx{../src/task rc:color.rc list 2>&1}; - -like ($output, qr/ \033\[33m .* nothing .* \033\[0m /x, 'color.tag.none'); -like ($output, qr/ \033\[31m .* red .* \033\[0m /x, 'color.tag.red'); -like ($output, qr/ \033\[32m .* green .* \033\[0m /x, 'color.tag.green'); - -# Cleanup. -unlink qw(pending.data completed.data undo.data backlog.data color.rc); -exit 0; - diff --git a/test/color.tagged.t b/test/color.tagged.t deleted file mode 100755 index a96827af0..000000000 --- a/test/color.tagged.t +++ /dev/null @@ -1,60 +0,0 @@ -#! /usr/bin/env perl -################################################################################ -## -## Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez. -## -## Permission is hereby granted, free of charge, to any person obtaining a copy -## of this software and associated documentation files (the "Software"), to deal -## in the Software without restriction, including without limitation the rights -## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -## copies of the Software, and to permit persons to whom the Software is -## furnished to do so, subject to the following conditions: -## -## The above copyright notice and this permission notice shall be included -## in all copies or substantial portions of the Software. -## -## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -## OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -## SOFTWARE. -## -## http://www.opensource.org/licenses/mit-license.php -## -################################################################################ - -use strict; -use warnings; -use Test::More tests => 3; - -# Ensure environment has no influence. -delete $ENV{'TASKDATA'}; -delete $ENV{'TASKRC'}; - -unlink 'pending.data'; -ok (!-r 'pending.data', 'Removed pending.data'); - -# Create the rc file. -if (open my $fh, '>', 'color.rc') -{ - print $fh "data.location=.\n", - "color.tagged=red\n", - "color.alternate=\n", - "_forcecolor=1\n"; - close $fh; -} - -# Test the add command. -qx{../src/task rc:color.rc add nothing 2>&1}; -qx{../src/task rc:color.rc add +tag red 2>&1}; -my $output = qx{../src/task rc:color.rc list 2>&1}; - -like ($output, qr/ (?!<\033\[\d\dm) .* nothing .* (?!>\033\[0m) /x, 'none'); -like ($output, qr/ \033\[31m .* red .* \033\[0m /x, 'color.tagged'); - -# Cleanup. -unlink qw(pending.data completed.data undo.data backlog.data color.rc); -exit 0; - diff --git a/test/color.uda.t b/test/color.uda.t deleted file mode 100755 index cad6f1194..000000000 --- a/test/color.uda.t +++ /dev/null @@ -1,63 +0,0 @@ -#! /usr/bin/env perl -################################################################################ -## -## Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez. -## -## Permission is hereby granted, free of charge, to any person obtaining a copy -## of this software and associated documentation files (the "Software"), to deal -## in the Software without restriction, including without limitation the rights -## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -## copies of the Software, and to permit persons to whom the Software is -## furnished to do so, subject to the following conditions: -## -## The above copyright notice and this permission notice shall be included -## in all copies or substantial portions of the Software. -## -## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -## OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -## SOFTWARE. -## -## http://www.opensource.org/licenses/mit-license.php -## -################################################################################ - -use strict; -use warnings; -use Test::More tests => 3; - -# Ensure environment has no influence. -delete $ENV{'TASKDATA'}; -delete $ENV{'TASKRC'}; - -# Create the rc file. -if (open my $fh, '>', 'color.rc') -{ - print $fh "data.location=.\n", - "color.uda.x=red\n", - "uda.x.type=numeric\n", - "uda.x.label=X\n", - "uda.y.type=numeric\n", - "uda.y.label=Y\n", - "color.uda.y.4=blue\n", - "color.alternate=\n", - "_forcecolor=1\n"; - close $fh; -} - -qx{../src/task rc:color.rc add one 2>&1}; -qx{../src/task rc:color.rc add two x:3 y:2 2>&1}; -qx{../src/task rc:color.rc add three y:4 2>&1}; -my $output = qx{../src/task rc:color.rc list 2>/dev/null}; - -unlike ($output, qr/ \033\[32m .* one .* \033\[0m /x, 'No color.uda'); -like ($output, qr/ \033\[31m .* two .* \033\[0m /x, 'Found color.uda'); -like ($output, qr/ \033\[34m .* three .* \033\[0m /x, 'Found color.uda.x'); - -# Cleanup. -unlink qw(pending.data completed.data undo.data backlog.data color.rc); -exit 0; - From 9f654a5c950f61081133f97ad17cf69824e6b7e0 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 7 Mar 2015 16:06:18 -0500 Subject: [PATCH 18/20] Unit Tests - Test was wrong. --- test/project.t | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/project.t b/test/project.t index a4e89dc1b..d7f4b53fa 100755 --- a/test/project.t +++ b/test/project.t @@ -113,10 +113,9 @@ class TestProjects(TestCase): code, out, err = self.t(("projects",)) order = ( - # NOTE all but abstractParent have 1 task hence the trailing space ".myProject ", ".myProject. ", - "abstractParent\n", + "abstractParent ", " kid ", "existingParent ", " child ", From 19674ee33954cf358146b5ef99c705cea928cacd Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 7 Mar 2015 16:11:38 -0500 Subject: [PATCH 19/20] Unit Tests - Specifically set certain color rules to '' to override default theme. --- test/color.rules.t | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/color.rules.t b/test/color.rules.t index 8e9f121fa..f47cdf33f 100755 --- a/test/color.rules.t +++ b/test/color.rules.t @@ -61,10 +61,14 @@ class TestColorRules(TestCase): cls.t.config('color.footnote', 'red') cls.t.config('color.debug', 'green') cls.t.config('color.project.x', 'red') + cls.t.config('color.project.none', '') cls.t.config('color.pri.H', 'red') cls.t.config('color.pri.M', 'blue') cls.t.config('color.pri.L', 'green') + cls.t.config('color.pri.none', '') cls.t.config('color.keyword.keyword', 'red') + cls.t.config('color.tagged', '') + cls.t.config('color.tag.none', '') cls.t.config('color.tag.x', 'red') cls.t.config('color.recurring', 'red') cls.t.config('color.uda.xxx', 'red') From 87d00698db850ce72b76c48eb2dabbab2e9bfe6c Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 7 Mar 2015 16:18:44 -0500 Subject: [PATCH 20/20] Unit Tests - Successful hook tests now query the task to make sure processing continued. Could be better. --- test/hooks.on-add.t | 3 +++ test/hooks.on-modify.t | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/test/hooks.on-add.t b/test/hooks.on-add.t index 508548b37..f0cef1656 100755 --- a/test/hooks.on-add.t +++ b/test/hooks.on-add.t @@ -56,6 +56,9 @@ class TestHooksOnAdd(TestCase): logs = hook.get_logs() self.assertEqual(logs["output"]["msgs"][0], "FEEDBACK") + code, out, err = self.t(("1", "info")) + self.assertIn("Description foo", out) + def test_onadd_builtin_reject(self): """on-add-reject - a well-behaved, failing, on-add hook.""" hookname = 'on-add-reject' diff --git a/test/hooks.on-modify.t b/test/hooks.on-modify.t index f8087565e..de6f5f77f 100755 --- a/test/hooks.on-modify.t +++ b/test/hooks.on-modify.t @@ -57,6 +57,10 @@ class TestHooksOnModify(TestCase): logs = hook.get_logs() self.assertEqual(logs["output"]["msgs"][0], "FEEDBACK") + code, out, err = self.t(("1", "info")) + self.assertIn("Description foo", out) + self.assertIn("Tags tag", out) + def test_onmodify_builtin_reject(self): """on-modify-reject - a well-behaved, failing, on-modify hook.""" hookname = 'on-modify-reject'