From 383962173eda59eff9c0cd1e13ce4104843b2c81 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 24 Jan 2010 17:35:37 -0500 Subject: [PATCH] Bug Fix - #360 Huh? "You cannot remove the recurrence from a recurring task. " - The logic for detecting changes to a recurring task was wrong. - Added unit tests for this bug. --- ChangeLog | 2 ++ src/command.cpp | 11 +++---- src/tests/bug.360.t | 70 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 5 deletions(-) create mode 100755 src/tests/bug.360.t diff --git a/ChangeLog b/ChangeLog index 303ee3a07..014939342 100644 --- a/ChangeLog +++ b/ChangeLog @@ -63,6 +63,8 @@ + Fixed bug that was causing the 'completed' report to sort incorrectly. + Fixed bug that showed a calendar for the year 2037 when 'task calendar due' was run, and there are no tasks with due dates. + + Fixed bug #360 which prevented certain modifications to recurring tasks + (thanks to John Flrorian). ------ old releases ------------------------------ diff --git a/src/command.cpp b/src/command.cpp index 4015de057..138390f00 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -1133,13 +1133,14 @@ int handleModify (std::string &outs) !task->has ("recur")) throw std::string ("You cannot specify an until date for a non-recurring task."); - if (task->has ("due") && - !context.task.has ("due") && - context.task.has ("recur")) + if (task->has ("due") && + context.task.has ("due") && + context.task.get ("due") == "") throw std::string ("You cannot remove the due date from a recurring task."); - if (task->has ("recur") && - !context.task.has ("recur")) + if (task->has ("recur") && + context.task.has ("recur") && + context.task.get ("recur") == "") throw std::string ("You cannot remove the recurrence from a recurring task."); // Make all changes. diff --git a/src/tests/bug.360.t b/src/tests/bug.360.t new file mode 100755 index 000000000..2bdfbfba1 --- /dev/null +++ b/src/tests/bug.360.t @@ -0,0 +1,70 @@ +#! /usr/bin/perl +################################################################################ +## task - a command line task list manager. +## +## Copyright 2006 - 2010, 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, '>', 'bug.rc') +{ + print $fh "data.location=.\n", + "confirmation=no\n"; + close $fh; + ok (-r 'bug.rc', 'Created bug.rc'); +} + +# Setup: Add a recurring task, generate an instance, then add a project. +qx{../task rc:bug.rc add foo due:tomorrow recur:daily}; +qx{../task rc:bug.rc ls}; + +# Result: trying to add the project generates an error about removing +# recurrence from a task. +my $output = qx{../task rc:bug.rc 2 project:bar}; +unlike ($output, qr/You cannot remove the recurrence from a recurring task./ms, 'No recurrence removal error'); + +# Now try to generate the error above via regular means - ie, is it actually +# doing what it should? +$output = qx{../task rc:bug.rc 2 recur:}; +like ($output, qr/You cannot remove the recurrence from a recurring task./ms, 'Recurrence removal error'); + +# 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 'bug.rc'; +ok (!-r 'bug.rc', 'Removed bug.rc'); + +exit 0; +