Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#182 Valid check_min_cppstd #184

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions hooks/conan-center.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"KB-H064": "INVALID TOPICS",
"KB-H065": "NO REQUIRED_CONAN_VERSION",
"KB-H066": "SHORT_PATHS USAGE",
"KB-H067": "VALIDATE CHECK_MIN_CPPSTD",
}


Expand Down Expand Up @@ -442,6 +443,27 @@ def test(out):
"Conanfile should not contain 'self.cpp_info.names['{0}']'. "
" Use 'cmake_find_package' and 'cmake_find_package_multi' instead.".format(generator))

@run_test("KB-H067", output)
def test(out):
def _which_line_is(content, lines):
n = 0
for line in lines:
n += 1
if content in line:
return n
return 0

lines = conanfile_content.splitlines()
check_line = _which_line_is("check_min_cppstd", lines)
if check_line:
if_1_line = _which_line_is('settings.get_safe("compiler.cppstd")', lines)
if_2_line = _which_line_is("settings.get_safe('compiler.cppstd')", lines)
if (not if_1_line and not if_2_line) or \
(if_1_line and if_1_line > check_line) or \
(if_2_line and if_2_line > check_line):
out.error("'tools.check_min_cppstd requires 'if self.settings.get_safe(\"compiler.cppstd\")' first."
" Check if 'cppstd' is configured before 'check_min_cppstd'.")

@run_test("KB-H041", output)
def test(out):
checked_fileexts = ".c", ".cc", ".cpp", ".cxx", ".h", ".hxx", ".hpp", \
Expand Down
24 changes: 24 additions & 0 deletions tests/test_hooks/conan-center/test_conan-center.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,30 @@ def package_info(self):
output = self.conan(['create', '.', 'name/version@user/test'])
self.assertIn("[NO TARGET NAME (KB-H040)] OK", output)

def test_check_min_cppstd(self):
conanfile = textwrap.dedent("""\
from conans import ConanFile, tools
class AConan(ConanFile):
settings = "compiler"
def configure(self):
{0}
{1}
""")
tools.save('conanfile.py', content=conanfile.replace("{0}", 'if self.settings.get_safe("compiler.cppstd"):').replace("{1}", ' tools.check_min_cppstd(self, "11")'))
output = self.conan(['create', '.', 'name/version@user/test'])
self.assertIn("[VALIDATE CHECK_MIN_CPPSTD (KB-H046)] OK", output)

tools.save('conanfile.py', content=conanfile.replace("{0}", 'tools.check_min_cppstd(self, "11")')
.replace("{1}", "if self.settings.get_safe(\"compiler.cppstd\"):\n pass"))
output = self.conan(['create', '.', 'name/version@user/test'])
self.assertIn("ERROR: [VALIDATE CHECK_MIN_CPPSTD (KB-H067)] 'tools.check_min_cppstd requires 'if self.settings.get_safe(\"compiler.cppstd\")' first."
" Check if 'cppstd' is configured before 'check_min_cppstd'.", output)

tools.save('conanfile.py', content=conanfile.replace("{0}", 'tools.check_min_cppstd(self, "11")').replace("{1}", ""))
output = self.conan(['create', '.', 'name/version@user/test'])
self.assertIn("ERROR: [VALIDATE CHECK_MIN_CPPSTD (KB-H067)] 'tools.check_min_cppstd requires 'if self.settings.get_safe(\"compiler.cppstd\")' first."
" Check if 'cppstd' is configured before 'check_min_cppstd'.", output)

def test_cmake_verbose_makefile(self):
conanfile = self.conanfile_base.format(placeholder="exports_sources = \"CMakeLists.txt\"")

Expand Down