Skip to content

Commit

Permalink
Add TestMetadata struct
Browse files Browse the repository at this point in the history
  • Loading branch information
emil-e committed Oct 24, 2015
1 parent 3c12977 commit 47bafd8
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ add_library(rapidcheck
src/detail/PropertyContext.cpp
src/detail/Results.cpp
src/detail/Serialization.cpp
src/detail/TestMetadata.cpp
src/detail/TestParams.cpp
src/detail/Testing.cpp
src/gen/Numeric.cpp
Expand Down
22 changes: 22 additions & 0 deletions include/rapidcheck/detail/TestMetadata.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include <string>
#include <iostream>

namespace rc {
namespace detail {

/// Describes a property.
struct TestMetadata {
/// A unique identifier for the test.
std::string id;
/// A description of the test.
std::string description;
};

std::ostream &operator<<(std::ostream &os, const TestMetadata &info);
bool operator==(const TestMetadata &lhs, const TestMetadata &rhs);
bool operator!=(const TestMetadata &lhs, const TestMetadata &rhs);

} // namespace detail
} // namespace rc
20 changes: 20 additions & 0 deletions src/detail/TestMetadata.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "rapidcheck/detail/TestMetadata.h"

namespace rc {
namespace detail {

std::ostream &operator<<(std::ostream &os, const TestMetadata &info) {
os << "id='" << info.id << "', description='" << info.description << "'";
return os;
}

bool operator==(const TestMetadata &lhs, const TestMetadata &rhs) {
return (lhs.id == rhs.id) && (lhs.description == rhs.description);
}

bool operator!=(const TestMetadata &lhs, const TestMetadata &rhs) {
return !(lhs == rhs);
}

} // namespace detail
} // namespace rc
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ add_executable(rapidcheck_tests
detail/ResultsTests.cpp
detail/SerializationTests.cpp
detail/ShowTypeTests.cpp
detail/TestMetadataTests.cpp
detail/TestParamsTests.cpp
detail/TestingTests.cpp
detail/VariantTests.cpp
Expand Down
20 changes: 20 additions & 0 deletions test/detail/TestMetadataTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <catch.hpp>
#include <rapidcheck/catch.h>

#include "rapidcheck/detail/TestMetadata.h"

#include "util/TemplateProps.h"
#include "util/Generators.h"

using namespace rc;
using namespace rc::detail;

TEST_CASE("TestMetadata") {
SECTION("operator==/operator!=") {
propConformsToEquals<TestMetadata>();
PROP_REPLACE_MEMBER_INEQUAL(TestMetadata, id);
PROP_REPLACE_MEMBER_INEQUAL(TestMetadata, description);
}

SECTION("operator<<") { propConformsToOutputOperator<TestMetadata>(); }
}
10 changes: 10 additions & 0 deletions test/util/Generators.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "rapidcheck/shrinkable/Create.h"
#include "rapidcheck/Maybe.h"
#include "rapidcheck/seq/Create.h"
#include "rapidcheck/detail/TestMetadata.h"

#include "util/ArbitraryRandom.h"

Expand Down Expand Up @@ -117,6 +118,15 @@ struct Arbitrary<detail::CaseDescription> {
}
};

template <>
struct Arbitrary<detail::TestMetadata> {
static Gen<detail::TestMetadata> arbitrary() {
return gen::build<detail::TestMetadata>(
gen::set(&detail::TestMetadata::id),
gen::set(&detail::TestMetadata::description));
}
};

template <typename T>
struct Arbitrary<Seq<T>> {
static Gen<Seq<T>> arbitrary() {
Expand Down

0 comments on commit 47bafd8

Please sign in to comment.