aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/tests/assert/asserter.cpp
blob: 4a5dfd3b7bb5a2a8eafcc865e25a823db9c7838d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/vespalib/util/assert.h>
#include <cassert>
#include <cstdlib>
#include <fstream>
#include <string>

int main(int argc, char *argv[]) {
    assert(argc == 3);
    const char * assertKey = argv[1];
    size_t assertCount = strtoul(argv[2], nullptr, 0);
    for (size_t i(0); i < assertCount; i++) {
        ASSERT_ONCE_OR_LOG(true, assertKey, 100);
        ASSERT_ONCE_OR_LOG(false, assertKey, 100);
    }
    std::string filename = vespalib::assert::getAssertLogFileName(assertKey);
    std::ifstream is(filename.c_str());
    assert(is);
    std::string line;
    std::getline(is, line);
    printf("%s\n", filename.c_str());
    assert(line.find(assertKey) != std::string::npos);
    assert(assertCount == vespalib::assert::getNumAsserts(assertKey));
    return 0;
}