You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
86 lines
1.3 KiB
86 lines
1.3 KiB
10 years ago
|
/*
|
||
6 years ago
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||
9 years ago
|
*
|
||
7 years ago
|
* This source code is licensed under the MIT license found in the
|
||
|
* LICENSE file in the root directory of this source tree.
|
||
9 years ago
|
*/
|
||
10 years ago
|
|
||
|
#include <assert.h>
|
||
9 years ago
|
#include <stdlib.h>
|
||
10 years ago
|
|
||
9 years ago
|
void simple_check(int x) { assert(x < 3); }
|
||
10 years ago
|
|
||
|
void simple_assertion_failure() {
|
||
|
int x = 4;
|
||
|
simple_check(x);
|
||
|
}
|
||
|
|
||
|
void no_assertion_failure() {
|
||
|
int x = 2;
|
||
|
simple_check(x);
|
||
|
}
|
||
|
|
||
7 years ago
|
typedef struct {
|
||
|
int value;
|
||
|
} node;
|
||
10 years ago
|
|
||
9 years ago
|
void check_node(node* n) { assert(n->value < 3); }
|
||
10 years ago
|
|
||
|
node* assertion_failure_with_heap() {
|
||
9 years ago
|
node* n = malloc(sizeof(node));
|
||
10 years ago
|
if (n != NULL) {
|
||
|
n->value = 4;
|
||
|
check_node(n);
|
||
|
}
|
||
|
return n;
|
||
|
}
|
||
|
|
||
|
node* no_assertion_failure_with_heap() {
|
||
9 years ago
|
node* n = malloc(sizeof(node));
|
||
10 years ago
|
if (n != NULL) {
|
||
|
n->value = 2;
|
||
|
check_node(n);
|
||
|
}
|
||
|
return n;
|
||
|
}
|
||
|
|
||
|
void __infer_fail(char*);
|
||
|
|
||
|
void my_assert(int x) {
|
||
|
if (!x) {
|
||
10 years ago
|
__infer_fail("ASSERTION_FAILURE");
|
||
10 years ago
|
}
|
||
|
}
|
||
|
|
||
9 years ago
|
void should_not_report_assertion_failure(int x) { my_assert(x); }
|
||
10 years ago
|
|
||
|
void should_report_assertion_failure(int x) {
|
||
|
x = 0;
|
||
|
my_assert(x);
|
||
|
}
|
||
|
|
||
|
int global;
|
||
|
|
||
9 years ago
|
void check_global() { assert(global != 0); }
|
||
10 years ago
|
|
||
|
void skip() {}
|
||
|
|
||
|
void assignment_after_check() {
|
||
|
check_global();
|
||
|
global = 0;
|
||
|
skip();
|
||
|
}
|
||
|
|
||
|
void assignemt_before_check() {
|
||
|
global = 0;
|
||
|
check_global();
|
||
|
}
|
||
9 years ago
|
|
||
|
void failure_on_both_branches(int x) {
|
||
|
if (x > 3) {
|
||
|
simple_check(x);
|
||
|
} else {
|
||
|
simple_check(42);
|
||
|
}
|
||
|
}
|