doctest

FORK: The fastest feature-rich C++11/14/17/20 single-header testing framework
git clone https://git.neptards.moe/neptards/doctest.git
Log | Files | Refs | README

build_and_test.py (2764B)


      1 import os
      2 import sys
      3 
      4 _os = sys.argv[1]
      5 assert _os in ["Linux", "macOS", "Windows"]
      6 
      7 _arch = sys.argv[2]
      8 assert _arch in ["x86", "x64"]
      9 
     10 _compiler = sys.argv[3]
     11 assert _compiler in ["cl", "clang-cl", "clang", "gcc", "xcode"]
     12 
     13 _version = sys.argv[4] if len(sys.argv) >= 5 else ""
     14 
     15 print("Env: " + "; ".join([_os, _arch, _compiler, _version]))
     16 
     17 if _compiler == "gcc":
     18     used_cxx = "g++"
     19 elif _compiler == "clang" or _compiler == "xcode":
     20     used_cxx = "clang++"
     21 else:
     22     used_cxx = _compiler
     23 
     24 if _os == "Linux":
     25     used_cxx += "-" + _version
     26 
     27 
     28 def log_and_call(command):
     29     print(command)
     30     return os.system(command)
     31 
     32 
     33 def run_test(build_type, test_mode, flags, test = True):
     34     print("Running: " + "; ".join([build_type, test_mode, flags, str(test)]))
     35     if log_and_call("cmake -E remove_directory build"):
     36         exit(1)
     37     if log_and_call(
     38         f"cmake -S . "
     39         f"-B build "
     40         f"-D CMAKE_BUILD_TYPE={build_type} "
     41         f"-D DOCTEST_TEST_MODE={test_mode} "
     42         + (flags and f'-D CMAKE_CXX_FLAGS="{flags}" ') +
     43         f"-D CMAKE_CXX_COMPILER={used_cxx}"
     44     ):
     45         exit(2)
     46     if log_and_call("cmake --build build"):
     47         exit(3)
     48     if test and log_and_call("ctest --test-dir build --no-tests=error"):
     49         exit(4)
     50 
     51 
     52 def version_tuple(v):
     53     return tuple(map(int, (v.split("."))))
     54 
     55 
     56 flags = "-fsanitize=address,undefined -fno-omit-frame-pointer"
     57 if _os == "Windows":
     58     flags = ""
     59 elif _os == "Linux":
     60     if _compiler == "clang":
     61         if version_tuple(_version) <= version_tuple("6.0"):
     62             flags = ""
     63     elif _compiler == "gcc":
     64         if version_tuple(_version) <= version_tuple("5.0"):
     65             flags = ""
     66 
     67 if _os == "Linux" and _compiler == "gcc":
     68     flags += " -static-libasan"
     69 
     70 tsan_flags = "-fsanitize=thread -pie -fPIE"
     71 if _os == "Windows":
     72     tsan_flags = ""
     73 elif _os == "Linux":
     74     if _compiler == "clang":
     75         if version_tuple(_version) <= version_tuple("3.9"):
     76             tsan_flags = ""
     77     elif _compiler == "gcc":
     78         if version_tuple(_version) <= version_tuple("6.0"):
     79             tsan_flags = ""
     80 
     81 if _os == "Linux" and _compiler == "gcc":
     82     tsan_flags += " -static-libtsan"
     83 
     84 x86_flag = " -m32" if _arch == "x86" and _compiler != "cl" else ""
     85 
     86 for configuration in ["Debug", "Release"]:
     87     run_test(configuration, "COMPARE", flags + x86_flag)
     88     if tsan_flags != "":
     89         run_test(configuration, "COMPARE", tsan_flags)
     90     if _os != "Windows":
     91         run_test(
     92             configuration,
     93             "COMPARE",
     94             "-fno-exceptions -D DOCTEST_CONFIG_NO_EXCEPTIONS_BUT_WITH_ALL_ASSERTS",
     95             test = False,
     96         )
     97         run_test(configuration, "COMPARE", "-fno-rtti")
     98     if _os == "Linux":
     99         run_test(configuration, "VALGRIND", x86_flag)