-
Notifications
You must be signed in to change notification settings - Fork 994
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ConanInvalidConfiguration exception and handle error codes. (#3517)
* add exception * test for command line * move exit codes to global scope
- Loading branch information
Showing
3 changed files
with
95 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
|
||
import unittest | ||
|
||
from conans.test.utils.tools import TestClient | ||
from conans.client.command import ERROR_INVALID_CONFIGURATION | ||
|
||
|
||
class InvalidConfigurationTest(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self.client = TestClient() | ||
self.client.save({"conanfile.py": """ | ||
from conans import ConanFile | ||
from conans.errors import ConanInvalidConfiguration | ||
class MyPkg(ConanFile): | ||
settings = "os", "compiler", "build_type", "arch" | ||
def configure(self): | ||
if self.settings.compiler.version == "12": | ||
raise ConanInvalidConfiguration("user says that compiler.version=12 is invalid") | ||
"""}) | ||
settings = "-s os=Windows -s compiler='Visual Studio' -s compiler.version={ver}" | ||
self.settings_msvc15 = settings.format(ver="15") | ||
self.settings_msvc12 = settings.format(ver="12") | ||
|
||
def test_install_method(self): | ||
self.client.run("install . %s" % self.settings_msvc15) | ||
|
||
error = self.client.run("install . %s" % self.settings_msvc12, ignore_error=True) | ||
self.assertEqual(error, ERROR_INVALID_CONFIGURATION) | ||
self.assertIn("Invalid configuration: user says that compiler.version=12 is invalid", | ||
self.client.out) | ||
|
||
def test_create_method(self): | ||
self.client.run("create . name/ver@jgsogo/test %s" % self.settings_msvc15) | ||
|
||
error = self.client.run("create . name/ver@jgsogo/test %s" % self.settings_msvc12, | ||
ignore_error=True) | ||
self.assertEqual(error, ERROR_INVALID_CONFIGURATION) | ||
self.assertIn("name/ver@jgsogo/test: Invalid configuration: user says that " | ||
"compiler.version=12 is invalid", self.client.out) | ||
|
||
def test_as_requirement(self): | ||
self.client.run("create . name/ver@jgsogo/test %s" % self.settings_msvc15) | ||
self.client.save({"other/conanfile.py": """ | ||
from conans import ConanFile | ||
from conans.errors import ConanInvalidConfiguration | ||
class MyPkg(ConanFile): | ||
requires = "name/ver@jgsogo/test" | ||
settings = "os", "compiler", "build_type", "arch" | ||
"""}) | ||
self.client.run("create other/ other/ver@jgsogo/test %s" % self.settings_msvc15) | ||
|
||
error = self.client.run("create other/ other/ver@jgsogo/test %s" % self.settings_msvc12, | ||
ignore_error=True) | ||
self.assertEqual(error, ERROR_INVALID_CONFIGURATION) | ||
self.assertIn("name/ver@jgsogo/test: Invalid configuration: user says that " | ||
"compiler.version=12 is invalid", self.client.out) |