11# -*- coding: utf-8 -*-
2+ import os
3+ import subprocess
4+ import sysconfig
25import textwrap
36
47import pytest
8+ from importlib_metadata import distribution
59
610import cmake
711
812from . import push_argv
913
14+ all_tools = pytest .mark .parametrize ("tool" , ["cmake" , "cpack" , "ctest" ])
15+
1016
1117def _run (program , args ):
1218 func = getattr (cmake , program )
@@ -16,10 +22,9 @@ def _run(program, args):
1622 assert excinfo .value .code == 0
1723
1824
19- def test_cmake_module ():
20- _run ("cmake" , ["--version" ])
21- _run ("cpack" , ["--version" ])
22- _run ("ctest" , ["--version" ])
25+ @all_tools
26+ def test_cmake_module (tool ):
27+ _run (tool , ["--version" ])
2328
2429
2530def test_cmake_https (tmpdir ):
@@ -43,3 +48,22 @@ def test_cmake_https(tmpdir):
4348 ))
4449
4550 _run ("cmake" , ["-DTMP_DIR:PATH=%s" % str (tmpdir ), "-P" , str (test_script )])
51+
52+
53+ def _get_scripts ():
54+ dist = distribution ("cmake" )
55+ scripts_paths = [os .path .abspath (sysconfig .get_path ("scripts" , scheme )) for scheme in sysconfig .get_scheme_names ()]
56+ scripts = []
57+ for file in dist .files :
58+ if os .path .abspath (str (file .locate ().parent )) in scripts_paths :
59+ scripts .append (file .locate ().resolve (strict = True ))
60+ return scripts
61+
62+
63+ @all_tools
64+ def test_cmake_script (tool ):
65+ expected_version = "3.27.7"
66+ scripts = [script for script in _get_scripts () if script .stem == tool ]
67+ assert len (scripts ) == 1
68+ output = subprocess .check_output ([str (scripts [0 ]), "--version" ]).decode ("ascii" )
69+ assert output .splitlines ()[0 ] == "{} version {}" .format (tool , expected_version )
0 commit comments