Skip to content

Commit

Permalink
Add regression tests for num_lines (issue meta-toolkit#90).
Browse files Browse the repository at this point in the history
  • Loading branch information
Chase Geigle committed Jun 3, 2015
1 parent d9e9ec5 commit 1052d93
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 0 deletions.
28 changes: 28 additions & 0 deletions include/test/filesystem_test.h
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
1 change: 1 addition & 0 deletions src/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ add_subdirectory(tools)
add_library(meta-testing analyzer_test.cpp
classifier_test.cpp
compression_test.cpp
filesystem_test.cpp
filter_test.cpp
forward_index_test.cpp
inverted_index_test.cpp
Expand Down
48 changes: 48 additions & 0 deletions src/test/filesystem_test.cpp
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;
}
}
}
4 changes: 4 additions & 0 deletions src/test/tools/unit-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "test/graph_test.h"
#include "test/compression_test.h"
#include "test/parser_test.h"
#include "test/filesystem_test.h"
#include "util/printing.h"

using namespace meta;
Expand All @@ -47,6 +48,7 @@ int main(int argc, char* argv[])
std::cerr << " \"compression\": runs compression reading and writing tests" << std::endl;
std::cerr << " \"graph\": runs undirected and directed graph tests" << std::endl;
std::cerr << " \"parser\": runs parser tests" << std::endl;
std::cerr << " \"filesystem\": runs filesystem tests" << std::endl;
return 1;
}

Expand Down Expand Up @@ -84,6 +86,8 @@ int main(int argc, char* argv[])
num_failed += testing::graph_tests();
if (all || args.find("parser") != args.end())
num_failed += testing::parser_tests();
if (all || args.find("filesystem") != args.end())
num_failed += testing::filesystem_tests();

return num_failed;
}
4 changes: 4 additions & 0 deletions src/test/unit_tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,7 @@ set_tests_properties(graph PROPERTIES TIMEOUT 10 WORKING_DIRECTORY
add_test(parser ${UNIT_TEST_EXE} parser)
set_tests_properties(parser PROPERTIES TIMEOUT 10 WORKING_DIRECTORY
${CMAKE_RUNTIME_OUTPUT_DIRECTORY})

add_test(filesystem ${UNIT_TEST_EXE} filesystem)
set_tests_properties(filesystem PROPERTIES TIMEOUT 10 WORKING_DIRECTORY
${CMAKE_RUNTIME_OUTPUT_DIRECTORY})

0 comments on commit 1052d93

Please sign in to comment.