scsl  0.2.5
Shimmering Clarity Standard Library
Debug.h
Go to the documentation of this file.
1 //
2 // Project: scccl
3 // File: include/test/debug.h
4 // Author: Kyle Isom
5 // Date: 2017-06-05
6 // Namespace: test
7 //
8 // debug.h defines assertions and other debugging functions.
9 //
10 // Copyright 2017 Kyle Isom <kyle@imap.cc>
11 //
12 // Licensed under the Apache License, Version 2.0 (the "License");
13 // you may not use this file except in compliance with the License.
14 // You may obtain a copy of the License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the License is distributed on an "AS IS" BASIS,
20 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 // See the License for the specific language governing permissions and
22 // limitations under the License.
23 #if 0
24 // Disabled for now.
25 #pragma once
26 
27 #include <iostream>
28 #ifndef NDEBUG
29 #include <cstdlib>
30 #endif
31 
32 namespace test {
33 
34 // GenerateCoreDumps should be set at the beginning of the program, before
35 // multithreading. It is *not* threadsafe.
36 static bool GenerateCoreDumps = false;
37 
38 static void
39 Assert(bool cond) {
40  #ifdef NDEBUG
41  std::cout << "Not a debug build, skipping assertion." << std::endl;
42  return;
43  #endif
44 
45  if (!cond) {
46  std::cerr << "Assertion failed in " << __func__ << "(" << __FILE__ << ":" << __LINE__ << ")" << std::endl;
47  if (GenerateCoreDumps) {
48  std::abort();
49  }
50  else {
51  std::exit(1);
52  }
53  }
54 }
55 
56 }
57 #endif
void Assert(bool condition)