1

我在升压测试工具中看到了宏:

BOOST_<level>_EQUAL_COLLECTION(left_begin, left_end, right_begin, right_end)

它可以通过使用 ifstream_iterator 来处理流。

Catch 框架是否提供了一种比较流/文件的方法?

4

1 回答 1

1

不是内置的,但它并不意味着。

为此,您编写自己的matcher

这是整数范围检查的文档示例:

// The matcher class
class IntRange : public Catch::MatcherBase<int> {
    int m_begin, m_end;
public:
    IntRange( int begin, int end ) : m_begin( begin ), m_end( end ) {}

    // Performs the test for this matcher
    virtual bool match( int const& i ) const override {
        return i >= m_begin && i <= m_end;
    }

    // Produces a string describing what this matcher does. It should
    // include any provided data (the begin/ end in this case) and
    // be written as if it were stating a fact (in the output it will be
    // preceded by the value under test).
    virtual std::string describe() const {
        std::ostringstream ss;
        ss << "is between " << m_begin << " and " << m_end;
        return ss.str();
    }
};

// The builder function
inline IntRange IsBetween( int begin, int end ) {
    return IntRange( begin, end );
}

// ...

// Usage
TEST_CASE("Integers are within a range")
{
    CHECK_THAT( 3, IsBetween( 1, 10 ) );
    CHECK_THAT( 100, IsBetween( 1, 10 ) );
}

显然,您可以对其进行调整以执行您需要的任何检查。

于 2018-10-30T13:39:50.147 回答