From 157699cbdeb3e98c50552deaafbdc1810ad15e98 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Tue, 7 May 2013 16:20:47 -0400 Subject: [PATCH] Feature #1256 Follow-up - Extended unit tests to cover 'add' failures. - Removed whitespace at EOL. - Updated ChangeLog, AUTHORS, NEWS. - Updated taskrc.5.in. - Updated CmdShow to allow new config settings. --- AUTHORS | 1 + ChangeLog | 1 + NEWS | 1 + doc/man/taskrc.5.in | 7 +++++++ src/Task.cpp | 25 +++++++++++++------------ src/commands/CmdShow.cpp | 1 + src/commands/CmdUDAs.cpp | 2 +- test/uda_defaults.t | 13 ++++++++----- 8 files changed, 33 insertions(+), 18 deletions(-) diff --git a/AUTHORS b/AUTHORS index aed2af047..dd2df9f33 100644 --- a/AUTHORS +++ b/AUTHORS @@ -86,6 +86,7 @@ The following submitted code, packages or analysis, and deserve special thanks: Russell Steicke YBSAR Tullio Facchinetti + Thomas Sullivan Thanks to the following, who submitted detailed bug reports and excellent suggestions: diff --git a/ChangeLog b/ChangeLog index cd7bc2f5e..087eaec08 100644 --- a/ChangeLog +++ b/ChangeLog @@ -11,6 +11,7 @@ Features + #1227 A new 'verify_l10n' utility ensures the localizations are in sync (thanks to Wim Schuermann). + #1250 Support out-of-tree test runs (thanks to Jakub Wilk). + + #1256 Supports default values for UDA fields (thanks to Thomas Sullivan). + Stores un-synched transactions in /backlog.data. + Adds a new 'synchronize' command to sync data with a task server. + Adds a new 'sync' verbosity token, which will reminds when a backlog builds diff --git a/NEWS b/NEWS index 541ab214e..4e0cce091 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,7 @@ New Features in taskwarrior 2.3.0 - New shell with Readline support. - The 'dateformat' settings now default to the ISO-8601 standard of 'Y-M-D'. - Italian translation. + - UDA fields now allow default values. New commands in taskwarrior 2.3.0 diff --git a/doc/man/taskrc.5.in b/doc/man/taskrc.5.in index d4c7723d1..e6e2c2fb6 100644 --- a/doc/man/taskrc.5.in +++ b/doc/man/taskrc.5.in @@ -1139,6 +1139,13 @@ Provides a default due date for the .I task add command, if you don't specify one. The default is blank. +.TP +.B +uda..default=... +Provides default values for UDA fields when using the +.I task add +command, if you don't specify values. The default is blank. + .TP .B default.command=next diff --git a/src/Task.cpp b/src/Task.cpp index 917ad1a59..4563947a1 100644 --- a/src/Task.cpp +++ b/src/Task.cpp @@ -1260,14 +1260,15 @@ void Task::validate (bool applyDefault /* = true */) context.columns["due"]->validate (defaultDue)) set ("due", Date (defaultDue).toEpoch ()); } - - // If a UDA has a default value in the configuration, - // override with uda.(uda).default, if not specified + + // If a UDA has a default value in the configuration, + // override with uda.(uda).default, if not specified. if (applyDefault) - { // Gather a list of all UDAs with a .default value + { + // Gather a list of all UDAs with a .default value std::vector names; context.config.all (names); - + std::vector udas; std::vector ::iterator name; for (name = names.begin (); name != names.end (); ++name) @@ -1280,9 +1281,10 @@ void Task::validate (bool applyDefault /* = true */) udas.push_back (name->substr (4, period - 4)); } } - + if (udas.size ()) - { // For each of those, setup the default value on the task now, + { + // For each of those, setup the default value on the task now, // of course only if we don't have one on the command line already std::vector ::iterator uda; for (uda = udas.begin (); uda != udas.end (); ++uda) @@ -1291,12 +1293,11 @@ void Task::validate (bool applyDefault /* = true */) std::string defVal = context.config.get ("uda." + *uda + ".default"); // If the default is empty, and we already have a value, skip it - if (defVal != "" && get (*uda) == "") - set(*uda,defVal); + if (defVal != "" && get (*uda) == "") + set (*uda, defVal); } } - } - + } // 2) To provide suitable warnings about odd states @@ -1457,7 +1458,7 @@ float Task::urgency_c () const value += fabsf (urgencyBlockingCoefficient) > epsilon ? (urgency_blocking () * urgencyBlockingCoefficient) : 0.0; value += fabsf (urgencyAgeCoefficient) > epsilon ? (urgency_age () * urgencyAgeCoefficient) : 0.0; -/* +/* // Very useful for debugging urgency problems. std::cout << "# Urgency for " << get ("uuid") << ":\n" << "# pri " << (urgency_priority () * urgencyPriorityCoefficient) << "\n" diff --git a/src/commands/CmdShow.cpp b/src/commands/CmdShow.cpp index c757a8c84..04c3187c8 100644 --- a/src/commands/CmdShow.cpp +++ b/src/commands/CmdShow.cpp @@ -238,6 +238,7 @@ int CmdShow::execute (std::string& output) i->substr (0, 5) != "pull." && i->substr (0, 6) != "merge." && i->substr (0, 4) != "uda." && + i->substr (0, 4) != "default." && i->substr (0, 21) != "urgency.user.project." && i->substr (0, 17) != "urgency.user.tag." && i->substr (0, 12) != "urgency.uda.") diff --git a/src/commands/CmdUDAs.cpp b/src/commands/CmdUDAs.cpp index 9d8fbb291..64fd10bef 100644 --- a/src/commands/CmdUDAs.cpp +++ b/src/commands/CmdUDAs.cpp @@ -85,7 +85,7 @@ int CmdUDAs::execute (std::string& output) view.add (Column::factory ("string", STRING_COLUMN_LABEL_TYPE)); view.add (Column::factory ("string", STRING_COLUMN_LABEL_LABEL)); view.add (Column::factory ("string", STRING_COLUMN_LABEL_VALUES)); - view.add (Column::factory ("string", STRING_COLUMN_LABEL_DEFAULT)); + view.add (Column::factory ("string", STRING_COLUMN_LABEL_DEFAULT)); view.add (Column::factory ("string", STRING_COLUMN_LABEL_UDACOUNT)); std::vector ::iterator uda; diff --git a/test/uda_defaults.t b/test/uda_defaults.t index ebf378d61..95c1ec499 100755 --- a/test/uda_defaults.t +++ b/test/uda_defaults.t @@ -28,7 +28,7 @@ use strict; use warnings; -use Test::More tests => 5; +use Test::More tests => 8; # Create the rc file. if (open my $fh, '>', 'uda.rc') @@ -50,15 +50,18 @@ if (open my $fh, '>', 'uda.rc') } # Add task with nondefault UDA -qx{../src/task rc:uda.rc add one smell:strong 2>&1}; +my $output = qx{../src/task rc:uda.rc add one smell:strong 2>&1}; +like ($output, qr/Created task 1/, 'Add 1 - no errors'); # Add task without a UDA value, checking for usage of the default -qx{../src/task rc:uda.rc add two 2>&1}; +$output = qx{../src/task rc:uda.rc add two 2>&1}; +like ($output, qr/Created task 2/, 'Add 2 - no errors'); # Add a task with a UDA that has no default, ensure it is entered fine -qx{../src/task rc:uda.rc add three size:10 2>&1}; +$output = qx{../src/task rc:uda.rc add three size:10 2>&1}; +like ($output, qr/Created task 3/, 'Add 3 - no errors'); -my $output = qx{../src/task rc:uda.rc uda 2>&1}; +$output = qx{../src/task rc:uda.rc uda 2>&1}; like ($output, qr/1\s+strong\s+one/, 'UDA nondefault stored'); like ($output, qr/2\s+weak\s+two/, 'UDA default stored'); like ($output, qr/3\s+weak\s+10\s+three/, 'UDA without default stored');