Repository: conan-io/conan

Issue:
Update tests to use msvc setting
Instead of Visual Studio

Not necessary to migrate the whole test suite. Just add or update some tests to have better coverage of the new ``msvc`` compiler.

There are already some tests that use it like ``test_locally_build_msvc_toolset()`` or ``test_toolchain_win_vs2017()``. The goal is to check relevant cases, like standard CMake build, and parameterize or add new tests.

Only ``conan.tools`` new integrations


Discussion:

Resolving patch:
diff --git a/conan/tools/_compilers.py b/conan/tools/_compilers.py
--- a/conan/tools/_compilers.py
+++ b/conan/tools/_compilers.py
@@ -62,7 +62,6 @@ def build_type_flags(settings):
     (-s, -g, /Zi, etc.)
     """
     compiler = settings.get_safe("compiler.base") or settings.get_safe("compiler")
-
     build_type = settings.get_safe("build_type")
     vs_toolset = settings.get_safe("compiler.toolset")
     if not compiler or not build_type:
@@ -70,7 +69,7 @@ def build_type_flags(settings):
 
     # https://github.com/Kitware/CMake/blob/d7af8a34b67026feaee558433db3a835d6007e06/
     # Modules/Platform/Windows-MSVC.cmake
-    if str(compiler) == 'Visual Studio':
+    if str(compiler) in ['Visual Studio', 'msvc']:
         if vs_toolset and "clang" in str(vs_toolset):
             flags = {"Debug": ["-gline-tables-only", "-fno-inline", "-O0"],
                      "Release": ["-O2"],


Test patch:
diff --git a/conans/test/unittests/client/settings_preprocessor_test.py b/conans/test/unittests/client/settings_preprocessor_test.py
--- a/conans/test/unittests/client/settings_preprocessor_test.py
+++ b/conans/test/unittests/client/settings_preprocessor_test.py
@@ -2,9 +2,12 @@
 
 import unittest
 
+import pytest
+
 from conans import Settings
 from conans.client.conf import get_default_settings_yml
 from conans.client.settings_preprocessor import preprocess
+from conans.errors import ConanException
 
 
 class SettingsCompilerIntelVisualPreprocessorTest(unittest.TestCase):
@@ -64,3 +67,35 @@ def test_custom_base_runtime_set(self):
         self.settings.compiler.runtime = "MT"
         preprocess(self.settings)
         self.assertEqual(self.settings.compiler.runtime, "MT")
+
+
+class TestSettingsCompilerMSVCPreprocessorTest:
+
+    @pytest.fixture(autouse=True)
+    def setup(self):
+        self.settings = Settings.loads(get_default_settings_yml())
+        self.settings.compiler = "msvc"
+
+    def test_release_build_type_runtime(self):
+        self.settings.build_type = "Release"
+        preprocess(self.settings)
+        assert self.settings.compiler.runtime_type == "Release"
+
+    def test_debug_build_type_runtime(self):
+        self.settings.build_type = "Debug"
+        preprocess(self.settings)
+        assert self.settings.compiler.runtime_type == "Debug"
+
+    def test_different_base_compiler(self):
+        self.settings.compiler = "gcc"
+        self.settings.build_type = "Debug"
+        preprocess(self.settings)
+        assert self.settings.compiler.get_safe("runtime") is None
+
+    def test_custom_base_runtime_set(self):
+        self.settings.build_type = "Debug"
+        with pytest.raises(ConanException) as e:
+            self.settings.compiler.runtime = "MT"
+            preprocess(self.settings)
+        assert "Invalid setting 'MT' is not a valid 'settings.compiler.runtime' value" \
+               in str(e.value)
diff --git a/conans/test/unittests/client/toolchain/autotools/autotools_toolchain_test.py b/conans/test/unittests/client/toolchain/autotools/autotools_toolchain_test.py
--- a/conans/test/unittests/client/toolchain/autotools/autotools_toolchain_test.py
+++ b/conans/test/unittests/client/toolchain/autotools/autotools_toolchain_test.py
@@ -1,4 +1,3 @@
-import platform
 from os import chdir
 
 import pytest
@@ -96,6 +95,17 @@ def test_cppstd():
     env = be.vars()
     assert "/std:c++latest" in env["CXXFLAGS"]
 
+    # With MSVC
+    conanfile.settings = MockSettings(
+        {"build_type": "Release",
+         "arch": "x86",
+         "compiler": "msvc",
+         "compiler.version": "19.3",
+         "compiler.cppstd": "17"})
+    be = AutotoolsToolchain(conanfile)
+    env = be.vars()
+    assert "/std:c++17" in env["CXXFLAGS"]
+
 
 def test_fpic():
     conanfile = ConanFileMock()
@@ -216,13 +226,14 @@ def test_architecture_flag(config):
     assert expected in env["LDFLAGS"]
 
 
-def test_build_type_flag():
+@pytest.mark.parametrize("compiler", ['Visual Studio', 'msvc'])
+def test_build_type_flag(compiler):
     """Architecture flag is set in CXXFLAGS, CFLAGS and LDFLAGS"""
     conanfile = ConanFileMock()
     conanfile.settings = MockSettings(
         {"build_type": "Debug",
          "os": "Windows",
-         "compiler": "Visual Studio",
+         "compiler": compiler,
          "arch": "x86_64"})
     be = AutotoolsToolchain(conanfile)
     assert be.build_type_flags == ["-Zi", "-Ob0", "-Od"]