commit 55bf254999edd1373d1df15a55b07776e4125af0
parent 740808ddd8a46d2da91d45eae2136bef4528377d
Author: yao-msft <50888816+yao-msft@users.noreply.github.com>
Date: Mon, 9 May 2022 16:59:27 -0700
Loc error as warning (#2144)
Diffstat:
3 files changed, 29 insertions(+), 5 deletions(-)
diff --git a/src/AppInstallerCLITests/YamlManifest.cpp b/src/AppInstallerCLITests/YamlManifest.cpp
@@ -818,4 +818,22 @@ TEST_CASE("ManifestApplyLocale", "[ManifestValidation]")
REQUIRE(manifest.CurrentLocalization.Locale == "fr-FR");
REQUIRE(manifest.CurrentLocalization.Get<Localization::PackageName>() == "fr-FR package name");
REQUIRE(manifest.CurrentLocalization.Get<Localization::Publisher>() == "es-MX publisher");
+}
+
+TEST_CASE("ManifestLocalizationValidation", "[ManifestValidation]")
+{
+ Manifest manifest = YamlParser::CreateFromPath(TestDataFile("Manifest-Good-MultiLocale.yaml"));
+
+ // Set 1 locale to bad value
+ manifest.Localizations.at(0).Locale = "Invalid";
+
+ // Full validation should detect as error
+ auto errors = ValidateManifest(manifest, true);
+ REQUIRE(errors.size() == 1);
+ REQUIRE(errors.at(0).ErrorLevel == ValidationError::Level::Error);
+
+ // Not full validation should detect as warning
+ errors = ValidateManifest(manifest, false);
+ REQUIRE(errors.size() == 1);
+ REQUIRE(errors.at(0).ErrorLevel == ValidationError::Level::Warning);
}
\ No newline at end of file
diff --git a/src/AppInstallerCommonCore/Manifest/ManifestValidation.cpp b/src/AppInstallerCommonCore/Manifest/ManifestValidation.cpp
@@ -203,20 +203,20 @@ namespace AppInstaller::Manifest
// Validate localizations
for (auto const& localization : manifest.Localizations)
{
- auto locErrors = ValidateManifestLocalization(localization);
+ auto locErrors = ValidateManifestLocalization(localization, !fullValidation);
std::move(locErrors.begin(), locErrors.end(), std::inserter(resultErrors, resultErrors.end()));
}
return resultErrors;
}
- std::vector<ValidationError> ValidateManifestLocalization(const ManifestLocalization& localization)
+ std::vector<ValidationError> ValidateManifestLocalization(const ManifestLocalization& localization, bool treatErrorAsWarning)
{
std::vector<ValidationError> resultErrors;
if (!localization.Locale.empty() && !Locale::IsWellFormedBcp47Tag(localization.Locale))
{
- resultErrors.emplace_back(ManifestError::InvalidBcp47Value, "PackageLocale", localization.Locale);
+ resultErrors.emplace_back(ManifestError::InvalidBcp47Value, "PackageLocale", localization.Locale, treatErrorAsWarning ? ValidationError::Level::Warning : ValidationError::Level::Error);
}
if (localization.Contains(Localization::Agreements))
@@ -227,7 +227,7 @@ namespace AppInstaller::Manifest
// At least one must be present
if (agreement.Label.empty() && agreement.AgreementText.empty() && agreement.AgreementUrl.empty())
{
- resultErrors.emplace_back(ManifestError::InvalidFieldValue, "Agreements");
+ resultErrors.emplace_back(ManifestError::InvalidFieldValue, "Agreements", treatErrorAsWarning ? ValidationError::Level::Warning : ValidationError::Level::Error);
}
}
}
diff --git a/src/AppInstallerCommonCore/Public/winget/ManifestValidation.h b/src/AppInstallerCommonCore/Public/winget/ManifestValidation.h
@@ -79,12 +79,18 @@ namespace AppInstaller::Manifest
ValidationError(std::string message, std::string field) :
Message(std::move(message)), Field(std::move(field)) {}
+ ValidationError(std::string message, std::string field, Level level) :
+ Message(std::move(message)), Field(std::move(field)), ErrorLevel(level) {}
+
ValidationError(std::string message, std::string field, std::string_view value) :
Message(std::move(message)), Field(std::move(field)), Value(value) {}
ValidationError(std::string message, std::string field, std::string value) :
Message(std::move(message)), Field(std::move(field)), Value(std::move(value)) {}
+ ValidationError(std::string message, std::string field, std::string value, Level level) :
+ Message(std::move(message)), Field(std::move(field)), Value(std::move(value)), ErrorLevel(level) {}
+
ValidationError(std::string message, std::string field, std::string value, size_t line, size_t column) :
Message(std::move(message)), Field(std::move(field)), Value(std::move(value)), Line(line), Column(column) {}
@@ -207,5 +213,5 @@ namespace AppInstaller::Manifest
// fullValidation: bool to set if manifest validation should perform extra validation that is not required for reading a manifest.
std::vector<ValidationError> ValidateManifest(const Manifest& manifest, bool fullValidation = true);
- std::vector<ValidationError> ValidateManifestLocalization(const ManifestLocalization& localization);
+ std::vector<ValidationError> ValidateManifestLocalization(const ManifestLocalization& localization, bool treatErrorAsWarning = false);
}
\ No newline at end of file