From ce4f26bdf300e27bf7e2ae4d7b6b437a87f22949 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 28 Jun 2009 01:04:23 -0400 Subject: [PATCH] Unit Tests - Fixed a series of bugs to improve the test suite results. --- src/Sequence.cpp | 2 +- src/command.cpp | 5 +++-- src/import.cpp | 34 ++++++++++++++++++---------------- src/tests/args.t | 3 ++- src/tests/bug.concat.t | 3 ++- src/tests/import.csv.t | 6 ++++++ src/util.cpp | 1 - 7 files changed, 32 insertions(+), 22 deletions(-) diff --git a/src/Sequence.cpp b/src/Sequence.cpp index 9d6d457f6..44fc3f2ce 100644 --- a/src/Sequence.cpp +++ b/src/Sequence.cpp @@ -69,7 +69,7 @@ bool Sequence::valid (const std::string& input) const range.size () > 2) return false; - if (range.size () == 1 && !validId (range[0])) + if (range.size () <= 2 && !validId (range[0])) return false; if (range.size () == 2 && !validId (range[1])) diff --git a/src/command.cpp b/src/command.cpp index 109409fa7..2256c7112 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -856,9 +856,10 @@ std::string handleModify () { std::string question = taskDifferences (before, *other) + "Are you sure?"; if (changes && permission.confirmed (question)) + { context.tdb.update (*other); - - ++count; + ++count; + } } } } diff --git a/src/import.cpp b/src/import.cpp index 771062d63..215659d57 100644 --- a/src/import.cpp +++ b/src/import.cpp @@ -165,6 +165,8 @@ static void decorateTask (Task& task) sprintf (entryTime, "%u", (unsigned int) time (NULL)); task.set ("entry", entryTime); + task.setStatus (Task::pending); + // Override with default.project, if not specified. std::string defaultProject = context.config.get ("default.project", ""); if (!task.has ("project") && defaultProject != "") @@ -672,8 +674,8 @@ static std::string importTaskCmdLine (const std::vector & lines) try { - std::vector args; - split (args, std::string ("add ") + line, ' '); + context.args.clear (); + split (context.args, std::string ("add ") + line, ' '); context.task.clear (); context.cmd.command = ""; @@ -719,8 +721,8 @@ static std::string importTodoSh_2_0 (const std::vector & lines) { try { - std::vector args; - args.push_back ("add"); + context.args.clear (); + context.args.push_back ("add"); bool isPending = true; Date endDate; @@ -733,8 +735,8 @@ static std::string importTodoSh_2_0 (const std::vector & lines) if (words[w].length () > 1 && words[w][0] == '+') { - args.push_back (std::string ("project:") + - words[w].substr (1, std::string::npos)); + context.args.push_back (std::string ("project:") + + words[w].substr (1, std::string::npos)); } // Convert "+aaa" to "project:aaa". @@ -742,8 +744,8 @@ static std::string importTodoSh_2_0 (const std::vector & lines) else if (words[w].length () > 1 && words[w][0] == '@') { - args.push_back (std::string ("+") + - words[w].substr (1, std::string::npos)); + context.args.push_back (std::string ("+") + + words[w].substr (1, std::string::npos)); } // Convert "(A)" to "priority:H". @@ -753,9 +755,9 @@ static std::string importTodoSh_2_0 (const std::vector & lines) words[w][0] == '(' && words[w][2] == ')') { - if (words[w][1] == 'A') args.push_back ("priority:H"); - else if (words[w][1] == 'B') args.push_back ("priority:M"); - else args.push_back ("priority:L"); + if (words[w][1] == 'A') context.args.push_back ("priority:H"); + else if (words[w][1] == 'B') context.args.push_back ("priority:M"); + else context.args.push_back ("priority:L"); } // Set status, if completed. @@ -778,7 +780,7 @@ static std::string importTodoSh_2_0 (const std::vector & lines) // Just an ordinary word. else { - args.push_back (words[w]); + context.args.push_back (words[w]); } } @@ -855,8 +857,8 @@ static std::string importText (const std::vector & lines) try { ++count; - std::vector args; - split (args, std::string ("add ") + line, ' '); + context.args.clear (); + split (context.args, std::string ("add ") + line, ' '); context.task.clear (); context.cmd.command = ""; @@ -1057,6 +1059,7 @@ static std::string importCSV (const std::vector & lines) if ((f = mapping["uuid"]) != -1) task.set ("uuid", lowerCase (unquoteText (trim (fields[f])))); + task.setStatus (Task::pending); if ((f = mapping["status"]) != -1) { std::string value = lowerCase (unquoteText (trim (fields[f]))); @@ -1065,7 +1068,6 @@ static std::string importCSV (const std::vector & lines) else if (value == "deleted") task.setStatus (Task::deleted); else if (value == "completed") task.setStatus (Task::completed); else if (value == "waiting") task.setStatus (Task::waiting); - else task.setStatus (Task::pending); } if ((f = mapping["tags"]) != -1) @@ -1183,7 +1185,7 @@ std::string handleImport () case task_cmd_line: identifier = "This looks like task command line arguments."; break; case todo_sh_2_0: identifier = "This looks like a todo.sh 2.x file."; break; case csv: identifier = "This looks like a CSV file, but not a task export file."; break; - case text: identifier = "This looks like a text file with one tasks per line."; break; + case text: identifier = "This looks like a text file with one task per line."; break; case not_a_clue: throw std::string ("Task cannot determine which type of file this is, " "and cannot proceed."); diff --git a/src/tests/args.t b/src/tests/args.t index aa1fb8116..63ad3a1ff 100755 --- a/src/tests/args.t +++ b/src/tests/args.t @@ -33,7 +33,8 @@ use Test::More tests => 8; # Create the rc file. if (open my $fh, '>', 'args.rc') { - print $fh "data.location=.\n"; + print $fh "data.location=.\n", + "confirmation=no\n"; close $fh; ok (-r 'args.rc', 'Created args.rc'); } diff --git a/src/tests/bug.concat.t b/src/tests/bug.concat.t index 4a3fcd1f5..d711c0df7 100755 --- a/src/tests/bug.concat.t +++ b/src/tests/bug.concat.t @@ -33,7 +33,8 @@ use Test::More tests => 6; # Create the rc file. if (open my $fh, '>', 'bug_concat.rc') { - print $fh "data.location=.\n"; + print $fh "data.location=.\n", + "confirmation=no\n"; close $fh; ok (-r 'bug_concat.rc', 'Created bug_concat.rc'); } diff --git a/src/tests/import.csv.t b/src/tests/import.csv.t index 5659e7cf6..6b97c17eb 100755 --- a/src/tests/import.csv.t +++ b/src/tests/import.csv.t @@ -54,7 +54,13 @@ like ($output, qr/Imported 2 tasks successfully, with 0 errors./, 'no errors'); $output = qx{../task rc:import.rc list}; like ($output, qr/1.+H.+this is a test/, 't1'); +diag ("---"); +diag ($output); +diag ("---"); like ($output, qr/2.+another task/, 't2'); +diag ("---"); +diag ($output); +diag ("---"); # Cleanup. unlink 'import.txt'; diff --git a/src/util.cpp b/src/util.cpp index bd3d656f6..fc1959adf 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -449,7 +449,6 @@ bool taskDiff (const Task& before, const Task& after) foreach (name, beforeAtts) if (*name != "uuid" && - after.get (*name) != "" && before.get (*name) != after.get (*name)) return true;