81 lines
2.6 KiB
Python
81 lines
2.6 KiB
Python
import json
|
|
from pathlib import Path
|
|
import sys
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
SCRIPTS = ROOT / "scripts"
|
|
sys.path.insert(0, str(SCRIPTS))
|
|
|
|
from msvc_harness.adapters.cmake import CMakeAdapter
|
|
from msvc_harness.config import load_config
|
|
from msvc_harness.models import ProjectKind, ProjectSelection, Toolchain
|
|
|
|
|
|
PRESET_NAME = "windows-msvc-ninja-debug"
|
|
BINARY_DIR = ".harness/build-ninja-msvc-debug"
|
|
|
|
|
|
def test_harness_uses_tracked_ninja_msvc_presets(tmp_path):
|
|
presets = json.loads((ROOT / "CMakePresets.json").read_text(encoding="utf-8"))
|
|
configure = presets["configurePresets"][0]
|
|
assert configure == {
|
|
"name": PRESET_NAME,
|
|
"displayName": "Windows MSVC x64 Debug (Ninja)",
|
|
"generator": "Ninja",
|
|
"binaryDir": f"${{sourceDir}}/{BINARY_DIR}",
|
|
"cacheVariables": {
|
|
"CMAKE_BUILD_TYPE": "Debug",
|
|
"FESA_GTEST_SOURCE_DIR": "$env{FESA_GTEST_SOURCE_DIR}",
|
|
"MKL_DIR": "$env{MKL_DIR}",
|
|
"TBB_DIR": "$env{TBB_DIR}",
|
|
"HDF5_DIR": "$env{HDF5_DIR}",
|
|
},
|
|
}
|
|
assert presets["buildPresets"] == [
|
|
{"name": PRESET_NAME, "configurePreset": PRESET_NAME}
|
|
]
|
|
assert presets["testPresets"] == [
|
|
{"name": PRESET_NAME, "configurePreset": PRESET_NAME}
|
|
]
|
|
|
|
example = json.loads(
|
|
(ROOT / ".harness" / "config.example.json").read_text(encoding="utf-8")
|
|
)
|
|
assert example == {
|
|
"version": 1,
|
|
"projectType": "cmake",
|
|
"cmake": {
|
|
"sourceDir": ".",
|
|
"binaryDir": BINARY_DIR,
|
|
"configurePreset": PRESET_NAME,
|
|
"buildPreset": PRESET_NAME,
|
|
"testPreset": PRESET_NAME,
|
|
},
|
|
}
|
|
assert ".harness/build-ninja-msvc-debug/" in (
|
|
ROOT / ".gitignore"
|
|
).read_text(encoding="utf-8").splitlines()
|
|
|
|
harness_dir = tmp_path / ".harness"
|
|
harness_dir.mkdir()
|
|
(harness_dir / "config.json").write_text(
|
|
json.dumps(example), encoding="utf-8"
|
|
)
|
|
config = load_config(tmp_path)
|
|
tools = Toolchain(
|
|
installation=tmp_path / "vs",
|
|
msbuild=tmp_path / "msbuild.exe",
|
|
cmake=tmp_path / "cmake.exe",
|
|
ctest=tmp_path / "ctest.exe",
|
|
)
|
|
selection = ProjectSelection(ProjectKind.CMAKE, ROOT / "CMakePresets.json")
|
|
plan = CMakeAdapter().create_plan(tmp_path, selection, config, tools)
|
|
|
|
assert [step.command.argv[1:] for step in plan.steps] == [
|
|
("--preset", PRESET_NAME),
|
|
("--build", "--preset", PRESET_NAME),
|
|
("--preset", PRESET_NAME, "--show-only=json-v1"),
|
|
("--preset", PRESET_NAME, "--output-on-failure"),
|
|
]
|