update agent, skill and scripts
This commit is contained in:
@@ -1,16 +1,9 @@
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from string import Formatter
|
||||
from typing import Any
|
||||
|
||||
from .models import CMakeConfig, HarnessConfig, MSBuildConfig, TDDConfig
|
||||
|
||||
DEFAULT_TEST_PATTERNS = (
|
||||
"{stem}_test.cpp",
|
||||
"{stem}_tests.cpp",
|
||||
"test_{stem}.cpp",
|
||||
"{stem}.test.cpp",
|
||||
)
|
||||
from .models import CMakeConfig, HarnessConfig, MSBuildConfig
|
||||
|
||||
|
||||
class ConfigError(ValueError):
|
||||
@@ -60,38 +53,6 @@ def _string_array(value: Any, label: str) -> tuple[str, ...]:
|
||||
)
|
||||
|
||||
|
||||
def _validate_test_pattern(pattern: str) -> None:
|
||||
candidate = Path(pattern)
|
||||
if (
|
||||
candidate.is_absolute()
|
||||
or bool(candidate.drive)
|
||||
or "/" in pattern
|
||||
or "\\" in pattern
|
||||
or candidate.name != pattern
|
||||
):
|
||||
raise ConfigError(
|
||||
"every tdd.testPatterns entry must be a safe basename pattern"
|
||||
)
|
||||
try:
|
||||
fields = [
|
||||
(field_name, format_spec, conversion)
|
||||
for _, field_name, format_spec, conversion in Formatter().parse(pattern)
|
||||
if field_name is not None
|
||||
]
|
||||
except ValueError as exc:
|
||||
raise ConfigError(f"invalid tdd.testPatterns entry: {exc}") from exc
|
||||
if (
|
||||
not fields
|
||||
or any(
|
||||
field_name != "stem" or format_spec or conversion
|
||||
for field_name, format_spec, conversion in fields
|
||||
)
|
||||
):
|
||||
raise ConfigError(
|
||||
"every tdd.testPatterns entry may contain only the {stem} field"
|
||||
)
|
||||
|
||||
|
||||
def load_config(root: Path) -> HarnessConfig:
|
||||
root = root.resolve()
|
||||
config_path = root / ".harness" / "config.json"
|
||||
@@ -166,21 +127,12 @@ def load_config(root: Path) -> HarnessConfig:
|
||||
else None
|
||||
)
|
||||
|
||||
tdd_data = _mapping(data.get("tdd", {}), "tdd")
|
||||
_reject_unknown(tdd_data, {"testRoots", "testPatterns", "exclude"}, "tdd")
|
||||
raw_test_roots = _string_array(tdd_data["testRoots"], "tdd.testRoots") if "testRoots" in tdd_data else ("tests", "test")
|
||||
test_roots = tuple(_repo_path(root, item, "tdd.testRoots") for item in raw_test_roots)
|
||||
test_patterns = _string_array(tdd_data["testPatterns"], "tdd.testPatterns") if "testPatterns" in tdd_data else DEFAULT_TEST_PATTERNS
|
||||
for pattern in test_patterns:
|
||||
_validate_test_pattern(pattern)
|
||||
exclude = _string_array(tdd_data["exclude"], "tdd.exclude") if "exclude" in tdd_data else ()
|
||||
for item in exclude:
|
||||
_repo_path(root, item, "tdd.exclude")
|
||||
if "tdd" in data:
|
||||
print("Deprecated config field 'tdd' is ignored; it may be removed.", file=sys.stderr)
|
||||
|
||||
return HarnessConfig(
|
||||
version=1,
|
||||
project_type=project_type,
|
||||
cmake=CMakeConfig(source_dir, binary_dir, configure_preset, build_preset, test_preset),
|
||||
msbuild=MSBuildConfig(solution, configuration, platform, test_command),
|
||||
tdd=TDDConfig(test_roots, test_patterns, exclude),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user