From ec7f7cc939161c7014b73f6e4a5596bcd980130c Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 16 Aug 2009 18:39:35 -0400 Subject: [PATCH] Bug Fix - #260 - Fixed bug whereby the start, stop and delete commands were not complaining when filter arguments were specified, even though they were ignored. Thanks to Charles T. Yun. --- ChangeLog | 3 ++ src/Context.cpp | 12 +++++++ src/Context.h | 1 + src/command.cpp | 8 +++++ src/tests/bug.start.extra.t | 62 +++++++++++++++++++++++++++++++++++++ 5 files changed, 86 insertions(+) create mode 100755 src/tests/bug.start.extra.t diff --git a/ChangeLog b/ChangeLog index c59594bc2..672346e96 100644 --- a/ChangeLog +++ b/ChangeLog @@ -24,6 +24,9 @@ automatic creation of an alternate rc file (thanks to Zach Frazier). + Fixed bug #250 whereby rc.dateformat was not observed when parsing the creation date of an annotation (thanks to Federico Hernandez). + + Fixed bug #260 whereby the start, stop and delete commands did not complain + when filter arguments were specified, even though they were ignored + (thanks to Charles T. Yun). ------ old releases ------------------------------ diff --git a/src/Context.cpp b/src/Context.cpp index abb22239c..a26b70c1a 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -316,6 +316,18 @@ std::string Context::canonicalize (const std::string& input) const return canonical; } +//////////////////////////////////////////////////////////////////////////////// +void Context::disallowModification () const +{ + if (task.size () || + subst.mFrom != "" || + tagAdditions.size () || + tagRemovals.size ()) + throw std::string ("The '") + + cmd.command + + "' command does not allow further modification of a task."; +} + //////////////////////////////////////////////////////////////////////////////// void Context::loadCorrectConfigFile () { diff --git a/src/Context.h b/src/Context.h index f59efcd40..391637798 100644 --- a/src/Context.h +++ b/src/Context.h @@ -65,6 +65,7 @@ public: void clear (); std::string canonicalize (const std::string&) const; + void disallowModification () const; private: void loadCorrectConfigFile (); diff --git a/src/command.cpp b/src/command.cpp index 26e551817..bda22854c 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -387,6 +387,8 @@ std::string handleCompletionIDs () //////////////////////////////////////////////////////////////////////////////// void handleUndo () { + context.disallowModification (); + context.tdb.lock (context.config.get ("locking", true)); context.tdb.undo (); context.tdb.unlock (); @@ -557,6 +559,8 @@ std::string handleDelete () { std::stringstream out; + context.disallowModification (); + std::vector tasks; context.tdb.lock (context.config.get ("locking", true)); Filter filter; @@ -656,6 +660,8 @@ std::string handleStart () { std::stringstream out; + context.disallowModification (); + std::vector tasks; context.tdb.lock (context.config.get ("locking", true)); Filter filter; @@ -707,6 +713,8 @@ std::string handleStop () { std::stringstream out; + context.disallowModification (); + std::vector tasks; context.tdb.lock (context.config.get ("locking", true)); Filter filter; diff --git a/src/tests/bug.start.extra.t b/src/tests/bug.start.extra.t new file mode 100755 index 000000000..87c6ca767 --- /dev/null +++ b/src/tests/bug.start.extra.t @@ -0,0 +1,62 @@ +#! /usr/bin/perl +################################################################################ +## task - a command line task list manager. +## +## Copyright 2006 - 2009, Paul Beckingham. +## All rights reserved. +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 2 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +## FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, write to the +## +## Free Software Foundation, Inc., +## 51 Franklin Street, Fifth Floor, +## Boston, MA +## 02110-1301 +## USA +## +################################################################################ + +use strict; +use warnings; +use Test::More tests => 7; + +# Create the rc file. +if (open my $fh, '>', 'extra.rc') +{ + print $fh "data.location=.\n", + "confirmation=no\n"; + close $fh; + ok (-r 'extra.rc', 'Created extra.rc'); +} + +qx{../task rc:extra.rc add foo}; +my $output = qx{../task rc:extra.rc 1 start pri:L}; +like ($output, qr/The 'start' command does not allow further modification of a task\./, 'no modifications allowed for start'); +$output = qx{../task rc:extra.rc 1 stop pro:bar}; +like ($output, qr/The 'stop' command does not allow further modification of a task\./, 'no modifications allowed for stop'); + +# Cleanup. +unlink 'pending.data'; +ok (!-r 'pending.data', 'Removed pending.data'); + +unlink 'completed.data'; +ok (!-r 'completed.data', 'Removed completed.data'); + +unlink 'undo.data'; +ok (!-r 'undo.data', 'Removed undo.data'); + +unlink 'extra.rc'; +ok (!-r 'extra.rc', 'Removed extra.rc'); + +exit 0; +