Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit 1a823b2

Browse files
committed
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.
1 parent 80b9be1 commit 1a823b2

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

ql/src/semmle/go/PrintAst.qll

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,20 @@ class ExprNode extends BaseAstNode {
173173
}
174174
}
175175

176+
/**
177+
* A node representing a `File`
178+
*/
179+
class FileNode extends BaseAstNode {
180+
override File ast;
181+
182+
/**
183+
* Gets the string representation of this File. Note explicitly using a relative path
184+
* like this rather than absolute as per default for the File class is a workaround for
185+
* a bug with codeql run test, which should replace absolute paths but currently does not.
186+
*/
187+
override string toString() { result = qlClass(ast) + ast.getRelativePath() }
188+
}
189+
176190
query predicate nodes(PrintAstNode node, string key, string value) {
177191
node.shouldPrint() and
178192
value = node.getProperty(key)

ql/test/library-tests/semmle/go/PrintAst/PrintAst.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
input.go:
2-
# 0| [File] /home/chris/codeql-home/codeql-go/ql/test/library-tests/semmle/go/PrintAst/input.go
2+
# 0| [File] library-tests/semmle/go/PrintAst/input.go
33
# 3| 0: [ImportDecl] import declaration
44
# 3| 0: [ImportSpec] import specifier
55
# 3| 0: [StringLit] "fmt"

0 commit comments

Comments
 (0)