File: normalized_test_names_test.cpp

package info (click to toggle)
cataclysm-dda 0.H-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 710,808 kB
  • sloc: cpp: 524,019; python: 11,580; sh: 1,228; makefile: 1,169; xml: 507; javascript: 150; sql: 56; exp: 41; perl: 37
file content (35 lines) | stat: -rw-r--r-- 1,098 bytes parent folder | download
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
#include "cata_catch.h"

#include <algorithm>
#include <cstddef>
#include <functional>
#include <iterator>
#include <set>

TEST_CASE( "enforce_normalized_test_cases" )
{
    const static std::string allowed_chars =
        "abcdefghijklmnopqrstuvwxyz"
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
        "0123456789"
        "_-+/";

    const std::set<char> allowed_set( allowed_chars.begin(), allowed_chars.end() );
    INFO( "Prefer simple characters for TEST_CASE names to avoid need for escaping" );
    CAPTURE( allowed_chars );

    for( const Catch::TestCase &tc :
         Catch::getAllTestCasesSorted( *Catch::getCurrentContext().getConfig() ) ) {
        const std::string &test_case_name = tc.name;
        CAPTURE( test_case_name );
        int i = 0;
        for( ; i < static_cast<int>( test_case_name.size() ); i++ ) {
            if( allowed_set.count( test_case_name[i] ) <= 0 ) {
                break;
            }
        }
        const char invalid_char = test_case_name[i];
        CAPTURE( invalid_char );
        CHECK( i == static_cast<int>( test_case_name.size() ) );
    }
}