Skip to main content

reflection.cpp File

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

Included Headers

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

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 74 of file reflection.cpp.

74 short_name (const char* name) noexcept
75 {
76#if defined(__GNUC__)
77#pragma GCC diagnostic push
78#if defined(__clang__)
79#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
80#endif
81#endif
82 const char* p = strrchr (name, '/');
83 if (p != nullptr)
84 return p + 1;
85 else
86 return name;
87#if defined(__GNUC__)
88#pragma GCC diagnostic pop
89#endif
90 }

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#include <cstring>
37
38#if defined(MICRO_OS_PLUS_INCLUDE_CONFIG_H)
39#include <micro-os-plus/config.h>
40#endif // MICRO_OS_PLUS_INCLUDE_CONFIG_H
41
43
44// ----------------------------------------------------------------------------
45
46#if defined(__GNUC__)
47#if defined(__clang__)
48#pragma clang diagnostic ignored "-Wc++98-compat"
49#endif
50#endif
51
52// ============================================================================
53
55{
56 // --------------------------------------------------------------------------
57 // Public API.
58
59 // --------------------------------------------------------------------------
60 // Too small to deserve a separate source file.
61 namespace reflection
62 {
63
73 const char*
74 short_name (const char* name) noexcept
75 {
76#if defined(__GNUC__)
77#pragma GCC diagnostic push
78#if defined(__clang__)
79#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
80#endif
81#endif
82 const char* p = strrchr (name, '/');
83 if (p != nullptr)
84 return p + 1;
85 else
86 return name;
87#if defined(__GNUC__)
88#pragma GCC diagnostic pop
89#endif
90 }
91
92 } // namespace reflection
93
94 // ==========================================================================
95} // namespace micro_os_plus::micro_test_plus
96
97// ----------------------------------------------------------------------------

Generated via doxygen2docusaurus 2.2.0 by Doxygen 1.17.0.