Use production directive extraction in import tests
This commit is contained in:
@@ -578,6 +578,14 @@ Focused check: `go test ./internal/engine` and `go test .`.
|
||||
Finding: **F03**.
|
||||
Owners: `internal/engine/import_spec.go`, `import_spec_test.go`, directive/selector tests.
|
||||
|
||||
Status: **complete** (F03). Prior completed commits: `2736ddf`, `deb9aa5`,
|
||||
`ae3408a`, `ea27f17`, `08a8c25`, `877c497`, `8aba43d`, `7bf2f0c`,
|
||||
`0f9ecf1`, `119b42c`, `247a12b`, `4fcff5f`, `12d350a`, `08f2a8f`,
|
||||
`826062a`, `e4a5ecb`, `3122e2f`. Validation passed:
|
||||
`env GOTOOLCHAIN=local GOPROXY=off GOTELEMETRY=off go test ./internal/engine -run 'Import|Directive|Directory|Glob|SourceVersion' -count=1`,
|
||||
`env GOTOOLCHAIN=local GOPROXY=off GOTELEMETRY=off go test ./internal/engine`,
|
||||
and `git diff --check`.
|
||||
|
||||
Change `parseImportSpecsYAML` to enter `extractRootDirectives` with the appropriate
|
||||
source context and return its imports/diagnostics. Keep parsing source fixtures
|
||||
through the real YAML boundary. Remove `parseImportSpecificationDirective`, its
|
||||
|
||||
@@ -179,26 +179,6 @@ func boolOr(explicit, application *bool, fallback bool) bool {
|
||||
return fallback
|
||||
}
|
||||
|
||||
// parseImportSpecificationDirective validates every declaration before callers select candidates.
|
||||
func parseImportSpecificationDirective(node *document.Node, directivePath Path) ([]importDeclarationSpec, []Diagnostic) {
|
||||
if node.Kind != document.Mapping {
|
||||
return nil, []Diagnostic{nodeImportDiagnostic(CodeImportInvalid, directivePath, "configuration directive must be a mapping", node)}
|
||||
}
|
||||
var specs []importDeclarationSpec
|
||||
var diagnostics []Diagnostic
|
||||
for _, entry := range node.Mapping {
|
||||
fieldPath := directivePath.Key(entry.Key)
|
||||
if entry.Key != "imports" {
|
||||
diagnostics = append(diagnostics, nodeImportDiagnostic(CodeImportInvalid, fieldPath, "configuration directive field is not recognized", entry.Value))
|
||||
continue
|
||||
}
|
||||
parsed, issues := parseImportDeclarations(entry.Value, fieldPath)
|
||||
specs = append(specs, parsed...)
|
||||
diagnostics = append(diagnostics, issues...)
|
||||
}
|
||||
return specs, canonicalDiagnostics(diagnostics)
|
||||
}
|
||||
|
||||
func parseImportDeclarations(node *document.Node, declarationPath Path) ([]importDeclarationSpec, []Diagnostic) {
|
||||
if node == nil || node.Kind != document.Sequence {
|
||||
return nil, []Diagnostic{nodeImportDiagnostic(CodeImportInvalid, declarationPath, "imports must be a sequence", node)}
|
||||
|
||||
@@ -224,11 +224,11 @@ func parseImportSpecsYAML(t *testing.T, declarations string) ([]importDeclaratio
|
||||
if len(diagnostics) != 0 {
|
||||
return nil, diagnostics
|
||||
}
|
||||
index := documentEntryIndex(parsed.document.Mapping, directiveKey)
|
||||
if index < 0 {
|
||||
t.Fatal("missing root directive in test fixture")
|
||||
extracted, diagnostics := extractRootDirectives(parsed.document, rootDirectiveContextSource)
|
||||
if len(diagnostics) != 0 {
|
||||
return nil, diagnostics
|
||||
}
|
||||
return parseImportSpecificationDirective(parsed.document.Mapping[index].Value, Keys(directiveKey))
|
||||
return extracted.imports, nil
|
||||
}
|
||||
|
||||
type countingImportSpecReader struct {
|
||||
|
||||
Reference in New Issue
Block a user