This file is indexed.

/usr/include/wibble/test.h is in libwibble-dev 1.1-1build1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
// -*- C++ -*-

#include <wibble/string.h>
#include <iostream>
#include <cstdlib>

#ifndef WIBBLE_TEST_H
#define WIBBLE_TEST_H

namespace wibble {

// TODO use TLS
extern int assertFailure;

struct Location {
    const char *file;
    int line, iteration;
    std::string stmt;
    Location( const char *f, int l, std::string st, int iter = -1 )
        : file( f ), line( l ), iteration( iter ), stmt( st ) {}
};

#define LOCATION(stmt) ::wibble::Location( __FILE__, __LINE__, stmt )

#undef assert // silence a gcc warning if we had assert.h included

#ifndef NDEBUG
#define LOCATION_I(stmt, i) ::wibble::Location( __FILE__, __LINE__, stmt, i )

#define assert(x) assert_fn( LOCATION( #x ), x )
#define assert_pred(p, x) assert_pred_fn( \
        LOCATION( #p "( " #x " )" ), x, p( x ) )
#define assert_eq(x, y) assert_eq_fn( LOCATION( #x " == " #y ), x, y )
#define assert_leq(x, y) assert_leq_fn( LOCATION( #x " <= " #y ), x, y )
#define assert_eq_l(i, x, y) assert_eq_fn( LOCATION_I( #x " == " #y, i ), x, y )
#define assert_neq(x, y) assert_neq_fn( LOCATION( #x " != " #y ), x, y )
#define assert_list_eq(x, y) \
    assert_list_eq_fn( LOCATION( #x " == " #y ), \
                       sizeof( y ) / sizeof( y[0] ), x, y )
#else
#define assert(x) ((void)0)
#define assert_pred(p, x) ((void)0)
#define assert_eq(x, y) ((void)0)
#define assert_leq(x, y) ((void)0)
#define assert_eq_l(i, x, y) ((void)0)
#define assert_neq(x, y) ((void)0)
#define assert_list_eq(x, y) ((void)0)
#endif

#define assert_unreachable(...) assert_die_fn( LOCATION( wibble::str::fmtf(__VA_ARGS__) ) )
#define assert_unimplemented() assert_die_fn( LOCATION( "not imlemented" ) )
#define assert_die() assert_die_fn( LOCATION( "forbidden code path tripped" ) )

struct AssertFailed {
    std::ostream &stream;
    std::ostringstream str;
    bool expect;
    AssertFailed( Location l, std::ostream &s = std::cerr )
        : stream( s )
    {
        expect = assertFailure > 0;
        str << l.file << ": " << l.line;
        if ( l.iteration != -1 )
            str << " (iteration " << l.iteration << ")";
        str << ": assertion `" << l.stmt << "' failed;";
    }

    ~AssertFailed() {
        if ( expect )
            ++assertFailure;
        else {
            stream << str.str() << std::endl;
            abort();
        }
    }
};

template< typename X >
inline AssertFailed &operator<<( AssertFailed &f, X x )
{
    f.str << x;
    return f;
}

template< typename X >
void assert_fn( Location l, X x )
{
    if ( !x ) {
        AssertFailed f( l );
    }
}

void assert_die_fn( Location l ) __attribute__((noreturn));

template< typename X, typename Y >
void assert_eq_fn( Location l, X x, Y y )
{
    if ( !( x == y ) ) {
        AssertFailed f( l );
        f << " got ["
          << x << "] != [" << y
          << "] instead";
    }
}

template< typename X, typename Y >
void assert_leq_fn( Location l, X x, Y y )
{
    if ( !( x <= y ) ) {
        AssertFailed f( l );
        f << " got ["
          << x << "] > [" << y
          << "] instead";
    }
}

template< typename X >
void assert_pred_fn( Location l, X x, bool p )
{
    if ( !p ) {
        AssertFailed f( l );
        f << " for " << x;
    }
}

template< typename X >
void assert_list_eq_fn(
    Location loc, int c, X l, const typename X::Type check[] )
{
    int i = 0;
    while ( !l.empty() ) {
        if ( l.head() != check[ i ] ) {
            AssertFailed f( loc );
            f << " list disagrees at position "
              << i << ": [" << wibble::str::fmt( l.head() )
              << "] != [" << wibble::str::fmt( check[ i ] )
              << "]";
        }
        l = l.tail();
        ++ i;
    }
    if ( i != c ) {
        AssertFailed f( loc );
        f << " got ["
          << i << "] != [" << c << "] instead";
    }
}

template< typename X, typename Y >
void assert_neq_fn( Location l, X x, Y y )
{
    if ( x != y )
        return;
    AssertFailed f( l );
    f << " got ["
      << x << "] == [" << y << "] instead";
}

inline void beginAssertFailure() {
    assertFailure = 1;
}

inline void endAssertFailure() {
#ifndef NDEBUG
    const int f = assertFailure;
    assertFailure = 0;
#endif
    assert( f > 1 );
}

struct ExpectFailure {
    ExpectFailure() { beginAssertFailure(); }
    ~ExpectFailure() { endAssertFailure(); }
};

}

typedef void Test;

#endif