Skip to content

Commit

Permalink
Add Compiler Warnings for empty test asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
vijaylather committed Nov 29, 2024
1 parent 39e5c0c commit b731e26
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package org.finos.legend.engine.language.pure.compiler.test;

import org.eclipse.collections.api.factory.Lists;
import org.junit.Test;

public class TestDataSpaceCompilationFromGrammar extends TestCompilationFromGrammar.TestCompilationFromGrammarTestSuite
Expand Down Expand Up @@ -1350,7 +1351,7 @@ public void testDataSpaceExecutablesCompilation()
" ];\n" +
" defaultExecutionContext: 'Context 1';\n" +
" executables: [{ title: 'MyExec'; executable: model::MyService; }];\n" +
"}\n");
"}\n", null, Lists.fixedSize.with("COMPILATION error at [17:9-23:3]: Single execution test has empty asserts"));

// not found executable
test("###Service\n" +
Expand Down Expand Up @@ -1407,6 +1408,6 @@ public void testDataSpaceExecutablesCompilation()
" ];\n" +
" defaultExecutionContext: 'Context 1';\n" +
" executables: [{ title: 'MyExec'; executable: model::MyService; }, { title: 'MyExec1'; executable: model::Mine; }];\n" +
"}\n", "COMPILATION error at [42:1-54:1]: Error in 'model::dataSpace': Can't find the packageable element 'model::Mine'");
"}\n", "COMPILATION error at [42:1-54:1]: Error in 'model::dataSpace': Can't find the packageable element 'model::Mine'", Lists.fixedSize.with("COMPILATION error at [17:9-23:3]: Single execution test has empty asserts"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package org.finos.legend.engine.pure.dsl.persistence.cloud.compiler.test;

import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.api.tuple.Pair;
import org.finos.legend.engine.language.pure.compiler.test.TestCompilationFromGrammar;
import org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel;
Expand Down Expand Up @@ -181,7 +182,7 @@ public void persistencePlatformDataProcessingUnits()
" modelClass: test::ServiceResult;\n" +
" }\n" +
" }\n" +
"}\n", null, Collections.singletonList("COMPILATION error at [88:1-117:1]: Persistence Spec V1 will be deprecated. Please shift to using Persistence Spec V2 grammar."));
"}\n", null, Lists.fixedSize.with("COMPILATION error at [39:9-43:3]: Single execution test has empty asserts","COMPILATION error at [88:1-117:1]: Persistence Spec V1 will be deprecated. Please shift to using Persistence Spec V2 grammar."));

PureModel model = result.getTwo();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package org.finos.legend.engine.language.pure.dsl.persistence.compiler.test;

import org.eclipse.collections.api.RichIterable;
import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.api.tuple.Pair;
import org.finos.legend.engine.language.pure.compiler.test.TestCompilationFromGrammar;
import org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel;
Expand Down Expand Up @@ -1445,7 +1446,7 @@ public void flatShape()
" isTestDataFromServiceOutput: false;\n" +
" }\n" +
" ]\n" +
"}\n", null, Collections.singletonList("COMPILATION error at [48:1-114:1]: Persistence Spec V1 will be deprecated. Please shift to using Persistence Spec V2 grammar."));
"}\n", null, Lists.fixedSize.with("COMPILATION error at [30:9-34:3]: Single execution test has empty asserts","COMPILATION error at [48:1-114:1]: Persistence Spec V1 will be deprecated. Please shift to using Persistence Spec V2 grammar."));

PureModel model = result.getTwo();

Expand Down Expand Up @@ -1691,7 +1692,7 @@ public void multiFlatShape()
" }\n" +
" ];\n" +
" }\n" +
"}", null, Collections.singletonList("COMPILATION error at [68:1-149:1]: Persistence Spec V1 will be deprecated. Please shift to using Persistence Spec V2 grammar."));
"}", null, Lists.fixedSize.with("COMPILATION error at [52:9-56:3]: Single execution test has empty asserts","COMPILATION error at [68:1-149:1]: Persistence Spec V1 will be deprecated. Please shift to using Persistence Spec V2 grammar."));

PureModel model = result.getTwo();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package org.finos.legend.engine.language.pure.dsl.persistence.compiler.test;

import org.eclipse.collections.api.factory.Lists;
import org.eclipse.collections.api.tuple.Pair;
import org.finos.legend.engine.language.pure.compiler.test.TestCompilationFromGrammar;
import org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel;
Expand Down Expand Up @@ -387,7 +388,7 @@ public void persistenceContextSinkConnectionPointer()
" modelClass: test::ServiceResult;\n" +
" }\n" +
" }\n" +
"}\n", null, Collections.singletonList("COMPILATION error at [103:1-132:1]: Persistence Spec V1 will be deprecated. Please shift to using Persistence Spec V2 grammar."));
"}\n", null, Lists.fixedSize.with("COMPILATION error at [103:1-132:1]: Persistence Spec V1 will be deprecated. Please shift to using Persistence Spec V2 grammar.","COMPILATION error at [39:9-43:3]: Single execution test has empty asserts"));

PureModel model = result.getTwo();

Expand Down Expand Up @@ -589,7 +590,7 @@ public void persistenceContextSinkConnectionEmbedded()
" modelClass: test::ServiceResult;\n" +
" }\n" +
" }\n" +
"}\n", null, Collections.singletonList("COMPILATION error at [104:1-133:1]: Persistence Spec V1 will be deprecated. Please shift to using Persistence Spec V2 grammar."));
"}\n", null, Lists.fixedSize.with("COMPILATION error at [104:1-133:1]: Persistence Spec V1 will be deprecated. Please shift to using Persistence Spec V2 grammar.","COMPILATION error at [39:9-43:3]: Single execution test has empty asserts"));

PureModel model = result.getTwo();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public void snapshotTds()
" isTestDataFromServiceOutput: false;\n" +
" }\n" +
" ]\n" +
"}\n");
"}\n", null, Lists.fixedSize.with("COMPILATION error at [24:9-28:3]: Single execution test has empty asserts"));

PureModel model = result.getTwo();

Expand Down Expand Up @@ -432,7 +432,7 @@ public void deltaTds()
" isTestDataFromServiceOutput: false;\n" +
" }\n" +
" ]\n" +
"}\n");
"}\n", null, Lists.fixedSize.with("COMPILATION error at [24:9-28:3]: Single execution test has empty asserts"));

PureModel model = result.getTwo();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ public void nontemporal()
" isTestDataFromServiceOutput: false;\n" +
" }\n" +
" ]\n" +
"}\n");
"}\n", null, Lists.fixedSize.with("COMPILATION error at [24:9-28:3]: Single execution test has empty asserts"));

PureModel model = result.getTwo();

Expand Down Expand Up @@ -1115,7 +1115,7 @@ public void unitemporal()
" isTestDataFromServiceOutput: false;\n" +
" }\n" +
" ]\n" +
"}\n");
"}\n", null, Lists.fixedSize.with("COMPILATION error at [24:9-28:3]: Single execution test has empty asserts"));

PureModel model = result.getTwo();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ public static Root_meta_legend_service_metamodel_Test processServiceTest(Service
throw new EngineException("Test does not match execution type", serviceTest.sourceInformation, EngineErrorType.COMPILATION);
}
SingleExecutionTest singleExecutionTest = (SingleExecutionTest) serviceTest;

if (singleExecutionTest.asserts != null && singleExecutionTest.asserts.isEmpty())
{
context.pureModel.addWarnings(Lists.mutable.with(new Warning(singleExecutionTest.sourceInformation, "Single execution test has empty asserts")));
}
return new Root_meta_legend_service_metamodel_SingleExecutionTest_Impl("", null, context.pureModel.getClass("meta::legend::service::metamodel::SingleExecutionTest"))
._data(singleExecutionTest.data)
._asserts(ListIterate.collect(singleExecutionTest.asserts, assertion -> processTestContainer(assertion, context)));
Expand Down Expand Up @@ -265,6 +270,12 @@ private static Root_meta_legend_service_metamodel_KeyedSingleExecutionTest proce
{
throw new EngineException("Service test with key '" + keyedSingleExecutionTest.key + "' already existed", keyedSingleExecutionTest.sourceInformation, EngineErrorType.COMPILATION);
}

if (keyedSingleExecutionTest.asserts != null && keyedSingleExecutionTest.key != null && keyedSingleExecutionTest.asserts.isEmpty())
{
context.pureModel.addWarnings(Lists.mutable.with(new Warning(keyedSingleExecutionTest.sourceInformation, "Multi execution" + " with test id: " + keyedSingleExecutionTest.key + "test has empty asserts")));
}

return new Root_meta_legend_service_metamodel_KeyedSingleExecutionTest_Impl("", null, context.pureModel.getClass("meta::legend::service::metamodel::KeyedSingleExecutionTest"))
._key(keyedSingleExecutionTest.key)
._data(keyedSingleExecutionTest.data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package org.finos.legend.engine.language.pure.compiler.test;

import org.eclipse.collections.impl.list.mutable.FastList;
import org.eclipse.collections.api.factory.Lists;
import org.junit.Test;

public class TestServiceCompilationFromGrammar extends TestCompilationFromGrammar.TestCompilationFromGrammarTestSuite
Expand Down Expand Up @@ -929,6 +930,139 @@ public void testServiceCompilationWithMilestoningElements()
"}\n");
}

@Test
public void testServiceWithSingleExecutionTestEmptyAsserts()
{
partialCompilationTest("Class meta::mySimpleClass\n" +
"{\n" +
" name: String[1];\n" +
"}\n" +
"\n\n" +
"Class meta::mySimpleClass2\n" +
"{\n" +
" name: String[1];\n" +
"}\n\n" +
"###Mapping\n" +
"Mapping meta::mySimpleMapping\n" +
"(\n" +
")\n\n\n" +
"###Connection\n" +
"JsonModelConnection meta::myConnection\n" +
"{\n" +
" class: meta::mySimpleClass;\n" +
" url: 'dummy';\n" +
"}\n\n\n" +
"###Runtime\n" +
"Runtime meta::mySimpleRuntime\n" +
"{\n" +
" mappings: [meta::mySimpleMapping];\n" +
"}\n\n\n" +
"###Service\n" +
"import meta::*;\n" +
// Service with embedded runtime
"Service meta::pure::myServiceSingleWithEmbeddedRuntime\n" +
"{\n" +
" pattern: 'url/myUrl/';\n" +
" documentation: 'this is just for context';\n" +
" autoActivateUpdates: true;\n" +
" execution: Single\n" +
" {\n" +
" query: src: mySimpleClass[1]|$src.name;\n" +
" mapping: mySimpleMapping;\n" +
" runtime:\n" +
" #{\n" +
" connections:\n" +
" [\n" +
" ModelStore:\n" +
" [\n" +
// embedded connection pointer
" id1: myConnection,\n" +
" id3: #{\n" +
" JsonModelConnection\n" +
" {\n" +
// embedded connection value
" class: mySimpleClass2;\n" +
" url: 'my_url';\n" +
" }\n" +
" }#\n" +
" ]\n" +
" ];\n" +
" }#;\n" +
" }\n" +
" test: Single\n" +
" {\n" +
" data: 'moreThanData';\n" +
" asserts:\n" +
" [\n" +
" ];\n" +
" }\n" +
"}\n", null, Lists.fixedSize.with("COMPILATION error at [62:9-68:3]: Single execution test has empty asserts"));
}

@Test
public void testServiceWithMultiExecutionTestEmptyAsserts()
{
partialCompilationTest("Class meta::mySimpleClass\n" +
"{\n" +
" name: String[1];\n" +
"}\n" +
"\n\n" +
"Class meta::mySimpleClass2\n" +
"{\n" +
" name: String[1];\n" +
"}\n\n" +
"###Mapping\n" +
"Mapping meta::mySimpleMapping\n" +
"(\n" +
")\n\n\n" +
"###Connection\n" +
"JsonModelConnection meta::myConnection\n" +
"{\n" +
" class: meta::mySimpleClass;\n" +
" url: 'dummy';\n" +
"}\n\n\n" +
"###Runtime\n" +
"Runtime meta::mySimpleRuntime\n" +
"{\n" +
" mappings: [meta::mySimpleMapping];\n" +
"}\n\n\n" +
"###Service\n" +
"import meta::*;\n" +
// Service with embedded runtime
"Service meta::pure::myServiceMulti\n" +
"{\n" +
" pattern: 'url/myUrl/';\n" +
" owners:[];\n" +
" documentation: 'this is just for context';\n" +
" autoActivateUpdates: true;\n" +
" execution: Multi\n" +
" {\n" +
// Pure multi execution query
" query: src: mySimpleClass[1]|$src.name;\n" +
" key: 'env';\n" +
" executions['QA']:\n" +
" {\n" +
// Pure multi execution mapping
" mapping: mySimpleMapping;\n" +
// Pure multi execution runtime
" runtime: mySimpleRuntime;\n" +
" }\n" +
" }\n" +
" test: Multi\n" +
" {\n" +
" tests['QA']:\n" +
" {\n" +
" data: 'moreData';\n" +
" asserts:\n" +
" [\n" +
// multi service test assertion
" ];\n" +
" }\n" +
" }\n" +
"}\n" +
"\n", null, Lists.fixedSize.with("COMPILATION error at [53:5-59:5]: Multi execution with test id: QAtest has empty asserts"));
}

@Test
public void testServiceWithImport()
{
Expand Down Expand Up @@ -1054,7 +1188,7 @@ public void testServiceWithImport()
" [\n" +
" ];\n" +
" }\n" +
"}\n");
"}\n", null, Lists.fixedSize.with("COMPILATION error at [113:9-119:3]: Single execution test has empty asserts"));
}

@Test
Expand Down

0 comments on commit b731e26

Please sign in to comment.