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:
Chris Smowton
2020-06-17 15:03:29 +01:00
parent 80b9be1004
commit 1a823b21f1
2 changed files with 15 additions and 1 deletions

View File

@@ -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)

View File

@@ -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"