File: TestLib.cpp

package info (click to toggle)
snap-aligner 1.0.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 4,988 kB
  • sloc: cpp: 36,500; ansic: 5,239; python: 227; makefile: 85; sh: 28
file content (43 lines) | stat: -rw-r--r-- 1,298 bytes parent folder | download | duplicates (6)
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
#include <cstring>

#include "TestLib.h"

using namespace std;
using namespace test;

int test::runAllTests(char *filter) {
    const std::vector<TestCase*> &testCases = TestCase::getCases();
    int tested = 0;
    int passed = 0;
    const char *prevFixture = "";

    for (int i = 0; i < testCases.size(); i++) {
        TestCase *tc = testCases[i];
        if (filter != NULL && strstr(tc->fixture, filter) == NULL && strstr(tc->name, filter) == NULL) {
            // Test name does not pass filter
            continue;
        }
        tested++;
        if (strcmp(tc->fixture, prevFixture) != 0) {
            if (strlen(prevFixture) != 0) {
                cout << endl;
            }
            cout << tc->fixture << ":" << endl;
            prevFixture = tc->fixture;
        }
        cout << "- " << tc->name << ": " << flush;
        try {
            tc->run();
            cout << "[OK]" << endl;
            passed++;
        } catch (TestFailedException &e) {
            cout << "[FAILED]" << endl;
            cout << "    " << e.message << endl;
            cout << "    (" << e.file << ":" << e.line << ")" << endl;
        }
    }
    
    cout << endl << passed << " / " << tested << " tests passed." << endl;
    return (passed == tested ? 0 : 1);
}