From 5f353f800d59f1530d3f3b390afda629fcea7617 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 6 Dec 2009 11:23:16 -0500 Subject: [PATCH] Unit Tests - cal.t - Fixed a broken fix (e7c8114dff0fc88317a0e590ce33ef1d2cd33b01) for the calendar command - previously if task could find no tasks with due dates, no calendar was displayed, and an error message shown. That broken fix was only on the 1.9.0 branch and never released. The correct behavior is to show a line of months. This bug broke 15 unit tests. - Fixed minor problem in unit tests where the output was not captured, although this has no bearing on the results. --- src/report.cpp | 17 ++++++----------- src/tests/cal.t | 12 ++++++------ 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/report.cpp b/src/report.cpp index f0df5b16d..3fe91d6bd 100644 --- a/src/report.cpp +++ b/src/report.cpp @@ -1489,19 +1489,19 @@ int handleReportCalendar (std::string &outs) int monthsToDisplay = 1; int mFrom = today.month (); int yFrom = today.year (); - int mTo; - int yTo; + int mTo = mFrom; + int yTo = yFrom; // Determine what to do int numberOfArgs = context.args.size(); - if (numberOfArgs == 1 ) { + if (numberOfArgs == 1) { // task cal monthsToDisplay = monthsPerLine; mFrom = today.month(); yFrom = today.year(); } - else if (numberOfArgs == 2 ) { + else if (numberOfArgs == 2) { if (context.args[1] == "y") { // task cal y monthsToDisplay = 12; @@ -1520,7 +1520,7 @@ int handleReportCalendar (std::string &outs) yFrom = atoi( context.args[1].data()); } } - else if (numberOfArgs == 3 ) { + else if (numberOfArgs == 3) { if (context.args[2] == "y") { // task cal due y monthsToDisplay = 12; @@ -1533,7 +1533,7 @@ int handleReportCalendar (std::string &outs) yFrom = atoi( context.args[2].data()); } } - else if (numberOfArgs == 4 ) { + else if (numberOfArgs == 4) { // task cal 8 2010 y monthsToDisplay = 12; mFrom = atoi( context.args[1].data()); @@ -1560,11 +1560,6 @@ int handleReportCalendar (std::string &outs) yFrom = oldest.year(); } - // If there are no tasks with due dates, then prevent showing a calendar from - // the year 2037. - if (countDueDates == 0) - throw std::string ("There are no tasks that have due dates."); - mTo = mFrom + monthsToDisplay - 1; yTo = yFrom; if (mTo > 12) { diff --git a/src/tests/cal.t b/src/tests/cal.t index 3b22cdd35..fe354543a 100755 --- a/src/tests/cal.t +++ b/src/tests/cal.t @@ -2,7 +2,7 @@ ################################################################################ ## task - a command line task list manager. ## -## Copyright 2006 - 2009, Paul Beckingham. +## Copyright 2006 - 2009, Paul Beckingham, Federico Hernandez. ## All rights reserved. ## ## Unit test cal.t originally writen by Federico Hernandez @@ -42,11 +42,11 @@ if (open my $fh, '>', 'cal.rc') close $fh; ok (-r 'cal.rc', 'Created cal.rc'); } - +my @months = qw(Jan Fev Mar Apr May Jun Jul Aug Sep Oct Nov Dec); my ($day, $nmon, $nyear) = (localtime)[3,4,5]; -my $nextmonth = ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")[($nmon+1) % 12]; -my $month = ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")[($nmon) % 12]; -my $prevmonth = ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")[($nmon-1) % 12]; +my $nextmonth = $months[($nmon+1) % 12]; +my $month = $months[($nmon) % 12]; +my $prevmonth = $months[($nmon-1) % 12]; my $nextyear = $nyear + 1901; my $year = $nyear + 1900; @@ -59,7 +59,7 @@ if ( $day <= 9) my $output = qx{../task rc:cal.rc rc._forcecolor:on cal}; like ($output, qr/\[36m$day/, 'Current day is highlighted'); like ($output, qr/$month\w+?\s+?$year/, 'Current month and year are displayed'); -qx{../task rc:cal.rc add zero}; +$output = qx{../task rc:cal.rc add zero}; unlike ($output, qr/\[41m\d+/, 'No overdue tasks are present'); unlike ($output, qr/\[43m\d+/, 'No due tasks are present'); $output = qx{../task rc:cal.rc rc.weekstart:Sunday cal};