mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Bug #1247
- #1247 Tests now create a local dir, rather than use the insecure /tmp dir (thanks to Jakub Wilk).
This commit is contained in:
parent
68a12908d2
commit
31b44de8b0
3 changed files with 58 additions and 43 deletions
|
@ -26,6 +26,8 @@ Bugs
|
||||||
'Y-M-D' (thanks to Robin Björklin).
|
'Y-M-D' (thanks to Robin Björklin).
|
||||||
+ #1222 The 'summary' report now obeys the 'color.label' setting (thanks to
|
+ #1222 The 'summary' report now obeys the 'color.label' setting (thanks to
|
||||||
Steve Rader).
|
Steve Rader).
|
||||||
|
+ #1247 Tests now create a local dir, rather than use the insecure /tmp dir
|
||||||
|
(thanks to Jakub Wilk).
|
||||||
+ Fixed bug so that 'limit:page' now considers footnote messages.
|
+ Fixed bug so that 'limit:page' now considers footnote messages.
|
||||||
|
|
||||||
------ old releases ------------------------------
|
------ old releases ------------------------------
|
||||||
|
|
|
@ -25,7 +25,6 @@
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <Context.h>
|
#include <Context.h>
|
||||||
#include <Directory.h>
|
#include <Directory.h>
|
||||||
|
@ -35,37 +34,41 @@ Context context;
|
||||||
|
|
||||||
int main (int argc, char** argv)
|
int main (int argc, char** argv)
|
||||||
{
|
{
|
||||||
UnitTest t (35);
|
UnitTest t (37);
|
||||||
|
|
||||||
|
Directory tmp ("tmp");
|
||||||
|
tmp.create ();
|
||||||
|
t.ok (tmp.exists (), "tmp dir created.");
|
||||||
|
|
||||||
// Directory (const File&);
|
// Directory (const File&);
|
||||||
// Directory (const Path&);
|
// Directory (const Path&);
|
||||||
Directory d0 (Path ("/tmp"));
|
Directory d0 (Path ("tmp"));
|
||||||
Directory d1 (File ("/tmp"));
|
Directory d1 (File ("tmp"));
|
||||||
Directory d2 (File (Path ("/tmp")));
|
Directory d2 (File (Path ("tmp")));
|
||||||
t.is (d0._data, d1._data, "Directory(std::string) == Directory (File&)");
|
t.is (d0._data, d1._data, "Directory(std::string) == Directory (File&)");
|
||||||
t.is (d0._data, d2._data, "Directory(std::string) == Directory (File (Path &))");
|
t.is (d0._data, d2._data, "Directory(std::string) == Directory (File (Path &))");
|
||||||
t.is (d1._data, d2._data, "Directory(File&)) == Directory (File (Path &))");
|
t.is (d1._data, d2._data, "Directory(File&)) == Directory (File (Path &))");
|
||||||
|
|
||||||
// Directory (const Directory&);
|
// Directory (const Directory&);
|
||||||
Directory d3 (d2);
|
Directory d3 (d2);
|
||||||
t.is (d3._data, "/tmp", "Directory (Directory&)");
|
t.is (d3._data, "tmp", "Directory (Directory&)");
|
||||||
|
|
||||||
// Directory (const std::string&);
|
// Directory (const std::string&);
|
||||||
Directory d4 ("/tmp/test_directory");
|
Directory d4 ("tmp/test_directory");
|
||||||
|
|
||||||
// Directory& operator= (const Directory&);
|
// Directory& operator= (const Directory&);
|
||||||
Directory d5 = d4;
|
Directory d5 = d4;
|
||||||
t.is (d5._data, "/tmp/test_directory", "Directory::operator=");
|
t.is (d5._data, "tmp/test_directory", "Directory::operator=");
|
||||||
|
|
||||||
// operator (std::string) const;
|
// operator (std::string) const;
|
||||||
t.is ((std::string) d3, "/tmp", "Directory::operator (std::string) const");
|
t.is ((std::string) d3, "tmp", "Directory::operator (std::string) const");
|
||||||
|
|
||||||
// virtual bool create ();
|
// virtual bool create ();
|
||||||
t.ok (d5.create (), "Directory::create /tmp/test_directory");
|
t.ok (d5.create (), "Directory::create tmp/test_directory");
|
||||||
t.ok (d5.exists (), "Directory::exists /tmp/test_directory");
|
t.ok (d5.exists (), "Directory::exists tmp/test_directory");
|
||||||
|
|
||||||
Directory d6 (d5._data + "/dir");
|
Directory d6 (d5._data + "/dir");
|
||||||
t.ok (d6.create (), "Directory::create /tmp/test_directory/dir");
|
t.ok (d6.create (), "Directory::create tmp/test_directory/dir");
|
||||||
|
|
||||||
File::create (d5._data + "/f0");
|
File::create (d5._data + "/f0");
|
||||||
File::create (d6._data + "/f1");
|
File::create (d6._data + "/f1");
|
||||||
|
@ -74,35 +77,35 @@ int main (int argc, char** argv)
|
||||||
std::vector <std::string> files = d5.list ();
|
std::vector <std::string> files = d5.list ();
|
||||||
std::sort (files.begin (), files.end ());
|
std::sort (files.begin (), files.end ());
|
||||||
t.is ((int)files.size (), 2, "Directory::list 1 file");
|
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[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[1], "tmp/test_directory/f0", "file[1] is tmp/test_directory/f0");
|
||||||
|
|
||||||
// std::vector <std::string> listRecursive ();
|
// std::vector <std::string> listRecursive ();
|
||||||
files = d5.listRecursive ();
|
files = d5.listRecursive ();
|
||||||
std::sort (files.begin (), files.end ());
|
std::sort (files.begin (), files.end ());
|
||||||
t.is ((int)files.size (), 2, "Directory::list 1 file");
|
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[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[1], "tmp/test_directory/f0", "file is tmp/test_directory/f0");
|
||||||
|
|
||||||
// virtual bool remove ();
|
// virtual bool remove ();
|
||||||
t.ok (File::remove (d5._data + "/f0"), "File::remove /tmp/test_directory/f0");
|
t.ok (File::remove (d5._data + "/f0"), "File::remove tmp/test_directory/f0");
|
||||||
t.ok (File::remove (d6._data + "/f1"), "File::remove /tmp/test_directory/dir/f1");
|
t.ok (File::remove (d6._data + "/f1"), "File::remove tmp/test_directory/dir/f1");
|
||||||
|
|
||||||
t.ok (d6.remove (), "Directory::remove /tmp/test_directory/dir");
|
t.ok (d6.remove (), "Directory::remove tmp/test_directory/dir");
|
||||||
t.notok (d6.exists (), "Directory::exists /tmp/test_directory/dir - no");
|
t.notok (d6.exists (), "Directory::exists tmp/test_directory/dir - no");
|
||||||
|
|
||||||
t.ok (d5.remove (), "Directory::remove /tmp/test_directory");
|
t.ok (d5.remove (), "Directory::remove tmp/test_directory");
|
||||||
t.notok (d5.exists (), "Directory::exists /tmp/test_directory - no");
|
t.notok (d5.exists (), "Directory::exists tmp/test_directory - no");
|
||||||
|
|
||||||
// bool remove (const std::string&);
|
// bool remove (const std::string&);
|
||||||
Directory d7 ("/tmp/to_be_removed");
|
Directory d7 ("tmp/to_be_removed");
|
||||||
t.ok (d7.create (), "Directory::create /tmp/to_be_removed");
|
t.ok (d7.create (), "Directory::create tmp/to_be_removed");
|
||||||
File::create (d7._data + "/f0");
|
File::create (d7._data + "/f0");
|
||||||
Directory d8 (d7._data + "/another");
|
Directory d8 (d7._data + "/another");
|
||||||
t.ok (d8.create (), "Directory::create /tmp/to_be_removed/another");
|
t.ok (d8.create (), "Directory::create tmp/to_be_removed/another");
|
||||||
File::create (d8._data + "/f1");
|
File::create (d8._data + "/f1");
|
||||||
t.ok (d7.remove (), "Directory::remove /tmp/to_be_removed");
|
t.ok (d7.remove (), "Directory::remove tmp/to_be_removed");
|
||||||
t.notok (d7.exists (), "Directory /tmp/to_be_removed gone");
|
t.notok (d7.exists (), "Directory tmp/to_be_removed gone");
|
||||||
|
|
||||||
// static std::string cwd ();
|
// static std::string cwd ();
|
||||||
std::string cwd = Directory::cwd ();
|
std::string cwd = Directory::cwd ();
|
||||||
|
@ -120,6 +123,9 @@ int main (int argc, char** argv)
|
||||||
t.is (d9._data, "/", "parent /one --> /");
|
t.is (d9._data, "/", "parent /one --> /");
|
||||||
t.notok (d9.up (), "parent / --> false");
|
t.notok (d9.up (), "parent / --> false");
|
||||||
|
|
||||||
|
tmp.remove ();
|
||||||
|
t.notok (tmp.exists (), "tmp dir removed.");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,46 +25,53 @@
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
#include <Context.h>
|
#include <Context.h>
|
||||||
#include <File.h>
|
#include <File.h>
|
||||||
|
#include <Directory.h>
|
||||||
#include <test.h>
|
#include <test.h>
|
||||||
|
|
||||||
Context context;
|
Context context;
|
||||||
|
|
||||||
int main (int argc, char** argv)
|
int main (int argc, char** argv)
|
||||||
{
|
{
|
||||||
UnitTest t (13);
|
UnitTest t (15);
|
||||||
|
|
||||||
File::write ("/tmp/file.t.txt", "This is a test\n");
|
Directory tmp ("tmp");
|
||||||
File f6 ("/tmp/file.t.txt");
|
tmp.create ();
|
||||||
t.ok (f6.size () == 15, "File::size /tmp/file.t.txt good");
|
t.ok (tmp.exists (), "tmp dir created.");
|
||||||
t.ok (f6.mode () & S_IRUSR, "File::mode /tmp/file.t.txt good");
|
|
||||||
t.ok (File::remove ("/tmp/file.t.txt"), "File::remove /tmp/file.t.txt good");
|
File::write ("tmp/file.t.txt", "This is a test\n");
|
||||||
|
File f6 ("tmp/file.t.txt");
|
||||||
|
t.ok (f6.size () == 15, "File::size tmp/file.t.txt good");
|
||||||
|
t.ok (f6.mode () & S_IRUSR, "File::mode tmp/file.t.txt good");
|
||||||
|
t.ok (File::remove ("tmp/file.t.txt"), "File::remove tmp/file.t.txt good");
|
||||||
|
|
||||||
// operator (std::string) const;
|
// operator (std::string) const;
|
||||||
t.is ((std::string) f6, "/tmp/file.t.txt", "File::operator (std::string) const");
|
t.is ((std::string) f6, "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::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");
|
t.ok (File::remove ("tmp/file.t.create"), "File::remove tmp/file.t.create good");
|
||||||
|
|
||||||
// basename (std::string) const;
|
// basename (std::string) const;
|
||||||
t.is (f6.name (), "file.t.txt", "File::basename /tmp/file.t.txt --> file.t.txt");
|
t.is (f6.name (), "file.t.txt", "File::basename tmp/file.t.txt --> file.t.txt");
|
||||||
|
|
||||||
// dirname (std::string) const;
|
// dirname (std::string) const;
|
||||||
t.is (f6.parent (), "/tmp", "File::dirname /tmp/file.t.txt --> /tmp");
|
t.is (f6.parent (), "tmp", "File::dirname tmp/file.t.txt --> /tmp");
|
||||||
|
|
||||||
// bool rename (const std::string&);
|
// bool rename (const std::string&);
|
||||||
File f7 ("/tmp/file.t.2.txt");
|
File f7 ("tmp/file.t.2.txt");
|
||||||
f7.append ("something\n");
|
f7.append ("something\n");
|
||||||
f7.close ();
|
f7.close ();
|
||||||
|
|
||||||
t.ok (f7.rename ("/tmp/file.t.3.txt"), "File::rename did not fail");
|
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, "tmp/file.t.3.txt", "File::rename stored new name");
|
||||||
t.ok (f7.exists (), "File::rename new file exists");
|
t.ok (f7.exists (), "File::rename new file exists");
|
||||||
t.ok (f7.remove (), "File::remove /tmp/file.t.3.txt good");
|
t.ok (f7.remove (), "File::remove tmp/file.t.3.txt good");
|
||||||
t.notok (f7.exists (), "File::remove new file no longer exists");
|
t.notok (f7.exists (), "File::remove new file no longer exists");
|
||||||
|
|
||||||
|
tmp.remove ();
|
||||||
|
t.notok (tmp.exists (), "tmp dir removed.");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue