From 548535390fcc07b4b4c75a30b7962d530cf4acdc Mon Sep 17 00:00:00 2001 From: Sourabh Mehta <73165318+soumeh01@users.noreply.github.com> Date: Wed, 14 Jan 2026 13:42:19 +0100 Subject: [PATCH] Hover info on Setup node and correct error type (#1385) --- tools/projmgr/schemas/common.schema.json | 6 +- .../src/ProjMgrSchemaCheckerUnitTests.cpp | 131 +++++++++++++++++- 2 files changed, 133 insertions(+), 4 deletions(-) diff --git a/tools/projmgr/schemas/common.schema.json b/tools/projmgr/schemas/common.schema.json index d1a629e50..2d4f5162e 100644 --- a/tools/projmgr/schemas/common.schema.json +++ b/tools/projmgr/schemas/common.schema.json @@ -1745,7 +1745,7 @@ "SetupType": { "type": "object", "properties": { - "setup": { + "setup": { "title": "setup:\nDocumentation: https://open-cmsis-pack.github.io/cmsis-toolbox/YML-Input-Format/#setups", "type": "string", "description": "Description of the setup." @@ -1773,7 +1773,7 @@ "undefine": { "$ref": "#/definitions/UndefinesType" }, "warnings": { "$ref": "#/definitions/WarningsType" } }, - "oneOf": [ + "allOf": [ { "$ref": "#/definitions/TypeListMutualExclusion" } ], "additionalProperties": false @@ -1851,7 +1851,7 @@ "not-for-context": { "$ref": "#/definitions/NotForContext" }, "for-compiler": { "$ref": "#/definitions/CompilersType" } }, - "oneOf": [ + "allOf": [ { "$ref": "#/definitions/TypeListMutualExclusion" } ], "additionalProperties": false diff --git a/tools/projmgr/test/src/ProjMgrSchemaCheckerUnitTests.cpp b/tools/projmgr/test/src/ProjMgrSchemaCheckerUnitTests.cpp index 556fd2eb0..c50d68e14 100644 --- a/tools/projmgr/test/src/ProjMgrSchemaCheckerUnitTests.cpp +++ b/tools/projmgr/test/src/ProjMgrSchemaCheckerUnitTests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021 Arm Limited. All rights reserved. + * Copyright (c) 2020-2026 Arm Limited. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 */ @@ -408,6 +408,135 @@ vector expectedErrPos = { } } +TEST_F(ProjMgrSchemaCheckerUnitTests, SchemaCheck_Setup_Linker) { + typedef std::pair ErrInfo; + + // only for-context + const char* valid_setup_schema_Ex1 = "\ +project:\n\ + setups:\n\ + - setup: debug Setup\n\ + for-context: +Debug\n\ + define:\n\ + - TEST: 1\n\ +"; + + //only not-for-context + const char* valid_setup_schema_Ex2 = "\ +project:\n\ + setups:\n\ + - setup: Release Setup\n\ + not-for-context: +Release\n\ + optimize: speed\n\ +"; + + // neither for-context not not-for-context present + const char* valid_setup_schema_Ex3 = "\ +project:\n\ + setups:\n\ + - setup: test\n\ + misc:\n\ + - Link:\n\ + - --verbose\n\ +"; + + // both for-context and not-for-context + const char* invalid_setup_schema_Ex1 = "\ +project:\n\ + setups:\n\ + - setup: test\n\ + for-context: +Debug\n\ + not-for-context: +Release\n\ +"; + + // No setup string + const char* invalid_setup_schema_Ex2 = "\ +project:\n\ + setups:\n\ + - setup:\n\ + for-context: +Debug\n\ +"; + + const char* valid_linker_schema_Ex1 = "\ +project:\n\ + linker:\n\ + - script: MyLinker.scf.src\n\ + for-context: +Debug\n\ +"; + + const char* valid_linker_schema_Ex2 = "\ +project:\n\ + linker:\n\ + - script: MyLinker.scf.src\n\ + not-for-context: +Debug\n\ +"; + + const char* valid_linker_schema_Ex3 = "\ +project:\n\ + linker:\n\ + - script: MyLinker.scf.src\n\ + for-compiler: AC6\n\ + - script: MyLinker.ld\n\ + for-compiler: CLANG\n\ +"; + + const char* invalid_linker_schema_Ex1 = "\ +project:\n\ + linker:\n\ + - script: MyLinker.scf.src\n\ + for-context: +Debug\n\ + not-for-context: +Release\n\ +"; + + const char* invalid_linker_schema_Ex2 = "\ +project:\n\ + linker:\n\ + - script: MyLinker.scf.src\n\ + for-context: +Debug\n\ + invalid: 1\n\ +"; + + vector>> vecTestData = { + // data, expectedRetVal, errorPos + { valid_setup_schema_Ex1, true, vector{ } }, + { valid_setup_schema_Ex2, true, vector{ } }, + { valid_setup_schema_Ex3, true, vector{ } }, + { invalid_setup_schema_Ex1, false, vector{ {3,7} } }, + { invalid_setup_schema_Ex2, false, vector{ {3,7} } }, + { valid_linker_schema_Ex1, true, vector{ } }, + { valid_linker_schema_Ex2, true, vector{ } }, + { valid_linker_schema_Ex3, true, vector{ } }, + { invalid_linker_schema_Ex1, false, vector{ {3,7} } }, + { invalid_linker_schema_Ex2, false, vector{ {5,7} } } + }; + + auto writeFile = [](const string& filePath, const char* data) { + ofstream fileStream(filePath); + fileStream << data; + fileStream << endl; + fileStream << flush; + fileStream.close(); + }; + + const string& filename = testoutput_folder + + "/test_schema_validation.cproject.yml"; + for (auto [data, expectRetVal, errorPos] : vecTestData) { + writeFile(filename, data); + EXPECT_EQ(expectRetVal, Validate(filename)) << "failed for: " << data; + + // Check errors + auto errList = GetErrors(); + EXPECT_EQ(errList.size(), expectRetVal ? 0 : errorPos.size()) << "failed for: " << data; + for (auto& err : errList) { + auto errItr = find_if(errorPos.begin(), errorPos.end(), + [&](const std::pair& errPos) { + return err.m_line == errPos.first && err.m_col == errPos.second; + }); + EXPECT_TRUE(errorPos.end() != errItr) << "failed for: " << data; + } + } +} + TEST_F(ProjMgrSchemaCheckerUnitTests, SchemaCheck_define) { vector> expectedErrPos = { // line, col