forked from meta-toolkit/meta
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add regression tests for num_lines (issue meta-toolkit#90).
- Loading branch information
Chase Geigle
committed
Jun 3, 2015
1 parent
d9e9ec5
commit 1052d93
Showing
5 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* @file filesystem_test.h | ||
* @author Chase Geigle | ||
* | ||
* All files in META are dual-licensed under the MIT and NCSA licenses. For more | ||
* details, consult the file LICENSE.mit and LICENSE.ncsa in the root of the | ||
* project. | ||
*/ | ||
|
||
#ifndef META_FILESYSTEM_TEST_H_ | ||
#define META_FILESYSTEM_TEST_H_ | ||
|
||
#include "test/unit_test.h" | ||
|
||
namespace meta | ||
{ | ||
namespace testing | ||
{ | ||
|
||
/** | ||
* Runs all the filesystem tests. | ||
* @return the number of tests failed | ||
*/ | ||
int filesystem_tests(); | ||
|
||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* @file filesystem_test.cpp | ||
* @author Chase Geigle | ||
*/ | ||
|
||
#include "test/filesystem_test.h" | ||
#include "util/filesystem.h" | ||
|
||
namespace meta | ||
{ | ||
namespace testing | ||
{ | ||
|
||
namespace | ||
{ | ||
void num_lines_normal() | ||
{ | ||
{ | ||
std::string data = "this is a test\ntwo lines\n"; | ||
std::ofstream file{"filesystem-temp.txt", std::ios::binary}; | ||
file.write(data.c_str(), data.length()); | ||
} | ||
ASSERT_EQUAL(filesystem::num_lines("filesystem-temp.txt"), uint64_t{2}); | ||
} | ||
|
||
void num_lines_notrailing() | ||
{ | ||
{ | ||
std::string data = "this is a test\ntwo lines but no last newline"; | ||
std::ofstream file{"filesystem-temp.txt", std::ios::binary}; | ||
file.write(data.c_str(), data.length()); | ||
} | ||
ASSERT_EQUAL(filesystem::num_lines("filesystem-temp.txt"), uint64_t{2}); | ||
} | ||
} | ||
|
||
int filesystem_tests() | ||
{ | ||
int failed = 0; | ||
filesystem::delete_file("filessytem-temp.txt"); | ||
failed += testing::run_test("num-lines-normal", num_lines_normal); | ||
filesystem::delete_file("filessytem-temp.txt"); | ||
failed += testing::run_test("num-lines-notrailing", num_lines_notrailing); | ||
filesystem::delete_file("filessytem-temp.txt"); | ||
return failed; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters