commit d6d91a8c1b6fa67926d00b00a0bae7bf3d4507bf
parent ce46c6e8266054d199fc9ff7d31870800202b628
Author: cfillion <cfillion@users.noreply.github.com>
Date: Tue, 5 Sep 2017 21:19:17 -0700
refactor test suite I/O helper and static root paths
Diffstat:
25 files changed, 88 insertions(+), 108 deletions(-)
diff --git a/Tupfile b/Tupfile
@@ -17,5 +17,4 @@ include @(TUP_PLATFORM).tup
: build/*.o | $(LINKDEPS) |> !link $(SOFLAGS) |> $(SOTARGET)
: foreach test/*.cpp |> !build -Isrc $(SRCFLAGS) |> build/test/%B.o
-: foreach test/helper/*.cpp |> !build -Isrc $(SRCFLAGS) |> build/test/helper_%B.o
: build/*.o build/test/*.o | $(LINKDEPS) |> !link $(TSFLAGS) |> $(TSTARGET)
diff --git a/src/path.cpp b/src/path.cpp
@@ -32,9 +32,9 @@ static const char SEPARATOR = '\\';
static const string DOT = ".";
static const string DOTDOT = "..";
-const Path Path::DATA = Path("ReaPack");
+const Path Path::DATA("ReaPack");
const Path Path::CACHE = Path::DATA + "cache";
-const Path Path::CONFIG = Path("reapack.ini");
+const Path Path::CONFIG("reapack.ini");
const Path Path::REGISTRY = Path::DATA + "registry.db";
Path Path::s_root;
@@ -58,7 +58,7 @@ static vector<string> Split(const string &input, bool *absolute)
continue;
}
- const string part = input.substr(last, pos - last);
+ const string &part = input.substr(last, pos - last);
if(!part.empty() && part != ".")
list.push_back(part);
@@ -252,7 +252,7 @@ const string &Path::operator[](const size_t index) const
return at(index);
}
-UseRootPath::UseRootPath(const string &path)
+UseRootPath::UseRootPath(const Path &path)
: m_backup(move(Path::s_root))
{
Path::s_root = path;
diff --git a/src/path.hpp b/src/path.hpp
@@ -34,7 +34,7 @@ public:
static Path prefixRoot(const std::string &p) { return s_root + p; }
static const Path &root() { return s_root; }
- Path(const std::string &path = std::string());
+ Path(const std::string &path = {});
void append(const std::string &parts, bool traversal = true);
void append(const Path &other);
@@ -78,7 +78,7 @@ private:
class UseRootPath {
public:
- UseRootPath(const std::string &);
+ UseRootPath(const Path &);
~UseRootPath();
private:
diff --git a/test/api.cpp b/test/api.cpp
@@ -1,6 +1,4 @@
-#include <catch.hpp>
-
-#include "helper/io.hpp"
+#include "helper.hpp"
#include <cstring>
diff --git a/test/database.cpp b/test/database.cpp
@@ -1,4 +1,4 @@
-#include <catch.hpp>
+#include "helper.hpp"
#include <database.hpp>
diff --git a/test/filesystem.cpp b/test/filesystem.cpp
@@ -1,11 +1,10 @@
-#include <catch.hpp>
+#include "helper.hpp"
#include <filesystem.hpp>
#include <index.hpp>
static const char *M = "[filesystem]";
-
-#define RIPATH "test/indexes"
+static const Path RIPATH("test/indexes");
TEST_CASE("open unicode file", M) {
UseRootPath root(RIPATH);
diff --git a/test/filter.cpp b/test/filter.cpp
@@ -1,4 +1,4 @@
-#include <catch.hpp>
+#include "helper.hpp"
#include <filter.hpp>
diff --git a/test/helper.cpp b/test/helper.cpp
@@ -0,0 +1,37 @@
+#include "helper.hpp"
+
+#include <errors.hpp>
+#include <path.hpp>
+#include <version.hpp>
+
+using namespace std;
+
+ostream &operator<<(ostream &os, const Path &path)
+{
+ os << '"' << path.join() << '"';
+ return os;
+}
+
+ostream &operator<<(ostream &os, const set<Path> &list)
+{
+ os << '{';
+
+ for(const Path &path : list)
+ os << path << ", ";
+
+ os << '}';
+
+ return os;
+}
+
+ostream &operator<<(ostream &os, const Time &time)
+{
+ os << time.toString();
+ return os;
+}
+
+ostream &operator<<(ostream &os, const Version &ver)
+{
+ os << ver.name().toString();
+ return os;
+}
diff --git a/test/helper.hpp b/test/helper.hpp
@@ -0,0 +1,14 @@
+#include <ostream>
+#include <set>
+
+class Path;
+class Time;
+class Version;
+
+std::ostream &operator<<(std::ostream &, const Path &);
+std::ostream &operator<<(std::ostream &, const std::set<Path> &);
+std::ostream &operator<<(std::ostream &, const Time &);
+std::ostream &operator<<(std::ostream &, const Version &);
+
+// include Catch only after having declared our ostream overloads
+#include <catch.hpp>
diff --git a/test/helper/io.cpp b/test/helper/io.cpp
@@ -1,36 +0,0 @@
-#include "io.hpp"
-
-#include <path.hpp>
-#include <version.hpp>
-
-using namespace std;
-
-ostream &operator<<(ostream &os, const Path &path)
-{
- os << "\"" << path.join() << '"';
- return os;
-}
-
-ostream &operator<<(ostream &os, const set<Path> &list)
-{
- os << '{';
-
- for(const Path &path : list)
- os << path << ", ";
-
- os << '}';
-
- return os;
-}
-
-ostream &operator<<(ostream &os, const Time &time)
-{
- os << time.toString();
- return os;
-}
-
-ostream &operator<<(ostream &os, const Version &ver)
-{
- os << ver.name().toString();
- return os;
-}
diff --git a/test/helper/io.hpp b/test/helper/io.hpp
@@ -1,16 +0,0 @@
-#ifndef REAPACK_TEST_HELPER_IO_HPP
-#define REAPACK_TEST_HELPER_IO_HPP
-
-#include <ostream>
-#include <set>
-
-class Path;
-class Time;
-class Version;
-
-std::ostream &operator<<(std::ostream &, const Path &);
-std::ostream &operator<<(std::ostream &, const std::set<Path> &);
-std::ostream &operator<<(std::ostream &, const Time &);
-std::ostream &operator<<(std::ostream &, const Version &);
-
-#endif
diff --git a/test/index.cpp b/test/index.cpp
@@ -1,15 +1,14 @@
-#include <catch.hpp>
+#include "helper.hpp"
#include <errors.hpp>
#include <index.hpp>
#include <string>
-#define RIPATH "test/indexes/"
-
using namespace std;
static const char *M = "[index]";
+static const Path RIPATH("test/indexes");
TEST_CASE("index file not found", M) {
UseRootPath root(RIPATH);
@@ -25,12 +24,12 @@ TEST_CASE("index file not found", M) {
TEST_CASE("load index from raw data", M) {
SECTION("valid") {
- Index::load("", "<index version=\"1\"/>\n");
+ Index::load({}, "<index version=\"1\"/>\n");
}
SECTION("broken") {
try {
- Index::load("", "<index>\n");
+ Index::load({}, "<index>\n");
FAIL();
}
catch(const reapack_error &e) {
@@ -181,7 +180,7 @@ TEST_CASE("drop unknown package", M) {
TEST_CASE("empty category name", M) {
try {
- Category cat{string(), nullptr};
+ Category cat{{}, nullptr};
FAIL();
}
catch(const reapack_error &e) {
diff --git a/test/index_v1.cpp b/test/index_v1.cpp
@@ -1,15 +1,14 @@
-#include <catch.hpp>
+#include "helper.hpp"
#include <index.hpp>
#include <errors.hpp>
#include <string>
-#define RIPATH "test/indexes/v1/"
-
using namespace std;
static const char *M = "[reapack_v1]";
+static const Path RIPATH("test/indexes/v1");
TEST_CASE("unnamed category", M) {
UseRootPath root(RIPATH);
diff --git a/test/main.cpp b/test/main.cpp
@@ -1,2 +1,2 @@
#define CATCH_CONFIG_MAIN
-#include <catch.hpp>
+#include "helper.hpp"
diff --git a/test/metadata.cpp b/test/metadata.cpp
@@ -1,4 +1,4 @@
-#include <catch.hpp>
+#include "helper.hpp"
#include <metadata.hpp>
diff --git a/test/ostream.cpp b/test/ostream.cpp
@@ -1,4 +1,4 @@
-#include <catch.hpp>
+#include "helper.hpp"
#include <ostream.hpp>
diff --git a/test/package.cpp b/test/package.cpp
@@ -1,6 +1,4 @@
-#include <catch.hpp>
-
-#include "helper/io.hpp"
+#include "helper.hpp"
#include <errors.hpp>
#include <index.hpp>
@@ -54,7 +52,7 @@ TEST_CASE("package type to string", M) {
TEST_CASE("invalid package name", M) {
SECTION("empty") {
try {
- Package pack(Package::ScriptType, string(), nullptr);
+ Package pack(Package::ScriptType, {}, nullptr);
FAIL();
}
catch(const reapack_error &e) {
diff --git a/test/path.cpp b/test/path.cpp
@@ -1,6 +1,4 @@
-#include <catch.hpp>
-
-#include "helper/io.hpp"
+#include "helper.hpp"
#include <path.hpp>
@@ -185,7 +183,7 @@ TEST_CASE("path generation utilities", M) {
REQUIRE(Path::prefixRoot(path) == Path("world"));
{
- UseRootPath root("hello");
+ UseRootPath root(Path("hello"));
(void)root;
REQUIRE(Path::prefixRoot(path) == Path("hello/world"));
diff --git a/test/platform.cpp b/test/platform.cpp
@@ -1,4 +1,4 @@
-#include <catch.hpp>
+#include "helper.hpp"
#include <platform.hpp>
diff --git a/test/registry.cpp b/test/registry.cpp
@@ -1,6 +1,4 @@
-#include <catch.hpp>
-
-#include "helper/io.hpp"
+#include "helper.hpp"
#include <registry.hpp>
diff --git a/test/remote.cpp b/test/remote.cpp
@@ -1,10 +1,7 @@
-#include <catch.hpp>
-
-#include <remote.hpp>
+#include "helper.hpp"
#include <errors.hpp>
-
-#define RPATH "test/remote/"
+#include <remote.hpp>
using namespace std;
@@ -58,7 +55,7 @@ TEST_CASE("remote name validation", M) {
"hello_world",
"Новая папка",
"Hello ~World~",
- "Repository #1"
+ "Repository #1",
};
for(const string &name : validNames) {
diff --git a/test/serializer.cpp b/test/serializer.cpp
@@ -1,4 +1,4 @@
-#include <catch.hpp>
+#include "helper.hpp"
#include <serializer.hpp>
@@ -48,7 +48,7 @@ TEST_CASE("read from serialized data", M) {
}
SECTION("empty string") {
- const auto &out = s.read("", 1);
+ const auto &out = s.read({}, 1);
REQUIRE(out.empty());
}
}
diff --git a/test/source.cpp b/test/source.cpp
@@ -1,4 +1,4 @@
-#include <catch.hpp>
+#include "helper.hpp"
#include <index.hpp>
#include <source.hpp>
diff --git a/test/time.cpp b/test/time.cpp
@@ -1,6 +1,4 @@
-#include <catch.hpp>
-
-#include "helper/io.hpp"
+#include "helper.hpp"
#include <time.hpp>
diff --git a/test/version.cpp b/test/version.cpp
@@ -1,6 +1,4 @@
-#include <catch.hpp>
-
-#include "helper/io.hpp"
+#include "helper.hpp"
#include <version.hpp>
@@ -67,10 +65,10 @@ TEST_CASE("parse invalid versions", M) {
try {
ver.parse(name);
- FAIL(string("'") + name + "' was accepted");
+ FAIL("'" + name + "' was accepted");
}
catch(const reapack_error &e) {
- REQUIRE(string(e.what()) == string("invalid version name '") + name + "'");
+ REQUIRE(string(e.what()) == "invalid version name '" + name + "'");
}
REQUIRE(ver.toString().empty());