blob: 770ddbd849e7161600354b50e26719b5d68ebb00 [file] [log] [blame]
Keir Mierle854adec2020-09-03 14:07:19 -07001// Copyright 2020 The Pigweed Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may not
4// use this file except in compliance with the License. You may obtain a copy of
5// the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12// License for the specific language governing permissions and limitations under
13// the License.
14
Keir Mierle854adec2020-09-03 14:07:19 -070015#include "pw_assert/assert.h"
16
Wyatt Hepler3d0e3152021-04-29 17:08:31 -070017#include "gtest/gtest.h"
18
Keir Mierle854adec2020-09-03 14:07:19 -070019// PW_ASSERT() should always be enabled, and always evaluate the expression.
20TEST(Light, AssertTrue) {
21 int evaluated = 1;
22 PW_ASSERT(++evaluated);
23 EXPECT_EQ(evaluated, 2);
24}
25
26// PW_DASSERT() might be disabled sometimes.
27TEST(Light, DebugAssertTrue) {
28 int evaluated = 1;
29 PW_DASSERT(++evaluated);
30 if (PW_ASSERT_ENABLE_DEBUG == 1) {
31 EXPECT_EQ(evaluated, 2);
32 } else {
33 EXPECT_EQ(evaluated, 1);
34 }
35}
36
37// Unfortunately, we don't have the infrastructure to test failure handling
38// automatically, since the harness crashes in the process of running this
39// test. The unsatisfying alternative is to test the functionality manually,
40// then disable the test.
41
42TEST(Light, AssertFalse) {
43 if (0) {
44 PW_ASSERT(false);
45 }
46}
47
48TEST(Light, DebugAssertFalse) {
49 if (0) {
50 PW_DASSERT(false);
51 }
52}