Pragma and signal validation added

This commit is contained in:
Martino Ferrari
2026-01-22 02:29:54 +01:00
parent 93d48bd3ed
commit 8fe319de2d
6 changed files with 448 additions and 22 deletions

View File

@@ -0,0 +1,107 @@
package integration
import (
"strings"
"testing"
"github.com/marte-dev/marte-dev-tools/internal/index"
"github.com/marte-dev/marte-dev-tools/internal/parser"
"github.com/marte-dev/marte-dev-tools/internal/validator"
)
func TestImplicitSignal(t *testing.T) {
content := `
+Data = {
Class = ReferenceContainer
+MyDS = {
Class = FileReader
Filename = "test"
Signals = {
ExplicitSig = { Type = uint32 }
}
}
}
+MyGAM = {
Class = IOGAM
InputSignals = {
ExplicitSig = {
DataSource = MyDS
Type = uint32
}
ImplicitSig = {
DataSource = MyDS
Type = uint32
}
}
}
`
p := parser.NewParser(content)
config, err := p.Parse()
if err != nil {
t.Fatalf("Parse failed: %v", err)
}
idx := index.NewProjectTree()
idx.AddFile("implicit_signal.marte", config)
idx.ResolveReferences()
v := validator.NewValidator(idx, ".")
v.ValidateProject()
foundWarning := false
foundError := false
for _, d := range v.Diagnostics {
if strings.Contains(d.Message, "Implicitly Defined Signal") {
if strings.Contains(d.Message, "ImplicitSig") {
foundWarning = true
}
}
if strings.Contains(d.Message, "Signal 'ExplicitSig' not found") {
foundError = true
}
}
if !foundWarning || foundError {
for _, d := range v.Diagnostics {
t.Logf("Diagnostic: %s", d.Message)
}
}
if !foundWarning {
t.Error("Expected warning for ImplicitSig")
}
if foundError {
t.Error("Unexpected error for ExplicitSig")
}
// Test missing Type for implicit
contentMissingType := `
+Data = { Class = ReferenceContainer +DS={Class=FileReader Filename="" Signals={}} }
+GAM = { Class = IOGAM InputSignals = { Impl = { DataSource = DS } } }
`
p2 := parser.NewParser(contentMissingType)
config2, err2 := p2.Parse()
if err2 != nil {
t.Fatalf("Parse2 failed: %v", err2)
}
idx2 := index.NewProjectTree()
idx2.AddFile("missing_type.marte", config2)
idx2.ResolveReferences()
v2 := validator.NewValidator(idx2, ".")
v2.ValidateProject()
foundTypeErr := false
for _, d := range v2.Diagnostics {
if strings.Contains(d.Message, "Implicit signal 'Impl' must define Type") {
foundTypeErr = true
}
}
if !foundTypeErr {
for _, d := range v2.Diagnostics {
t.Logf("Diagnostic2: %s", d.Message)
}
t.Error("Expected error for missing Type in implicit signal")
}
}

View File

@@ -0,0 +1,69 @@
package integration
import (
"strings"
"testing"
"github.com/marte-dev/marte-dev-tools/internal/index"
"github.com/marte-dev/marte-dev-tools/internal/parser"
"github.com/marte-dev/marte-dev-tools/internal/validator"
)
func TestPragmaSuppression(t *testing.T) {
content := `
+Data = {
Class = ReferenceContainer
+MyDS = {
Class = FileReader
Filename = "test"
Signals = {
//!unused: Ignore this
UnusedSig = { Type = uint32 }
UsedSig = { Type = uint32 }
}
}
}
+MyGAM = {
Class = IOGAM
InputSignals = {
UsedSig = { DataSource = MyDS Type = uint32 }
//!implicit: Ignore this implicit
ImplicitSig = { DataSource = MyDS Type = uint32 }
}
}
`
p := parser.NewParser(content)
config, err := p.Parse()
if err != nil {
t.Fatalf("Parse failed: %v", err)
}
idx := index.NewProjectTree()
idx.AddFile("pragma.marte", config)
idx.ResolveReferences()
v := validator.NewValidator(idx, ".")
v.ValidateProject()
v.CheckUnused()
foundUnusedWarning := false
foundImplicitWarning := false
for _, d := range v.Diagnostics {
if strings.Contains(d.Message, "Unused Signal") && strings.Contains(d.Message, "UnusedSig") {
foundUnusedWarning = true
}
if strings.Contains(d.Message, "Implicitly Defined Signal") && strings.Contains(d.Message, "ImplicitSig") {
foundImplicitWarning = true
}
}
if foundUnusedWarning {
t.Error("Expected warning for UnusedSig to be suppressed")
}
if foundImplicitWarning {
t.Error("Expected warning for ImplicitSig to be suppressed")
}
}

View File

@@ -0,0 +1,108 @@
package integration
import (
"strings"
"testing"
"github.com/marte-dev/marte-dev-tools/internal/index"
"github.com/marte-dev/marte-dev-tools/internal/parser"
"github.com/marte-dev/marte-dev-tools/internal/validator"
)
func TestSignalProperties(t *testing.T) {
content := `
+Data = {
Class = ReferenceContainer
+MyDS = {
Class = FileReader
Filename = "test"
Signals = {
Correct = { Type = uint32 NumberOfElements = 10 }
}
}
}
+MyGAM = {
Class = IOGAM
InputSignals = {
// Correct reference
Correct = { DataSource = MyDS Type = uint32 NumberOfElements = 10 }
// Mismatch Type
BadType = {
Alias = Correct
DataSource = MyDS
Type = float32 // Error
}
// Mismatch Elements
BadElements = {
Alias = Correct
DataSource = MyDS
Type = uint32
NumberOfElements = 20 // Error
}
// Valid Cast
//!cast(uint32, float32): Cast reason
CastSig = {
Alias = Correct
DataSource = MyDS
Type = float32 // OK
}
// Invalid Cast (Wrong definition type in pragma)
//!cast(int32, float32): Wrong def type
BadCast = {
Alias = Correct
DataSource = MyDS
Type = float32 // Error because pragma mismatch
}
}
}
`
p := parser.NewParser(content)
config, err := p.Parse()
if err != nil {
t.Fatalf("Parse failed: %v", err)
}
idx := index.NewProjectTree()
idx.AddFile("signal_props.marte", config)
idx.ResolveReferences()
v := validator.NewValidator(idx, ".")
v.ValidateProject()
foundBadType := false
foundBadElements := false
foundBadCast := false
for _, d := range v.Diagnostics {
if strings.Contains(d.Message, "property 'Type' mismatch") {
if strings.Contains(d.Message, "'BadType'") {
foundBadType = true
}
if strings.Contains(d.Message, "'BadCast'") {
foundBadCast = true
}
if strings.Contains(d.Message, "'CastSig'") {
t.Error("Unexpected error for CastSig (should be suppressed by pragma)")
}
}
if strings.Contains(d.Message, "property 'NumberOfElements' mismatch") {
foundBadElements = true
}
}
if !foundBadType {
t.Error("Expected error for BadType")
}
if !foundBadElements {
t.Error("Expected error for BadElements")
}
if !foundBadCast {
t.Error("Expected error for BadCast (pragma mismatch)")
}
}