1 // Copyright 2020 The Pigweed Authors
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
7 // https://www.apache.org/licenses/LICENSE-2.0
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
15 #include "pw_assert_test/fake_backend.h"
20 #include "pw_string/string_builder.h"
22 // Global that's publicly accessible to read captured assert contents.
23 struct pw_CapturedAssert pw_captured_assert;
25 bool IsDirSeparator(char c) { return c == '/' || c == '\\'; }
27 const char* GetFileBasename(const char* filename) {
28 int length = std::strlen(filename);
33 // Start on the last character, find the parent directory.
34 const char* basename = filename + std::strlen(filename) - 1;
35 while (basename != filename && !IsDirSeparator(*basename)) {
38 if (IsDirSeparator(*basename)) {
44 void pw_CaptureAssert(const char* file_name,
46 const char* function_name,
50 pw_captured_assert.triggered = 1;
53 pw_captured_assert.file_name = file_name;
56 pw_captured_assert.line_number = line_number;
59 pw_captured_assert.function_name = function_name;
62 pw::StringBuilder builder(pw_captured_assert.message);
64 va_start(args, message);
65 builder.FormatVaList(message, args);