Moved to CUE validation

This commit is contained in:
Martino Ferrari
2026-01-23 11:16:06 +01:00
parent 5c3f05a1a4
commit 5853365707
15 changed files with 511 additions and 477 deletions

View File

@@ -38,7 +38,7 @@ func TestMDSWriterValidation(t *testing.T) {
found := false
for _, d := range v.Diagnostics {
if strings.Contains(d.Message, "Missing mandatory field 'TreeName'") {
if strings.Contains(d.Message, "TreeName: incomplete value") {
found = true
break
}
@@ -71,7 +71,7 @@ func TestMathExpressionGAMValidation(t *testing.T) {
found := false
for _, d := range v.Diagnostics {
if strings.Contains(d.Message, "Missing mandatory field 'Expression'") {
if strings.Contains(d.Message, "Expression: incomplete value") {
found = true
break
}

View File

@@ -35,10 +35,10 @@ func TestPIDGAMValidation(t *testing.T) {
foundKd := false
for _, d := range v.Diagnostics {
if strings.Contains(d.Message, "Missing mandatory field 'Ki'") {
if strings.Contains(d.Message, "Ki: incomplete value") {
foundKi = true
}
if strings.Contains(d.Message, "Missing mandatory field 'Kd'") {
if strings.Contains(d.Message, "Kd: incomplete value") {
foundKd = true
}
}
@@ -73,7 +73,7 @@ func TestFileDataSourceValidation(t *testing.T) {
found := false
for _, d := range v.Diagnostics {
if strings.Contains(d.Message, "Missing mandatory field 'Filename'") {
if strings.Contains(d.Message, "Filename: incomplete value") {
found = true
break
}

View File

@@ -35,14 +35,20 @@ func TestRealTimeApplicationValidation(t *testing.T) {
missingStates := false
for _, d := range v.Diagnostics {
if strings.Contains(d.Message, "Missing mandatory field 'Data'") {
if strings.Contains(d.Message, "Data: field is required") {
missingData = true
}
if strings.Contains(d.Message, "Missing mandatory field 'States'") {
if strings.Contains(d.Message, "States: field is required") {
missingStates = true
}
}
if !missingData || !missingStates {
for _, d := range v.Diagnostics {
t.Logf("Diagnostic: %s", d.Message)
}
}
if !missingData {
t.Error("Expected error for missing 'Data' field in RealTimeApplication")
}
@@ -73,7 +79,7 @@ func TestGAMSchedulerValidation(t *testing.T) {
found := false
for _, d := range v.Diagnostics {
if strings.Contains(d.Message, "Missing mandatory field 'TimingDataSource'") {
if strings.Contains(d.Message, "TimingDataSource: incomplete value") {
found = true
break
}

View File

@@ -32,7 +32,7 @@ func TestSDNSubscriberValidation(t *testing.T) {
found := false
for _, d := range v.Diagnostics {
if strings.Contains(d.Message, "Missing mandatory field 'Port'") {
if strings.Contains(d.Message, "Port: incomplete value") {
found = true
break
}
@@ -65,7 +65,7 @@ func TestFileWriterValidation(t *testing.T) {
found := false
for _, d := range v.Diagnostics {
if strings.Contains(d.Message, "Missing mandatory field 'Filename'") {
if strings.Contains(d.Message, "Filename: incomplete value") {
found = true
break
}

View File

@@ -82,7 +82,7 @@ func TestGAMSignalValidation(t *testing.T) {
if strings.Contains(d.Message, "DataSource 'OutDS' (Class FileWriter) is Output-only but referenced in InputSignals") {
foundBadInput = true
}
if strings.Contains(d.Message, "Signal 'MissingSig' not found in DataSource 'InDS'") {
if strings.Contains(d.Message, "Implicitly Defined Signal: 'MissingSig'") {
foundMissing = true
}
if strings.Contains(d.Message, "DataSource 'InDS' (Class FileReader) is Input-only but referenced in OutputSignals") {

View File

@@ -21,17 +21,16 @@ func TestProjectSpecificSchema(t *testing.T) {
// Define project schema
schemaContent := `
{
"classes": {
"ProjectClass": {
"fields": [
{"name": "CustomField", "type": "int", "mandatory": true}
]
}
}
package schema
#Classes: {
ProjectClass: {
CustomField: int
...
}
}
`
err = os.WriteFile(filepath.Join(tmpDir, ".marte_schema.json"), []byte(schemaContent), 0644)
err = os.WriteFile(filepath.Join(tmpDir, ".marte_schema.cue"), []byte(schemaContent), 0644)
if err != nil {
t.Fatal(err)
}
@@ -59,7 +58,7 @@ func TestProjectSpecificSchema(t *testing.T) {
found := false
for _, d := range v.Diagnostics {
if strings.Contains(d.Message, "Missing mandatory field 'CustomField'") {
if strings.Contains(d.Message, "CustomField: incomplete value") {
found = true
break
}

View File

@@ -31,7 +31,7 @@ func TestSchemaValidationMandatory(t *testing.T) {
found := false
for _, d := range v.Diagnostics {
if strings.Contains(d.Message, "Missing mandatory field 'States'") {
if strings.Contains(d.Message, "States: field is required") {
found = true
break
}
@@ -65,7 +65,7 @@ func TestSchemaValidationType(t *testing.T) {
found := false
for _, d := range v.Diagnostics {
if strings.Contains(d.Message, "Field 'First' expects type 'int'") {
if strings.Contains(d.Message, "mismatched types") {
found = true
break
}
@@ -105,8 +105,8 @@ func TestSchemaValidationOrder(t *testing.T) {
}
}
if !found {
t.Error("Expected error for out-of-order fields, but found none")
if found {
t.Error("Unexpected error for out-of-order fields (Order check is disabled in CUE)")
}
}

View File

@@ -63,8 +63,10 @@ $App = {
$Data = {
+MyDS = {
Class = DataSourceClass
Sig1 = { Type = uint32 }
Sig2 = { Type = uint32 }
+Signals = {
Sig1 = { Type = uint32 }
Sig2 = { Type = uint32 }
}
}
}
}