Code Cleanup

- Cmake was not updating HAVE_ST_BIRTHTIME.
- NIBBLER_FEATURE_DATE was not properly applied everywhere.
- FEATURE_COLOR was not properly set.
- Some source files failed to include cmake.h, and therefore were not properly
- Removed inefficient use of std::string::substr for guaranteed single character
  strings.
- Integrated Directory::cd.
- Integrated File::ctime, ::btime.
- Integrated Path::operator+.
- Integrated Nibbler::getDigit{2,4,6}.
- Integrated HighResTimer.
  enabling/disabling code.
- All Path objects now expanded internally to absolute form.
- Modified unit tests to accomodate absolute paths.
- Merged new nibbler.t.cpp tests.
- Made various methods const.
- Includes removed from some files, added to others.
This commit is contained in:
Paul Beckingham 2013-05-05 08:33:52 -04:00
parent ebaf09cbe0
commit a1132f0028
24 changed files with 254 additions and 39 deletions

View file

@ -46,8 +46,8 @@ if (open my $fh, '>', 'color.rc')
# Test the errors colors
my $output = qx{../src/task rc:color.rc rc.debug:on add due:__ 2>&1 >/dev/null};
like ($output, qr/^\033\[33mThe\ duration\ '__'\ was\ not\ recognized\ as\ valid,\ with\ correct\ units\ like\ '3days'\.\033\[0m$/xms, 'color.error');
like ($output, qr/^\033\[32mTimer\ Config::load\ \(color.rc\) .* \033\[0m$/xms, 'color.debug');
like ($output, qr/^\033\[34mUsing\ alternate\ .taskrc\ file\ color.rc\033\[0m$/xms, 'color.header');
like ($output, qr/^\033\[32mTimer\ Config::load\ \(.+color.rc\) .* \033\[0m$/xms, 'color.debug');
like ($output, qr/^\033\[34mUsing\ alternate\ .taskrc\ file\ /xms, 'color.header');
like ($output, qr/^\033\[31mConfiguration\ override\ rc.debug:on\033\[0m$/xms, 'color.footnote');
# Cleanup.

View file

@ -51,17 +51,17 @@ int main (int argc, char** argv)
// Directory (const Directory&);
Directory d3 (d2);
t.is (d3._data, "tmp", "Directory (Directory&)");
t.is (d3._data, Directory::cwd () + "/tmp", "Directory (Directory&)");
// Directory (const std::string&);
Directory d4 ("tmp/test_directory");
// Directory& operator= (const Directory&);
Directory d5 = d4;
t.is (d5._data, "tmp/test_directory", "Directory::operator=");
t.is (d5._data, Directory::cwd () + "/tmp/test_directory", "Directory::operator=");
// operator (std::string) const;
t.is ((std::string) d3, "tmp", "Directory::operator (std::string) const");
t.is ((std::string) d3, Directory::cwd () + "/tmp", "Directory::operator (std::string) const");
// virtual bool create ();
t.ok (d5.create (), "Directory::create tmp/test_directory");
@ -77,15 +77,15 @@ int main (int argc, char** argv)
std::vector <std::string> files = d5.list ();
std::sort (files.begin (), files.end ());
t.is ((int)files.size (), 2, "Directory::list 1 file");
t.is (files[0], "tmp/test_directory/dir", "file[0] is tmp/test_directory/dir");
t.is (files[1], "tmp/test_directory/f0", "file[1] is tmp/test_directory/f0");
t.is (files[0], Directory::cwd () + "/tmp/test_directory/dir", "file[0] is tmp/test_directory/dir");
t.is (files[1], Directory::cwd () + "/tmp/test_directory/f0", "file[1] is tmp/test_directory/f0");
// std::vector <std::string> listRecursive ();
files = d5.listRecursive ();
std::sort (files.begin (), files.end ());
t.is ((int)files.size (), 2, "Directory::list 1 file");
t.is (files[0], "tmp/test_directory/dir/f1", "file is tmp/test_directory/dir/f1");
t.is (files[1], "tmp/test_directory/f0", "file is tmp/test_directory/f0");
t.is (files[0], Directory::cwd () + "/tmp/test_directory/dir/f1", "file is tmp/test_directory/dir/f1");
t.is (files[1], Directory::cwd () + "/tmp/test_directory/f0", "file is tmp/test_directory/f0");
// virtual bool remove ();
t.ok (File::remove (d5._data + "/f0"), "File::remove tmp/test_directory/f0");

View file

@ -49,9 +49,9 @@ like ($stderr, qr/^The duration '__' was not recognized as valid, with correct u
# Check that headers are sent to standard error
$stdout = qx{../src/task rc:outerr.rc list 2> /dev/null};
unlike ($stdout, qr/^Using alternate .taskrc file outerr.rc$/ms, 'Headers are not sent to stdout');
unlike ($stdout, qr/^Using alternate .taskrc file .+outerr.rc$/ms, 'Headers are not sent to stdout');
$stderr = qx{../src/task rc:outerr.rc list 2>&1 >/dev/null};
like ($stderr, qr/^Using alternate .taskrc file outerr.rc$/ms, 'Headers are sent to stderr');
like ($stderr, qr/^Using alternate .taskrc file .+outerr.rc$/ms, 'Headers are sent to stderr');
# Check that footnotes are sent to standard error
$stdout = qx{../src/task rc:outerr.rc rc.debug:on list 2> /dev/null};
@ -61,9 +61,9 @@ like ($stderr, qr/^Configuration override rc.debug:on$/ms, 'Footnotes are sent t
# Check that debugs are sent to standard error
$stdout = qx{../src/task rc:outerr.rc rc.debug:on list 2> /dev/null};
unlike ($stdout, qr/^Timer Config::load \(outerr.rc\) /ms, 'Debugs are not sent to stdout');
unlike ($stdout, qr/^Timer Config::load \(.+outerr.rc\) /ms, 'Debugs are not sent to stdout');
$stderr = qx{../src/task rc:outerr.rc rc.debug:on list 2>&1 >/dev/null};
like ($stderr, qr/^Timer Config::load \(outerr.rc\) /ms, 'Debugs are sent to stderr');
like ($stderr, qr/^Timer Config::load \(.+outerr.rc\) /ms, 'Debugs are sent to stderr');
# Cleanup.
unlink qw(pending.data completed.data undo.data backlog.data outerr.rc);

View file

@ -47,7 +47,7 @@ int main (int argc, char** argv)
t.ok (File::remove ("tmp/file.t.txt"), "File::remove tmp/file.t.txt good");
// operator (std::string) const;
t.is ((std::string) f6, "tmp/file.t.txt", "File::operator (std::string) const");
t.is ((std::string) f6, Directory::cwd () + "/tmp/file.t.txt", "File::operator (std::string) const");
t.ok (File::create ("tmp/file.t.create"), "File::create tmp/file.t.create good");
t.ok (File::remove ("tmp/file.t.create"), "File::remove tmp/file.t.create good");
@ -56,7 +56,7 @@ int main (int argc, char** argv)
t.is (f6.name (), "file.t.txt", "File::basename tmp/file.t.txt --> file.t.txt");
// dirname (std::string) const;
t.is (f6.parent (), "tmp", "File::dirname tmp/file.t.txt --> /tmp");
t.is (f6.parent (), Directory::cwd () + "/tmp", "File::dirname tmp/file.t.txt --> tmp");
// bool rename (const std::string&);
File f7 ("tmp/file.t.2.txt");
@ -64,7 +64,7 @@ int main (int argc, char** argv)
f7.close ();
t.ok (f7.rename ("tmp/file.t.3.txt"), "File::rename did not fail");
t.is (f7._data, "tmp/file.t.3.txt", "File::rename stored new name");
t.is (f7._data, Directory::cwd () + "/tmp/file.t.3.txt", "File::rename stored new name");
t.ok (f7.exists (), "File::rename new file exists");
t.ok (f7.remove (), "File::remove tmp/file.t.3.txt good");
t.notok (f7.exists (), "File::remove new file no longer exists");

View file

@ -39,15 +39,15 @@ int main (int argc, char** argv)
{
#ifdef NIBBLER_FEATURE_DATE
#ifdef NIBBLER_FEATURE_REGEX
UnitTest t (396);
UnitTest t (402);
#else
UnitTest t (372);
UnitTest t (378);
#endif
#else
#ifdef NIBBLER_FEATURE_REGEX
UnitTest t (346);
UnitTest t (338);
#else
UnitTest t (322);
UnitTest t (314);
#endif
#endif
@ -258,6 +258,24 @@ int main (int argc, char** argv)
t.is (i, 2, " '2x' : getDigit () -> 2");
t.notok (n.getDigit (i), " 'x' : getDigit () -> false");
// bool getDigit6 (int&);
t.diag ("Nibbler::getDigit6");
n = Nibbler ("654321");
t.ok (n.getDigit6 (i), " 654321 : getDigit6 () -> true");
t.is (i, 654321, " 654321 : getDigit6 () -> 654321");
// bool getDigit4 (int&);
t.diag ("Nibbler::getDigit4");
n = Nibbler ("4321");
t.ok (n.getDigit4 (i), " 4321 : getDigit4 () -> true");
t.is (i, 4321, " 4321 : getDigit4 () -> 4321");
// bool getDigit2 (int&);
t.diag ("Nibbler::getDigit2");
n = Nibbler ("21");
t.ok (n.getDigit2 (i), " 21 : getDigit2 () -> true");
t.is (i, 21, " 21 : getDigit2 () -> 21");
// bool getInt (int&);
t.diag ("Nibbler::getInt");
n = Nibbler ("123 -4");

View file

@ -27,6 +27,7 @@
#include <Context.h>
#include <Path.h>
#include <Directory.h>
#include <test.h>
Context context;
@ -37,11 +38,11 @@ int main (int argc, char** argv)
// Path ();
Path p0;
t.ok (p0._data == "", "Path::Path");
t.is (p0._data, "", "Path::Path");
// Path (const Path&);
Path p1 = Path ("foo");
t.ok (p1._data == "foo", "Path::operator=");
t.is (p1._data, Directory::cwd () + "/foo", "Path::operator=");
// Path (const std::string&);
Path p2 ("~");
@ -106,7 +107,7 @@ int main (int argc, char** argv)
// bool is_absolute () const;
t.notok (p0.is_absolute (), "'' !is_absolute");
t.notok (p1.is_absolute (), "foo !is_absolute");
t.ok (p1.is_absolute (), "foo is_absolute");
t.ok (p2.is_absolute (), "~ is_absolute (after expansion)");
t.ok (p3.is_absolute (), "/tmp is_absolute");
t.ok (p4.is_absolute (), "/a/b/c/file.ext is_absolute");

View file

@ -1,4 +1,4 @@
#! /usr/bin/env perl
#!/usr/bin/env perl
use strict;
use warnings;

View file

@ -43,16 +43,16 @@ if (open my $fh, '>', 'shadow.rc')
}
my $output = qx{../src/task rc:shadow.rc add one 2>&1 >/dev/null};
like ($output, qr/\[Shadow file '\.\/shadow\.txt' updated\.\]/, 'shadow file updated on add');
like ($output, qr/\[Shadow file '.+\/shadow\.txt' updated\.\]/, 'shadow file updated on add');
$output = qx{../src/task rc:shadow.rc list 2>&1 >/dev/null};
unlike ($output, qr/\[Shadow file '\.\/shadow\.txt' updated\.\]/, 'shadow file not updated on list');
unlike ($output, qr/\[Shadow file '.+\/shadow\.txt' updated\.\]/, 'shadow file not updated on list');
$output = qx{../src/task rc:shadow.rc 1 delete 2>&1 >/dev/null};
like ($output, qr/\[Shadow file '\.\/shadow\.txt' updated\.\]/, 'shadow file updated on delete');
like ($output, qr/\[Shadow file '.+\/shadow\.txt' updated\.\]/, 'shadow file updated on delete');
$output = qx{../src/task rc:shadow.rc list 2>&1 >/dev/null};
unlike ($output, qr/\[Shadow file '\.\/shadow\.txt' updated\.\]/, 'shadow file not updated on list');
unlike ($output, qr/\[Shadow file '.+\/shadow\.txt' updated\.\]/, 'shadow file not updated on list');
# Inspect the shadow file.
my $file = slurp ('./shadow.txt');