Pragma and signal validation added
This commit is contained in:
107
test/validator_implicit_signal_test.go
Normal file
107
test/validator_implicit_signal_test.go
Normal 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")
|
||||
}
|
||||
}
|
||||
69
test/validator_pragma_test.go
Normal file
69
test/validator_pragma_test.go
Normal 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")
|
||||
}
|
||||
}
|
||||
108
test/validator_signal_properties_test.go
Normal file
108
test/validator_signal_properties_test.go
Normal 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)")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user