mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Feature - Config validation
- The 'version' command now complains about use of deprecated color names and duplicate entries. - Unit tests verify duplicate detection. - Unit tests verify deprecated color detection. - Most validation code moved from command.cpp to Config.cpp.
This commit is contained in:
parent
b032a00283
commit
42c1b30c31
6 changed files with 206 additions and 25 deletions
|
@ -15,6 +15,8 @@
|
|||
the description "Pay the bill", then "description.word:the" will match, but
|
||||
"description.word:th" will not. For partial word matches, there is still
|
||||
"description.contains:th".
|
||||
+ The 'version' command now complains about use of deprecated color names and
|
||||
duplicate entries.
|
||||
+ 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 #316 which caused the timesheet report to display an oddly sorted
|
||||
|
|
|
@ -83,6 +83,7 @@ bool Config::load (const std::string& file)
|
|||
std::string key = trim (line.substr (0, equal), " \t"); // no i18n
|
||||
std::string value = trim (line.substr (equal+1, line.length () - equal), " \t"); // no i18n
|
||||
(*this)[key] = value;
|
||||
sequence.push_back (key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -329,6 +330,13 @@ void Config::setDefaults ()
|
|||
set ("alias.rm", "delete"); // TODO i18n
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Config::clear ()
|
||||
{
|
||||
std::map <std::string, std::string>::clear ();
|
||||
sequence.clear ();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Return the configuration value given the specified key.
|
||||
const std::string Config::get (const char* key)
|
||||
|
@ -437,3 +445,71 @@ void Config::all (std::vector<std::string>& items)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Config::getSequence (std::vector<std::string>& items)
|
||||
{
|
||||
items = sequence;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
std::string Config::checkForDuplicates ()
|
||||
{
|
||||
std::vector <std::string> duplicates;
|
||||
std::map <std::string, int> unique;
|
||||
|
||||
foreach (i, sequence)
|
||||
{
|
||||
if (unique.find (*i) != unique.end ())
|
||||
duplicates.push_back (*i);
|
||||
else
|
||||
unique[*i] = 0;
|
||||
}
|
||||
|
||||
std::stringstream out;
|
||||
if (duplicates.size ())
|
||||
{
|
||||
out << "Found duplicate entries for:" << std::endl;
|
||||
|
||||
foreach (i, duplicates)
|
||||
out << " " << *i << std::endl;
|
||||
|
||||
out << std::endl;
|
||||
}
|
||||
|
||||
return out.str ();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
std::string Config::checkForDeprecatedColor ()
|
||||
{
|
||||
int count = 0;
|
||||
std::vector <std::string> deprecated;
|
||||
foreach (i, *this)
|
||||
{
|
||||
if (i->first.find ("color.") != std::string::npos)
|
||||
{
|
||||
std::string value = get (i->first);
|
||||
if (value.find ("_") != std::string::npos)
|
||||
{
|
||||
++count;
|
||||
deprecated.push_back (i->first);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::stringstream out;
|
||||
if (count)
|
||||
{
|
||||
out << "Your .taskrc file contains color settings that use deprecated "
|
||||
<< "underscores. Please check:"
|
||||
<< std::endl;
|
||||
|
||||
foreach (i, deprecated)
|
||||
out << " " << *i << "=" << get (*i) << std::endl;
|
||||
|
||||
out << std::endl;
|
||||
}
|
||||
|
||||
return out.str ();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -44,6 +44,7 @@ public:
|
|||
void createDefaultRC (const std::string&, const std::string&);
|
||||
void createDefaultData (const std::string&);
|
||||
void setDefaults ();
|
||||
void clear ();
|
||||
|
||||
const std::string get (const char*);
|
||||
const std::string get (const char*, const char*);
|
||||
|
@ -56,6 +57,13 @@ public:
|
|||
void set (const std::string&, const double);
|
||||
void set (const std::string&, const std::string&);
|
||||
void all (std::vector <std::string>&);
|
||||
void getSequence (std::vector<std::string>&);
|
||||
|
||||
std::string checkForDuplicates ();
|
||||
std::string checkForDeprecatedColor ();
|
||||
|
||||
private:
|
||||
std::vector <std::string> sequence;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -551,31 +551,8 @@ int handleVersion (std::string &outs)
|
|||
out << std::endl;
|
||||
}
|
||||
|
||||
// Complain about colors that still use underscores.
|
||||
int countDeprecatedColors = 0;
|
||||
std::vector <std::string> deprecatedColors;
|
||||
foreach (i, all)
|
||||
{
|
||||
if (i->find ("color.") != std::string::npos)
|
||||
{
|
||||
std::string value = context.config.get (*i);
|
||||
if (value.find ("_") != std::string::npos)
|
||||
{
|
||||
++countDeprecatedColors;
|
||||
deprecatedColors.push_back (*i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (countDeprecatedColors)
|
||||
{
|
||||
out << "Your .taskrc file contains color settings that use deprecated "
|
||||
<< "underscores. Please check:"
|
||||
<< std::endl;
|
||||
|
||||
foreach (i, deprecatedColors)
|
||||
out << " " << *i << "=" << context.config.get (*i) << std::endl;
|
||||
}
|
||||
out << context.config.checkForDeprecatedColor ();
|
||||
out << context.config.checkForDuplicates ();
|
||||
|
||||
// Verify installation. This is mentioned in the documentation as the way to
|
||||
// ensure everything is properly installed.
|
||||
|
|
59
src/tests/color.deprecated.t
Executable file
59
src/tests/color.deprecated.t
Executable file
|
@ -0,0 +1,59 @@
|
|||
#! /usr/bin/perl
|
||||
################################################################################
|
||||
## task - a command line task list manager.
|
||||
##
|
||||
## Copyright 2006 - 2009, 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 => 6;
|
||||
|
||||
# Create the rc file.
|
||||
if (open my $fh, '>', 'color.rc')
|
||||
{
|
||||
print $fh "data.location=.\n",
|
||||
"color.pri.H=red on black\n",
|
||||
"color.pri.M=red on_black\n";
|
||||
close $fh;
|
||||
ok (-r 'color.rc', 'Created color.rc');
|
||||
}
|
||||
|
||||
# Test the add command.
|
||||
my $output = qx{../task rc:color.rc rc.longversion:off version};
|
||||
like ($output, qr/color\.pri\.M/ms, 'Deprecated color detected');
|
||||
unlike ($output, qr/color\.pri\.H/ms, 'Non-deprecated color ignored');
|
||||
|
||||
# Cleanup.
|
||||
unlink 'pending.data';
|
||||
ok (!-r 'pending.data', 'Removed pending.data');
|
||||
|
||||
unlink 'undo.data';
|
||||
ok (!-r 'undo.data', 'Removed undo.data');
|
||||
|
||||
unlink 'color.rc';
|
||||
ok (!-r 'color.rc', 'Removed color.rc');
|
||||
|
||||
exit 0;
|
||||
|
59
src/tests/config.duplicate.t
Executable file
59
src/tests/config.duplicate.t
Executable file
|
@ -0,0 +1,59 @@
|
|||
#! /usr/bin/perl
|
||||
################################################################################
|
||||
## task - a command line task list manager.
|
||||
##
|
||||
## Copyright 2006 - 2009, 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 => 6;
|
||||
|
||||
# Create the rc file.
|
||||
if (open my $fh, '>', 'duplicate.rc')
|
||||
{
|
||||
print $fh "data.location=.\n",
|
||||
"data.location=.\n",
|
||||
"color=off\n";
|
||||
close $fh;
|
||||
ok (-r 'duplicate.rc', 'Created duplicate.rc');
|
||||
}
|
||||
|
||||
# Test the add command.
|
||||
my $output = qx{../task rc:duplicate.rc rc.longversion:off version};
|
||||
like ($output, qr/data\.location/ms, 'Duplicate entry detected');
|
||||
unlike ($output, qr/colorl/ms, 'Single entry not ignored');
|
||||
|
||||
# Cleanup.
|
||||
unlink 'pending.data';
|
||||
ok (!-r 'pending.data', 'Removed pending.data');
|
||||
|
||||
unlink 'undo.data';
|
||||
ok (!-r 'undo.data', 'Removed undo.data');
|
||||
|
||||
unlink 'duplicate.rc';
|
||||
ok (!-r 'duplicate.rc', 'Removed duplicate.rc');
|
||||
|
||||
exit 0;
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue