Skip to content

Commit eda1c50

Browse files
authored
Create DumpSnapshot class, update tests and CMakeLists (#95)
* add .clang-format * add .clang-format * restructure directory and move c++ files out * init DumpSnapshot type * dump snapshot template * update CMakeLists.txt to read VERSION; fix initialization ordering * add unit tests with Gtest * add unit tests with Gtest * update tests workflow to configure build and run tests with CMake/ctest * update changelog * specify path to tests
1 parent efd57f9 commit eda1c50

File tree

14 files changed

+522
-237
lines changed

14 files changed

+522
-237
lines changed

.clang-format

+224
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
---
2+
Language: Cpp
3+
# BasedOnStyle: Google
4+
AccessModifierOffset: -1
5+
AlignAfterOpenBracket: Align
6+
AlignArrayOfStructures: None
7+
AlignConsecutiveMacros: None
8+
AlignConsecutiveAssignments: None
9+
AlignConsecutiveBitFields: None
10+
AlignConsecutiveDeclarations: None
11+
AlignEscapedNewlines: Left
12+
AlignOperands: Align
13+
AlignTrailingComments: true
14+
AllowAllArgumentsOnNextLine: true
15+
AllowAllParametersOfDeclarationOnNextLine: true
16+
AllowShortEnumsOnASingleLine: true
17+
AllowShortBlocksOnASingleLine: Never
18+
AllowShortCaseLabelsOnASingleLine: false
19+
AllowShortFunctionsOnASingleLine: All
20+
AllowShortLambdasOnASingleLine: All
21+
AllowShortIfStatementsOnASingleLine: WithoutElse
22+
AllowShortLoopsOnASingleLine: true
23+
AlwaysBreakAfterDefinitionReturnType: None
24+
AlwaysBreakAfterReturnType: None
25+
AlwaysBreakBeforeMultilineStrings: true
26+
AlwaysBreakTemplateDeclarations: Yes
27+
AttributeMacros:
28+
- __capability
29+
BinPackArguments: true
30+
BinPackParameters: true
31+
BraceWrapping:
32+
AfterCaseLabel: false
33+
AfterClass: false
34+
AfterControlStatement: Never
35+
AfterEnum: false
36+
AfterFunction: false
37+
AfterNamespace: false
38+
AfterObjCDeclaration: false
39+
AfterStruct: false
40+
AfterUnion: false
41+
AfterExternBlock: false
42+
BeforeCatch: false
43+
BeforeElse: false
44+
BeforeLambdaBody: false
45+
BeforeWhile: false
46+
IndentBraces: false
47+
SplitEmptyFunction: true
48+
SplitEmptyRecord: true
49+
SplitEmptyNamespace: true
50+
BreakBeforeBinaryOperators: None
51+
BreakBeforeConceptDeclarations: true
52+
BreakBeforeBraces: Attach
53+
BreakBeforeInheritanceComma: false
54+
BreakInheritanceList: BeforeColon
55+
BreakBeforeTernaryOperators: true
56+
BreakConstructorInitializersBeforeComma: false
57+
BreakConstructorInitializers: BeforeColon
58+
BreakAfterJavaFieldAnnotations: false
59+
BreakStringLiterals: true
60+
ColumnLimit: 80
61+
CommentPragmas: "^ IWYU pragma:"
62+
QualifierAlignment: Leave
63+
CompactNamespaces: false
64+
ConstructorInitializerIndentWidth: 4
65+
ContinuationIndentWidth: 4
66+
Cpp11BracedListStyle: true
67+
DeriveLineEnding: true
68+
DerivePointerAlignment: true
69+
DisableFormat: false
70+
EmptyLineAfterAccessModifier: Never
71+
EmptyLineBeforeAccessModifier: LogicalBlock
72+
ExperimentalAutoDetectBinPacking: false
73+
PackConstructorInitializers: NextLine
74+
BasedOnStyle: ""
75+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
76+
AllowAllConstructorInitializersOnNextLine: true
77+
FixNamespaceComments: true
78+
ForEachMacros:
79+
- foreach
80+
- Q_FOREACH
81+
- BOOST_FOREACH
82+
IfMacros:
83+
- KJ_IF_MAYBE
84+
IncludeBlocks: Regroup
85+
IncludeCategories:
86+
- Regex: '^<ext/.*\.h>'
87+
Priority: 2
88+
SortPriority: 0
89+
CaseSensitive: false
90+
- Regex: '^<.*\.h>'
91+
Priority: 1
92+
SortPriority: 0
93+
CaseSensitive: false
94+
- Regex: "^<.*"
95+
Priority: 2
96+
SortPriority: 0
97+
CaseSensitive: false
98+
- Regex: ".*"
99+
Priority: 3
100+
SortPriority: 0
101+
CaseSensitive: false
102+
IncludeIsMainRegex: "([-_](test|unittest))?$"
103+
IncludeIsMainSourceRegex: ""
104+
IndentAccessModifiers: false
105+
IndentCaseLabels: true
106+
IndentCaseBlocks: false
107+
IndentGotoLabels: true
108+
IndentPPDirectives: None
109+
IndentExternBlock: AfterExternBlock
110+
IndentRequires: false
111+
IndentWidth: 2
112+
IndentWrappedFunctionNames: false
113+
InsertTrailingCommas: None
114+
JavaScriptQuotes: Leave
115+
JavaScriptWrapImports: true
116+
KeepEmptyLinesAtTheStartOfBlocks: false
117+
LambdaBodyIndentation: Signature
118+
MacroBlockBegin: ""
119+
MacroBlockEnd: ""
120+
MaxEmptyLinesToKeep: 1
121+
NamespaceIndentation: None
122+
ObjCBinPackProtocolList: Never
123+
ObjCBlockIndentWidth: 2
124+
ObjCBreakBeforeNestedBlockParam: true
125+
ObjCSpaceAfterProperty: false
126+
ObjCSpaceBeforeProtocolList: true
127+
PenaltyBreakAssignment: 2
128+
PenaltyBreakBeforeFirstCallParameter: 1
129+
PenaltyBreakComment: 300
130+
PenaltyBreakFirstLessLess: 120
131+
PenaltyBreakOpenParenthesis: 0
132+
PenaltyBreakString: 1000
133+
PenaltyBreakTemplateDeclaration: 10
134+
PenaltyExcessCharacter: 1000000
135+
PenaltyReturnTypeOnItsOwnLine: 200
136+
PenaltyIndentedWhitespace: 0
137+
PointerAlignment: Left
138+
PPIndentWidth: -1
139+
RawStringFormats:
140+
- Language: Cpp
141+
Delimiters:
142+
- cc
143+
- CC
144+
- cpp
145+
- Cpp
146+
- CPP
147+
- "c++"
148+
- "C++"
149+
CanonicalDelimiter: ""
150+
BasedOnStyle: google
151+
- Language: TextProto
152+
Delimiters:
153+
- pb
154+
- PB
155+
- proto
156+
- PROTO
157+
EnclosingFunctions:
158+
- EqualsProto
159+
- EquivToProto
160+
- PARSE_PARTIAL_TEXT_PROTO
161+
- PARSE_TEST_PROTO
162+
- PARSE_TEXT_PROTO
163+
- ParseTextOrDie
164+
- ParseTextProtoOrDie
165+
- ParseTestProto
166+
- ParsePartialTestProto
167+
CanonicalDelimiter: pb
168+
BasedOnStyle: google
169+
ReferenceAlignment: Pointer
170+
ReflowComments: true
171+
RemoveBracesLLVM: false
172+
SeparateDefinitionBlocks: Leave
173+
ShortNamespaceLines: 1
174+
SortIncludes: CaseSensitive
175+
SortJavaStaticImport: Before
176+
SortUsingDeclarations: true
177+
SpaceAfterCStyleCast: false
178+
SpaceAfterLogicalNot: false
179+
SpaceAfterTemplateKeyword: true
180+
SpaceBeforeAssignmentOperators: true
181+
SpaceBeforeCaseColon: false
182+
SpaceBeforeCpp11BracedList: false
183+
SpaceBeforeCtorInitializerColon: true
184+
SpaceBeforeInheritanceColon: true
185+
SpaceBeforeParens: ControlStatements
186+
SpaceBeforeParensOptions:
187+
AfterControlStatements: true
188+
AfterForeachMacros: true
189+
AfterFunctionDefinitionName: false
190+
AfterFunctionDeclarationName: false
191+
AfterIfMacros: true
192+
AfterOverloadedOperator: false
193+
BeforeNonEmptyParentheses: false
194+
SpaceAroundPointerQualifiers: Default
195+
SpaceBeforeRangeBasedForLoopColon: true
196+
SpaceInEmptyBlock: false
197+
SpaceInEmptyParentheses: false
198+
SpacesBeforeTrailingComments: 2
199+
SpacesInAngles: Never
200+
SpacesInConditionalStatement: false
201+
SpacesInContainerLiterals: true
202+
SpacesInCStyleCastParentheses: false
203+
SpacesInLineCommentPrefix:
204+
Minimum: 1
205+
Maximum: -1
206+
SpacesInParentheses: false
207+
SpacesInSquareBrackets: false
208+
SpaceBeforeSquareBrackets: false
209+
BitFieldColonSpacing: Both
210+
Standard: Auto
211+
StatementAttributeLikeMacros:
212+
- Q_EMIT
213+
StatementMacros:
214+
- Q_UNUSED
215+
- QT_REQUIRE_VERSION
216+
TabWidth: 8
217+
UseCRLF: false
218+
UseTab: Never
219+
WhitespaceSensitiveMacros:
220+
- STRINGIZE
221+
- PP_STRINGIZE
222+
- BOOST_PP_STRINGIZE
223+
- NS_SWIFT_NAME
224+
- CF_SWIFT_NAME

.github/workflows/tests.yml

+15-57
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,7 @@ on:
1212

1313
jobs:
1414
tests:
15-
runs-on: ${{ matrix.os }}
16-
strategy:
17-
fail-fast: false
18-
matrix:
19-
os: ["ubuntu-20.04"]
20-
container:
21-
- python:3.8-buster
22-
- python:3.8-bullseye
23-
- python:3.9-buster
24-
- python:3.9-bullseye
25-
container: ${{ matrix.container }}
15+
runs-on: "ubuntu-latest"
2616
continue-on-error: false
2717
outputs:
2818
release: ${{ steps.push.outputs.release }}
@@ -33,60 +23,28 @@ jobs:
3323
persist-credentials: false
3424
token: ${{ secrets.ADMIN_TOKEN }}
3525

36-
- name: Install package dependencies
37-
run: |
38-
pip install --no-cache-dir -r ./requirements.txt
39-
pip install --no-cache-dir -r ./tests/requirements.txt
40-
41-
- name: Build package distribution
42-
run: python setup.py sdist
26+
- name: Install GCC toolchain
27+
uses: egor-tensin/setup-gcc@v1
28+
with:
29+
version: 11
30+
platform: x64
4331

44-
- name: Validate distribution
32+
- name: Install Google Tests
4533
run: |
46-
VERSION="$(cat ./VERSION)"
47-
cd dist
48-
tar xzf lmptools-${VERSION}.tar.gz
49-
diff -r lmptools-${VERSION}/lmptools/core ../lmptools/core
50-
diff -r lmptools-${VERSION}/lmptools/dump ../lmptools/dump
51-
diff -r lmptools-${VERSION}/lmptools/writers ../lmptools/writers
52-
rm -rf lmptools-${VERSION}/
53-
54-
- name: Install lmptools
55-
run: pip install -e .
34+
sudo apt-get update
35+
sudo apt-get install -y libgtest-dev
5636
57-
- name: Run tests and measure coverage
37+
- name: Configure CMake
5838
run: |
59-
PYTHONPATH=${PWD}/ pytest -vv --cov-report xml:coverage.xml --cov-report term-missing --cov '.' tests
60-
61-
- name: Upload report to Codecov
62-
if: github.ref == 'refs/head/develop' && matrix.container == 'python:3.9-buster'
63-
uses: codecov/codecov-action@v2
64-
with:
65-
files: ./coverage.xml
39+
cmake -B ${{ github.workspace }}/build -DCMAKE_BUILD_TYPE=Debug
6640
67-
- name: Get latest release tag
68-
id: get-latest-tag
69-
if: github.ref == 'refs/head/develop' && matrix.os == 'ubuntu-20.04' && matrix.container == 'python:3.9-buster'
41+
- name: Build
7042
run: |
71-
tag=$(git describe --abbrev=0)
72-
echo "::set-output name=tag::$tag"
43+
cmake --build ${{ github.workspace }}/build --config Debug
7344
74-
- name: Check if a release can be made or not
75-
id: push
76-
if: github.ref == 'refs/heads/develop' && matrix.os == 'ubuntu-20.04' && matrix.container == 'python:3.9-buster'
45+
- name: Run tests and measure coverage
7746
run: |
78-
MASTER_VERSION="$(echo '${{ steps.get-latest-tag.outputs.tag }}' | cut -c2- )"
79-
VERSION=$(cat ./VERSION)"
80-
echo "MASTER_VERSION = ${MASTER_VERSION}"
81-
echo "VERSION = ${VERSION}"
82-
release=false
83-
if [ "$MASTER_VERSION" = "$VERSION" ]; then
84-
echo "$VERSION has been previously released"
85-
else
86-
release=true
87-
fi
88-
echo "RELEASE=$release" >> $GITHUB_ENV
89-
echo "::set-output name=release::$release"
47+
ctest --test-dir ${{ github.workspace }}/build -v --output-on-failure
9048
9149
release:
9250
needs: tests

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

33
## [Unreleased]
44

5+
### Added
6+
7+
- Adding `DumpSnapshot` class skeleton
8+
9+
### Changed
10+
11+
- Update `tests.yml` to configure & build using CMake
12+
- Use GoogleTest to run C++ tests
13+
- Update CMakeLists.txt to build shared library with version information parsed from file
14+
515
## [0.17.7] - 2022-11-11
616
### Added
717
- `C++` base type for `Atom` and `SimulationBox`

CMakeLists.txt

+25-11
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,35 @@
11
cmake_minimum_required(VERSION 3.17)
22
project(lmptools)
33

4-
set(CMAKE_CXX_STANDARD 20)
4+
file(READ "VERSION" LMPTOOLS_VERSION)
5+
string(STRIP "${LMPTOOLS_VERSION}" LMPTOOLS_VERSION)
6+
message("Version will be ${LMPTOOLS_VERSION}")
57

6-
find_package(Python COMPONENTS Development Interpreter)
8+
set(CMAKE_CXX_COMPILER g++)
9+
set(CMAKE_CXX_STANDARD 20)
10+
add_compile_options(-Werror -pedantic -Wall)
711

12+
include_directories(cpp/include)
13+
file(GLOB SRCS cpp/src/*.cpp)
814

9-
include_directories(lmptools/_lib/include)
10-
include_directories(${Python_INCLUDE_DIRS})
1115

12-
FILE(GLOB SRCS lmptools/_lib/src/*.cpp)
16+
#set(CMAKE_CXX_CLANG_TIDY clang-tidy; -header-filter=.;
17+
# -checks=*,-llvmlibc-restrict-system-libc-headers,-fuchsia-overloaded-operator;
18+
# --warnings-as-errors=*;)
1319

1420
add_library(lmptools SHARED ${SRCS})
21+
set_target_properties(lmptools PROPERTIES VERSION ${LMPTOOLS_VERSION})
22+
set_target_properties(lmptools PROPERTIES SOVERSION 1)
23+
24+
25+
# Enable testing
26+
enable_testing()
27+
find_package(GTest REQUIRED)
28+
include_directories(${GTEST_INCLUDE_DIRS})
29+
30+
# Glob all tests
31+
file(GLOB ALLTESTS tests/cpp/*.cpp)
1532

16-
set_target_properties(
17-
lmptools
18-
PROPERTIES
19-
PREFIX ""
20-
OUTPUT_NAME "lmptools"
21-
LINKER_LANGUAGE CXX)
33+
add_executable(lmptoolstests ${ALLTESTS})
34+
target_link_libraries(lmptoolstests GTest::gtest GTest::gtest_main)
35+
add_test(LMPTOOLSTestSuite lmptoolstests)

0 commit comments

Comments
 (0)