Skip to content

Commit 4f86357

Browse files
committed
Added tests for CI/CD
1 parent 5c657c3 commit 4f86357

7 files changed

Lines changed: 85 additions & 6 deletions

File tree

cfg/microsoft_gsl.cfg

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
<define name="Ensures(x)" value=""/>
55
<define name="GSL_SUPPRESS(x)" value=""/>
66
<podtype name="gsl::index" sign="s"/>
7+
<podtype name="gsl::byte" sign="u" size="1"/><!-- Deprecated in GSL -->
78
<container id="gslSpan" startPattern="gsl :: span" inherits="stdSpan">
89
</container>
910
<smart-pointer class-name="gsl::owner"/>
1011
<smart-pointer class-name="gsl::not_null"/>
11-
<!-- non-existing in C++ Core Guidelines -->
12-
<smart-pointer class-name="gsl::strict_not_null"/>
13-
<!-- Deprecated in GSL -->
14-
<podtype name="gsl::byte" sign="u" size="1"/>
15-
<smart-pointer class-name="gsl::unique_ptr"/>
16-
<smart-pointer class-name="gsl::shared_ptr"/>
12+
<smart-pointer class-name="gsl::unique_ptr"><!-- Deprecated in GSL -->
13+
<unique/>
14+
</smart-pointer>
15+
<smart-pointer class-name="gsl::shared_ptr"/><!-- Deprecated in GSL -->
16+
<smart-pointer class-name="gsl::strict_not_null"/><!-- non-existing in C++ Core Guidelines -->
1717
</def>

man/manual.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,7 @@ To use a `.cfg` file shipped with Cppcheck, pass the `--library=<lib>` option. T
11611161
| `lua.cfg` | | |
11621162
| `mfc.cfg` | [MFC](https://learn.microsoft.com/en-us/cpp/mfc/mfc-desktop-applications) | |
11631163
| `microsoft_atl.cfg` | [ATL](https://learn.microsoft.com/en-us/cpp/atl/active-template-library-atl-concepts) | |
1164+
| `microsoft_gsl.cfg` | [Microsoft.GSL](https://github.com/microsoft/gsl) | |
11641165
| `microsoft_sal.cfg` | [SAL annotations](https://learn.microsoft.com/en-us/cpp/c-runtime-library/sal-annotations) | |
11651166
| `microsoft_unittest.cfg` | [CppUnitTest](https://learn.microsoft.com/en-us/visualstudio/test/microsoft-visualstudio-testtools-cppunittestframework-api-reference) | |
11661167
| `motif.cfg` | | |

test/cfg/microsoft_gsl.cpp

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// Test library configuration for microsoft_gsl.cfg
2+
//
3+
// Usage:
4+
// $ cppcheck --check-library --library=microsoft_gsl --enable=style,information --inconclusive --error-exitcode=1 --inline-suppr test/cfg/microsoft_gsl.cpp
5+
// =>
6+
// No warnings about bad library configuration, unmatched suppressions, etc. exitcode=0
7+
//
8+
9+
// C++ Standard Library
10+
#include <vector>
11+
12+
// Guideline Support Library
13+
#include <gsl/gsl>
14+
15+
struct owner_type
16+
{
17+
owner_type() = default;
18+
owner_type(const owner_type &) = delete;
19+
owner_type(owner_type &&) = default;
20+
21+
~owner_type() { delete ptr_; }
22+
23+
auto operator=(const owner_type &) -> owner_type & = delete;
24+
auto operator=(owner_type &&) -> owner_type & = default;
25+
26+
private:
27+
gsl::owner<int *> ptr_{new int(42)};
28+
};
29+
30+
auto pre_and_post_condition_test(int i) -> int
31+
{
32+
Expects(i > 0);
33+
34+
const auto result{i * 2};
35+
36+
Ensures(result > 0);
37+
return result;
38+
}
39+
40+
auto suppress_macro_test(std::span<int> s) -> int
41+
{
42+
GSL_SUPPRESS("bounds.1")
43+
return s[0];
44+
}
45+
46+
auto iterate_over_container_test(std::vector<int> v) -> int
47+
{
48+
int sum{0};
49+
50+
for (gsl::index i{0}; i < v.size(); ++i)
51+
{
52+
sum += v[i];
53+
}
54+
return sum;
55+
}
56+
57+
void not_null_test(gsl::not_null<int *> p)
58+
{
59+
Expects(p != nullptr);
60+
*p = 42;
61+
}
62+
63+
void strict_not_null_test(gsl::strict_not_null<int *> p)
64+
{
65+
Expects(p != nullptr);
66+
*p = 42;
67+
}
68+
69+
auto byte_test(gsl::byte b) -> gsl::byte
70+
{
71+
return b | 0x81;
72+
}

test/cfg/runtests.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,9 @@ function check_file {
563563
lua_fn
564564
cppcheck_run --library="$lib" "${DIR}""$f"
565565
;;
566+
microsoft_gsl.cpp)
567+
cppcheck_run --library="$lib" "${DIR}""$f"
568+
;;
566569
mfc.cpp)
567570
mfc_fn
568571
cppcheck_run --platform=win64 --library="$lib" "${DIR}""$f"

test/tools/donate_cpu_lib_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def test_library_includes(tmpdir):
5858
_test_library_includes(tmpdir, ['posix', 'gnu', 'bsd', 'opengl'], '#include\t <GL/glut.h>')
5959
_test_library_includes(tmpdir, ['posix', 'gnu', 'bsd', 'nspr'], '#include\t"prtypes.h"')
6060
_test_library_includes(tmpdir, ['posix', 'gnu', 'bsd', 'lua'], '#include \t<lua.h>')
61+
_test_library_includes(tmpdir, ['posix', 'gnu', 'bsd', 'microsoft_gsl'], '#include <gsl/gsl>')
6162

6263
def test_match_multiple_time(tmpdir):
6364
libinc = LibraryIncludes()

tools/donate_cpu_lib.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,7 @@ def __init__(self):
723723
'wxwidgets': ['<wx/', '"wx/'],
724724
'zephyr': ['<zephyr/'],
725725
'zlib': ['<zlib.h>'],
726+
'microsoft_gsl': ['<gsl/gsl>'],
726727
}
727728

728729
self.__library_includes_re = {}

win_installer/cppcheck.wxs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
<File Id='lua.cfg' Name='lua.cfg' Source='$(var.CfgsDir)\lua.cfg' />
108108
<File Id='mfc.cfg' Name='mfc.cfg' Source='$(var.CfgsDir)\mfc.cfg' />
109109
<File Id='microsoft_atl.cfg' Name='microsoft_atl.cfg' Source='$(var.CfgsDir)\microsoft_atl.cfg' />
110+
<File Id='microsoft_gsl.cfg' Name='microsoft_gsl.cfg' Source='$(var.CfgsDir)\microsoft_gsl.cfg' />
110111
<File Id='microsoft_sal.cfg' Name='microsoft_sal.cfg' Source='$(var.CfgsDir)\microsoft_sal.cfg' />
111112
<File Id='microsoft_unittest.cfg' Name='microsoft_unittest.cfg' Source='$(var.CfgsDir)\microsoft_unittest.cfg' />
112113
<File Id='motif.cfg' Name='motif.cfg' Source='$(var.CfgsDir)\motif.cfg' />

0 commit comments

Comments
 (0)