Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test cases for the file metric calculation for C++ #89

Merged
merged 7 commits into from
Feb 8, 2024

Conversation

ResistantBear
Copy link
Collaborator

@ResistantBear ResistantBear commented Feb 7, 2024

Adds test source and header files in the C++ programming languages. These files are tested to compile correctly using the LLVM C++ compiler clang that comes with MacOS (command clang -c -xc++ -std=c++20 <file>)
Adds test cases that check if the file metrics are calculated correctly if these C++ files are used as input.

Additional notes:

  • Fixes that C++ for-each-loops (syntax node for_range_loop) were not counted when calculating the complexity metric

Resolves #84

@@ -58,7 +58,7 @@ This is quite slow and can take up to one or two hours but can provide good resu
Counts expressions that branch the control flow (if-statements, loops, catch-blocks, etc. - but no else/default/finally statements) and other expressions that are considered to increase the complexity of the code inside a file:

- function declarations (including lambda expressions)
- logical operations (like AND and OR)
- binary logical operations (like AND and OR)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clearification, as we do not count unary logical operations, like the use of the ! / negation operator.

["hpp", Languages.CPlusPlus],
["hxx", Languages.CPlusPlus],
["hh", Languages.CPlusPlus],
Copy link
Collaborator Author

@ResistantBear ResistantBear Feb 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added more file extensions for as supported by the GNU compiler for C++, but not the .C (capital C) extension, as we currently convert all file extension to lower case, and lower case c would indicate a file for the C programming language.
Note that we will have some trouble here anyway if we introduce a parser for the C programming language, as they also use the .h header files. We probably have to introduce a command line option to make the user decide whether his .h files should be interpreted as C or C++ code. Just leaving .h for C is no viable option here, as the use of the .h file extension is also very common for C++ headers.

@@ -56,7 +56,7 @@ export function sortCouplingResults(couplingResult: CouplingResult) {
* @param metric Name of the metric.
* @param expected Expected test result.
* */
export async function testFileMetrics(inputPath: string, metric: FileMetric, expected: number) {
export async function testFileMetric(inputPath: string, metric: FileMetric, expected: number) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed testFileMetrics to testFileMetric, as it only checks one value.

Copy link
Collaborator

@michaelalper-cezik-mw michaelalper-cezik-mw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very nice example source files, everything looks good

@michaelalper-cezik-mw michaelalper-cezik-mw merged commit bed32c0 into main Feb 8, 2024
2 checks passed
@michaelalper-cezik-mw michaelalper-cezik-mw deleted the test/84/add-c++-tests branch February 8, 2024 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add tests for file metrics for C++
2 participants