Skip to main content

reflection.cpp File

C++ source file with implementations for the µTest++ methods. More...

Included Headers

#include "micro-os-plus/micro-test-plus/reflection.h" #include <cstring>

Namespaces Index

namespacemicro_os_plus

The primary namespace for the µOS++ framework. More...

namespacemicro_test_plus

Primary namespace for the µTest++ testing framework. More...

namespacereflection

Reflection utilities for the µTest++ testing framework. More...

Functions Index

const char *short_name (const char *name) noexcept

Extract a short type or function name from a fully qualified name. More...

Description

C++ source file with implementations for the µTest++ methods.

This source file contains the implementation of reflection::short_name(), which extracts the base file name from a fully qualified path by returning the portion after the last / separator, or the original string if no separator is present.

All definitions reside within the micro_os_plus::micro_test_plus::reflection namespace.

This file must be included when building the µTest++ library.

Functions

short_name()

const char * micro_os_plus::micro_test_plus::reflection::short_name (const char * name)
noexcept

Extract a short type or function name from a fully qualified name.

Parameters
name

The fully qualified name as a C-string.

Returns

A pointer to the short name within the input string.

This function extracts the short name from a given file path by locating the final folder separator ('/'). If a separator is found, it returns a pointer to the character immediately following it, effectively providing the file or folder name. If no separator is present, the original input string is returned. This utility is useful for reporting concise file or folder names in test output.

Definition at line 82 of file reflection.cpp.

82 short_name (const char* name) noexcept
83 {
84#if defined(__GNUC__)
85#pragma GCC diagnostic push
86#if defined(__clang__)
87#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
88#endif
89#endif
90 const char* p = strrchr (name, '/');
91 if (p != nullptr)
92 return p + 1;
93 else
94 return name;
95#if defined(__GNUC__)
96#pragma GCC diagnostic pop
97#endif
98 }

Referenced by micro_os_plus::micro_test_plus::runner::abort, micro_os_plus::micro_test_plus::reporter_human::output_fail_prefix_ and micro_os_plus::micro_test_plus::reporter_tap::output_fail_suffix_.

File Listing

The file content with the documentation metadata removed is:

1/*
2 * This file is part of the µOS++ project (https://micro-os-plus.github.io/).
3 * Copyright (c) 2021-2026 Liviu Ionescu. All rights reserved.
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose is hereby granted, under the terms of the MIT license.
7 *
8 * If a copy of the license was not distributed with this file, it can be
9 * obtained from https://opensource.org/licenses/mit.
10 *
11 * Major parts of the code are inspired from v1.1.8 of the Boost UT project,
12 * released under the terms of the Boost Version 1 Software License,
13 * which can be obtained from https://www.boost.org/LICENSE_1_0.txt.
14 */
15
16// ----------------------------------------------------------------------------
17
33
34// ----------------------------------------------------------------------------
35
36#if __has_include(<micro-os-plus/project-config.h>)
37#include <micro-os-plus/project-config.h>
38#elif __has_include(<micro-os-plus/config.h>)
39#pragma message \
40 "micro-os-plus/config.h is deprecated, rename to micro-os-plus/project-config.h and include it instead of micro-os-plus/config.h"
41#include <micro-os-plus/config.h>
42#endif // __has_include(<micro-os-plus/project-config.h>)
43
44#if __has_include(<micro-os-plus/micro-test-plus-defines.h>)
45#include <micro-os-plus/micro-test-plus-defines.h>
46#endif // __has_include(<micro-os-plus/micro-test-plus-defines.h>)
47
49
50#include <cstring>
51
52// ----------------------------------------------------------------------------
53
54#if defined(__GNUC__)
55#if defined(__clang__)
56#pragma clang diagnostic ignored "-Wc++98-compat"
57#endif
58#endif
59
60// ============================================================================
61
63{
64 // --------------------------------------------------------------------------
65 // Public API.
66
67 // --------------------------------------------------------------------------
68 // Too small to deserve a separate source file.
69 namespace reflection
70 {
71
81 const char*
82 short_name (const char* name) noexcept
83 {
84#if defined(__GNUC__)
85#pragma GCC diagnostic push
86#if defined(__clang__)
87#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
88#endif
89#endif
90 const char* p = strrchr (name, '/');
91 if (p != nullptr)
92 return p + 1;
93 else
94 return name;
95#if defined(__GNUC__)
96#pragma GCC diagnostic pop
97#endif
98 }
99
100 } // namespace reflection
101
102 // ==========================================================================
103} // namespace micro_os_plus::micro_test_plus
104
105// ----------------------------------------------------------------------------

Generated via doxygen2docusaurus 2.2.1 by Doxygen 1.17.0.