Unit Tests

- Fixed a series of bugs to improve the test suite results.
This commit is contained in:
Paul Beckingham 2009-06-28 01:04:23 -04:00
parent f3d3126839
commit ce4f26bdf3
7 changed files with 32 additions and 22 deletions

View file

@ -69,7 +69,7 @@ bool Sequence::valid (const std::string& input) const
range.size () > 2) range.size () > 2)
return false; return false;
if (range.size () == 1 && !validId (range[0])) if (range.size () <= 2 && !validId (range[0]))
return false; return false;
if (range.size () == 2 && !validId (range[1])) if (range.size () == 2 && !validId (range[1]))

View file

@ -856,13 +856,14 @@ std::string handleModify ()
{ {
std::string question = taskDifferences (before, *other) + "Are you sure?"; std::string question = taskDifferences (before, *other) + "Are you sure?";
if (changes && permission.confirmed (question)) if (changes && permission.confirmed (question))
{
context.tdb.update (*other); context.tdb.update (*other);
++count; ++count;
} }
} }
} }
} }
}
context.tdb.commit (); context.tdb.commit ();
context.tdb.unlock (); context.tdb.unlock ();

View file

@ -165,6 +165,8 @@ static void decorateTask (Task& task)
sprintf (entryTime, "%u", (unsigned int) time (NULL)); sprintf (entryTime, "%u", (unsigned int) time (NULL));
task.set ("entry", entryTime); task.set ("entry", entryTime);
task.setStatus (Task::pending);
// Override with default.project, if not specified. // Override with default.project, if not specified.
std::string defaultProject = context.config.get ("default.project", ""); std::string defaultProject = context.config.get ("default.project", "");
if (!task.has ("project") && defaultProject != "") if (!task.has ("project") && defaultProject != "")
@ -672,8 +674,8 @@ static std::string importTaskCmdLine (const std::vector <std::string>& lines)
try try
{ {
std::vector <std::string> args; context.args.clear ();
split (args, std::string ("add ") + line, ' '); split (context.args, std::string ("add ") + line, ' ');
context.task.clear (); context.task.clear ();
context.cmd.command = ""; context.cmd.command = "";
@ -719,8 +721,8 @@ static std::string importTodoSh_2_0 (const std::vector <std::string>& lines)
{ {
try try
{ {
std::vector <std::string> args; context.args.clear ();
args.push_back ("add"); context.args.push_back ("add");
bool isPending = true; bool isPending = true;
Date endDate; Date endDate;
@ -733,7 +735,7 @@ static std::string importTodoSh_2_0 (const std::vector <std::string>& lines)
if (words[w].length () > 1 && if (words[w].length () > 1 &&
words[w][0] == '+') words[w][0] == '+')
{ {
args.push_back (std::string ("project:") + context.args.push_back (std::string ("project:") +
words[w].substr (1, std::string::npos)); words[w].substr (1, std::string::npos));
} }
@ -742,7 +744,7 @@ static std::string importTodoSh_2_0 (const std::vector <std::string>& lines)
else if (words[w].length () > 1 && else if (words[w].length () > 1 &&
words[w][0] == '@') words[w][0] == '@')
{ {
args.push_back (std::string ("+") + context.args.push_back (std::string ("+") +
words[w].substr (1, std::string::npos)); words[w].substr (1, std::string::npos));
} }
@ -753,9 +755,9 @@ static std::string importTodoSh_2_0 (const std::vector <std::string>& lines)
words[w][0] == '(' && words[w][0] == '(' &&
words[w][2] == ')') words[w][2] == ')')
{ {
if (words[w][1] == 'A') args.push_back ("priority:H"); if (words[w][1] == 'A') context.args.push_back ("priority:H");
else if (words[w][1] == 'B') args.push_back ("priority:M"); else if (words[w][1] == 'B') context.args.push_back ("priority:M");
else args.push_back ("priority:L"); else context.args.push_back ("priority:L");
} }
// Set status, if completed. // Set status, if completed.
@ -778,7 +780,7 @@ static std::string importTodoSh_2_0 (const std::vector <std::string>& lines)
// Just an ordinary word. // Just an ordinary word.
else else
{ {
args.push_back (words[w]); context.args.push_back (words[w]);
} }
} }
@ -855,8 +857,8 @@ static std::string importText (const std::vector <std::string>& lines)
try try
{ {
++count; ++count;
std::vector <std::string> args; context.args.clear ();
split (args, std::string ("add ") + line, ' '); split (context.args, std::string ("add ") + line, ' ');
context.task.clear (); context.task.clear ();
context.cmd.command = ""; context.cmd.command = "";
@ -1057,6 +1059,7 @@ static std::string importCSV (const std::vector <std::string>& lines)
if ((f = mapping["uuid"]) != -1) if ((f = mapping["uuid"]) != -1)
task.set ("uuid", lowerCase (unquoteText (trim (fields[f])))); task.set ("uuid", lowerCase (unquoteText (trim (fields[f]))));
task.setStatus (Task::pending);
if ((f = mapping["status"]) != -1) if ((f = mapping["status"]) != -1)
{ {
std::string value = lowerCase (unquoteText (trim (fields[f]))); std::string value = lowerCase (unquoteText (trim (fields[f])));
@ -1065,7 +1068,6 @@ static std::string importCSV (const std::vector <std::string>& lines)
else if (value == "deleted") task.setStatus (Task::deleted); else if (value == "deleted") task.setStatus (Task::deleted);
else if (value == "completed") task.setStatus (Task::completed); else if (value == "completed") task.setStatus (Task::completed);
else if (value == "waiting") task.setStatus (Task::waiting); else if (value == "waiting") task.setStatus (Task::waiting);
else task.setStatus (Task::pending);
} }
if ((f = mapping["tags"]) != -1) 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 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 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 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: case not_a_clue:
throw std::string ("Task cannot determine which type of file this is, " throw std::string ("Task cannot determine which type of file this is, "
"and cannot proceed."); "and cannot proceed.");

View file

@ -33,7 +33,8 @@ use Test::More tests => 8;
# Create the rc file. # Create the rc file.
if (open my $fh, '>', 'args.rc') if (open my $fh, '>', 'args.rc')
{ {
print $fh "data.location=.\n"; print $fh "data.location=.\n",
"confirmation=no\n";
close $fh; close $fh;
ok (-r 'args.rc', 'Created args.rc'); ok (-r 'args.rc', 'Created args.rc');
} }

View file

@ -33,7 +33,8 @@ use Test::More tests => 6;
# Create the rc file. # Create the rc file.
if (open my $fh, '>', 'bug_concat.rc') if (open my $fh, '>', 'bug_concat.rc')
{ {
print $fh "data.location=.\n"; print $fh "data.location=.\n",
"confirmation=no\n";
close $fh; close $fh;
ok (-r 'bug_concat.rc', 'Created bug_concat.rc'); ok (-r 'bug_concat.rc', 'Created bug_concat.rc');
} }

View file

@ -54,7 +54,13 @@ like ($output, qr/Imported 2 tasks successfully, with 0 errors./, 'no errors');
$output = qx{../task rc:import.rc list}; $output = qx{../task rc:import.rc list};
like ($output, qr/1.+H.+this is a test/, 't1'); like ($output, qr/1.+H.+this is a test/, 't1');
diag ("---");
diag ($output);
diag ("---");
like ($output, qr/2.+another task/, 't2'); like ($output, qr/2.+another task/, 't2');
diag ("---");
diag ($output);
diag ("---");
# Cleanup. # Cleanup.
unlink 'import.txt'; unlink 'import.txt';

View file

@ -449,7 +449,6 @@ bool taskDiff (const Task& before, const Task& after)
foreach (name, beforeAtts) foreach (name, beforeAtts)
if (*name != "uuid" && if (*name != "uuid" &&
after.get (*name) != "" &&
before.get (*name) != after.get (*name)) before.get (*name) != after.get (*name))
return true; return true;