Test directories
A lot of code is hard to test because it involves reading or writing files. Managing directories with test data is tedious, especially when the data is modified by tests.
UquoniTest lets you easily create test directories. Every time you want to use a test directory a new directory is created, in which you can easily create files and subdirectories, or copy from another directory.
uqtTEST(UseEmptyDirectory) { UquoniTest::TestDirectory dir; dir.MakeFile("file.txt", "1, 2"); dir.MakeDirectory("sub1"); dir.MakeDirectory("sub1/sub2"); dir.MakeFile("sub1/sub2/file.txt", "3, 4"); std::string dirname = dir; // dirname now contains the path Process(dirname); uqtASSERT(rbFILE_EXISTS(dir/"result.txt")); }
You can also reuse test directories with certain data, which will be recreated every time you use it.
uqtTEST_DIRECTORY(Predefined) { uqtDirectory.MakeFile("file1.txt", "1 2"); uqtDirectory.MakeFile("file2.txt", "5 8"); } uqtTEST(UsePredefinedTestDirectory) { UquoniTest::TestDirectory dir("Predefined"); dir.MakeFile("other_file.txt", "data"); // create extra file ... }
You can then easily check whether certain files and directories exist or not, or have certain properties (readable, writable, link, ...). The function GetFileContent returns a string that contains the content of the file, so you can perform tests on that. The class LineReader holds the contents of a file as lines, which allows to perform even more powerful checks.