Skip to content

Commit

Permalink
fix(analyzer): Add a test for dangling embed directives / GoMod
Browse files Browse the repository at this point in the history
The `GoMod` integration does not execute `go generate/go build`, so the
embed directive in `main.go` points to a non-existing file. When `GoMod`
executes [1] it failed [2] with the previously used Go version 1.20.5.
As of [3], with Go version 1.21.1, that issue is fixed.

Add a test to ensure it keeps on working.

Note: It is essential to pass `json=Module` instead of not just
      `-json` [4], because otherwise the issue would still persist on
      Go 1.21.1. So, [3] and [4] together fix [5].

Fixes #5560.

[1] `go list -deps -json=Module -buildvcs=false ./...`
[2] `pattern file.txt: no matching`
[3] 47e4520
[4] 43ad3a7
[5] #5560.

Signed-off-by: Frank Viernau <[email protected]>
  • Loading branch information
fviernau committed Oct 6, 2023
1 parent ff9d65a commit b596b49
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
project:
id: "GoMod::gomod_dangling_embed:<REPLACE_REVISION>"
definition_file_path: "analyzer/src/funTest/assets/projects/synthetic/gomod-dangling-embed/go.mod"
declared_licenses: []
declared_licenses_processed: {}
vcs:
type: "Git"
url: "<REPLACE_URL_PROCESSED>"
revision: "<REPLACE_REVISION>"
path: "<REPLACE_PATH>"
vcs_processed:
type: "Git"
url: "<REPLACE_URL_PROCESSED>"
revision: "<REPLACE_REVISION>"
path: "<REPLACE_PATH>"
homepage_url: ""
scopes:
- name: "main"
dependencies: []
- name: "vendor"
dependencies: []
packages: []
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module gomod_dangling_embed

go 1.19
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package main

import (
_ "embed"
"fmt"
)

//go:generate touch file.txt
var(
//go:embed file.txt
file string
)

func main() {
fmt.Println(file)
fmt.Println("hello world")
}
9 changes: 9 additions & 0 deletions analyzer/src/funTest/kotlin/managers/GoModFunTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,13 @@ class GoModFunTest : StringSpec({

result.toYaml() should matchExpectedResult(expectedResultFile, definitionFile)
}

"Source files with dangling embed directives do not yield issues" {
val definitionFile = testDir.resolve("gomod-dangling-embed/go.mod")
val expectedResultFile = testDir.resolve("gomod-dangling-embed-expected-output.yml")

val result = create("GoMod").resolveSingleProject(definitionFile)

result.toYaml() should matchExpectedResult(expectedResultFile, definitionFile)
}
})

0 comments on commit b596b49

Please sign in to comment.