Skip to content

Commit

Permalink
Merge pull request #15381 from geoffw0/cppfiles
Browse files Browse the repository at this point in the history
C++: Report any extracted file as successfully extracted
  • Loading branch information
geoffw0 authored Jan 26, 2024
2 parents 4602f89 + b125d2c commit d19ad49
Show file tree
Hide file tree
Showing 17 changed files with 64 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
/**
* @name Successfully extracted files
* @description Lists all files in the source code directory that were extracted without encountering a problem in the file.
* @name Extracted files
* @description Lists all files in the source code directory that were extracted.
* @kind diagnostic
* @id cpp/diagnostics/successfully-extracted-files
* @tags successfully-extracted-files
*/

import cpp
import ExtractionProblems

from File f
where
not exists(ExtractionProblem e | e.getFile() = f) and
exists(f.getRelativePath())
where exists(f.getRelativePath()) and f.fromSource()
select f, "File successfully extracted."
4 changes: 4 additions & 0 deletions cpp/ql/src/change-notes/2024-01-19-extracted-files.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
category: minorAnalysis
---
* The diagnostic query `cpp/diagnostics/successfully-extracted-files` now considers any C/C++ file seen during extraction, even one with some errors, to be extracted / scanned. This affects the Code Scanning UI measure of scanned C/C++ files.
5 changes: 5 additions & 0 deletions cpp/ql/test/query-tests/Diagnostics/ExtractedFiles.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
| containserror.cpp:0:0:0:0 | containserror.cpp | File successfully extracted. |
| containswarning.cpp:0:0:0:0 | containswarning.cpp | File successfully extracted. |
| doesnotcompile.cpp:0:0:0:0 | doesnotcompile.cpp | File successfully extracted. |
| header.h:0:0:0:0 | header.h | File successfully extracted. |
| successful.cpp:0:0:0:0 | successful.cpp | File successfully extracted. |
1 change: 1 addition & 0 deletions cpp/ql/test/query-tests/Diagnostics/ExtractedFiles.qlref
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Diagnostics/ExtractedFiles.ql
2 changes: 2 additions & 0 deletions cpp/ql/test/query-tests/Diagnostics/ExtractionErrors.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
| doesnotcompile.cpp:4:2:4:2 | Recoverable extraction error: identifier 'This' is undefined | Extraction failed in doesnotcompile.cpp with error "doesnotcompile.cpp", line 4: error: identifier "This" is undefined\n \tThis is not correct C/C++ code.\n \t^\n\n | 2 |
| doesnotcompile.cpp:4:10:4:10 | Recoverable extraction error: expected a ';' | Extraction failed in doesnotcompile.cpp with error "doesnotcompile.cpp", line 4: error: expected a ";"\n \tThis is not correct C/C++ code.\n \t ^\n\n | 2 |
1 change: 1 addition & 0 deletions cpp/ql/test/query-tests/Diagnostics/ExtractionErrors.qlref
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Diagnostics/Internal/ExtractionErrors.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
| doesnotcompile.cpp:4:2:4:2 | Recoverable extraction error: identifier 'This' is undefined | Extraction failed in doesnotcompile.cpp with warning "doesnotcompile.cpp", line 4: error: identifier "This" is undefined\n \tThis is not correct C/C++ code.\n \t^\n\n | 1 |
| doesnotcompile.cpp:4:10:4:10 | Recoverable extraction error: expected a ';' | Extraction failed in doesnotcompile.cpp with warning "doesnotcompile.cpp", line 4: error: expected a ";"\n \tThis is not correct C/C++ code.\n \t ^\n\n | 1 |
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Diagnostics/ExtractionWarnings.ql
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Diagnostics/FailedExtractorInvocations.ql
6 changes: 6 additions & 0 deletions cpp/ql/test/query-tests/Diagnostics/Info.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
| containserror.cpp:0:0:0:0 | containserror.cpp | query-tests/Diagnostics/containserror.cpp | fromSource, normalTermination |
| containswarning.cpp:0:0:0:0 | containswarning.cpp | query-tests/Diagnostics/containswarning.cpp | fromSource, normalTermination |
| doesnotcompile.cpp:0:0:0:0 | doesnotcompile.cpp | query-tests/Diagnostics/doesnotcompile.cpp | ExtractionProblem (severity 1), fromSource, normalTermination |
| file://:0:0:0:0 | | | |
| header.h:0:0:0:0 | header.h | query-tests/Diagnostics/header.h | fromSource |
| successful.cpp:0:0:0:0 | successful.cpp | query-tests/Diagnostics/successful.cpp | fromSource, normalTermination |
17 changes: 17 additions & 0 deletions cpp/ql/test/query-tests/Diagnostics/Info.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import cpp
import Diagnostics.ExtractionProblems

string describe(File f) {
exists(ExtractionProblem e | e.getFile() = f |
result = "ExtractionProblem (severity " + e.getSeverity().toString() + ")"
)
or
f.fromSource() and result = "fromSource"
or
exists(Compilation c | c.getAFileCompiled() = f |
(c.normalTermination() and result = "normalTermination")
)
}

from File f
select f, concat(f.getRelativePath(), ", "), concat(describe(f), ", ")
5 changes: 5 additions & 0 deletions cpp/ql/test/query-tests/Diagnostics/containserror.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// semmle-extractor-options: --expect_errors

void containserror() {
#error An error!
}
4 changes: 4 additions & 0 deletions cpp/ql/test/query-tests/Diagnostics/containswarning.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

void containswarning() {
#warning A warning.
}
5 changes: 5 additions & 0 deletions cpp/ql/test/query-tests/Diagnostics/doesnotcompile.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// semmle-extractor-options: --expect_errors

void doesnotcompile() {
This is not correct C/C++ code.
}
2 changes: 2 additions & 0 deletions cpp/ql/test/query-tests/Diagnostics/header.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

// a header file
5 changes: 5 additions & 0 deletions cpp/ql/test/query-tests/Diagnostics/successful.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

#include "header.h"

void successful() {
}

0 comments on commit d19ad49

Please sign in to comment.