mirror of
https://github.com/github/codeql.git
synced 2026-01-30 06:42:57 +01:00
PrintAst: Emit relative paths for file nodes
This is a workaround for codeql run test not itself truncating absolute paths when comparing against actual output.
This commit is contained in:
@@ -173,6 +173,20 @@ class ExprNode extends BaseAstNode {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A node representing a `File`
|
||||
*/
|
||||
class FileNode extends BaseAstNode {
|
||||
override File ast;
|
||||
|
||||
/**
|
||||
* Gets the string representation of this File. Note explicitly using a relative path
|
||||
* like this rather than absolute as per default for the File class is a workaround for
|
||||
* a bug with codeql run test, which should replace absolute paths but currently does not.
|
||||
*/
|
||||
override string toString() { result = qlClass(ast) + ast.getRelativePath() }
|
||||
}
|
||||
|
||||
query predicate nodes(PrintAstNode node, string key, string value) {
|
||||
node.shouldPrint() and
|
||||
value = node.getProperty(key)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
input.go:
|
||||
# 0| [File] /home/chris/codeql-home/codeql-go/ql/test/library-tests/semmle/go/PrintAst/input.go
|
||||
# 0| [File] library-tests/semmle/go/PrintAst/input.go
|
||||
# 3| 0: [ImportDecl] import declaration
|
||||
# 3| 0: [ImportSpec] import specifier
|
||||
# 3| 0: [StringLit] "fmt"
|
||||
|
||||
Reference in New Issue
Block a user