Skip to content

Commit 04a9258

Browse files
authored
Feat(kclvm-windows): Add konfig test for windows. (#414)
* Fix(kclvm-windows): rm all the '\\?\' path prefix in windows. issue #379. * Feat(kclvm-windows): add konfig test for kclvm-windows. issue #379. * add windows ci * fix typo
1 parent f6f1aa3 commit 04a9258

File tree

8 files changed

+140
-4
lines changed

8 files changed

+140
-4
lines changed

.github/workflows/windows_test.yaml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,23 @@ jobs:
2626

2727
- run: echo "C:/LLVM/bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
2828

29-
- run: .\build_and_test_win.bat
29+
# Build kclvm-cli
30+
- run: .\scripts\build-windows\build.bat
31+
32+
# Set kclvm-cli path
33+
- run: echo ";$(pwd)\scripts\build-windows\_output\kclvm-windows\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
34+
working-directory: .
35+
36+
# Rust unit test
37+
- run: cargo test -p kclvm-*
38+
working-directory: ./kclvm
39+
40+
# Rust runtime test
41+
- run: python3 -m pip install --upgrade pip && python3 -m pip install pytest && kclvm -m pytest -vv
42+
working-directory: ./kclvm/tests/test_units
43+
44+
# Rust konfig test
45+
- run: .\test\integration\test_konfig.bat
3046
working-directory: .
3147

3248
- uses: actions/upload-artifact@v3

.gitmodules

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[submodule "plugins"]
22
path = plugins
33
url = https://github.com/KusionStack/kcl-plugin
4-
[submodule "test/konfig"]
5-
path = test/konfig
4+
[submodule "test/integration/konfig"]
5+
path = test/integration/konfig
66
url = https://github.com/KusionStack/konfig.git

build_and_test_win.bat

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@ cd %~dp0
1313
@REM rust runtime test
1414
cd .\\kclvm\\tests\\test_units
1515
kclvm -m pytest -vv
16+
cd %~dp0
17+
18+
@REM konfig test
19+
call .\\test\\integration\\test_konfig.bat

kclvm/runner/src/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ fn multi_file_test_cases() -> Vec<String> {
8080
.join("..")
8181
.join("..")
8282
.join("test")
83+
.join("integration")
8384
.join("konfig")
8485
.join("base")
8586
.join("examples")

test/integration/konfig

Submodule konfig added at 1eabe5f

test/integration/test_konfig.bat

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
cd %~dp0
2+
3+
python3 -m pip install --upgrade pip
4+
python3 -m pip install pytest pytest-xdist
5+
python3 -m pytest -vv -n 10

test/integration/test_konfig_kcl.py

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
"""
2+
this testing framework is developed based on pytest.
3+
see quick start of pytest: https://docs.pytest.org/en/latest/example/simple.html
4+
5+
"""
6+
import os
7+
import subprocess
8+
from pathlib import Path
9+
10+
import pytest
11+
from ruamel.yaml import YAML
12+
from collections.abc import Mapping, Sequence
13+
14+
TEST_FILE = "kcl.yaml"
15+
CI_TEST_DIR = "ci-test"
16+
STDOUT_GOLDEN = "stdout.golden.yaml"
17+
SETTINGS_FILE = "settings.yaml"
18+
19+
ROOT_STR = "konfig"
20+
ROOT = str(Path(__file__).parent.joinpath(ROOT_STR))
21+
22+
yaml = YAML(typ="unsafe", pure=True)
23+
24+
25+
def find_test_dirs():
26+
result = []
27+
root_dirs = [ROOT]
28+
for root_dir in root_dirs:
29+
for root, _, files in os.walk(root_dir):
30+
for name in files:
31+
if name == TEST_FILE:
32+
result.append(root)
33+
return result
34+
35+
36+
def compare_results(result, golden_result):
37+
# Convert result and golden_result string to string lines with line ending stripped, then compare.
38+
39+
assert compare_unordered_yaml_objects(list(yaml.load_all(result)), list(yaml.load_all(golden_result)))
40+
41+
# Comparing the contents of two YAML objects for equality in an unordered manner
42+
def compare_unordered_yaml_objects(result, golden_result):
43+
if isinstance(result, Mapping) and isinstance(golden_result, Mapping):
44+
if result.keys() != golden_result.keys():
45+
return False
46+
for key in result.keys():
47+
if not compare_unordered_yaml_objects(result[key], golden_result[key]):
48+
return False
49+
50+
return True
51+
elif isinstance(result, Sequence) and isinstance(golden_result, Sequence):
52+
if len(result) != len(golden_result):
53+
return False
54+
for item in result:
55+
if item not in golden_result:
56+
return False
57+
for item in golden_result:
58+
if item not in result:
59+
return False
60+
return True
61+
else:
62+
return result == golden_result
63+
64+
def has_settings_file(directory):
65+
settings_file = directory / SETTINGS_FILE
66+
return settings_file.is_file()
67+
68+
69+
print("##### K Language Grammar Test Suite #####")
70+
test_dirs = find_test_dirs()
71+
pwd = str(Path(__file__).parent.parent.parent)
72+
os.environ["PYTHONPATH"] = pwd
73+
74+
75+
@pytest.mark.parametrize("test_dir", test_dirs)
76+
def test_konfigs(test_dir):
77+
print(f"Testing {test_dir}")
78+
test_dir = Path(test_dir)
79+
kcl_file_name = test_dir / TEST_FILE
80+
ci_test_dir = test_dir / CI_TEST_DIR
81+
if not ci_test_dir.is_dir():
82+
# Skip invalid test cases
83+
return
84+
golden_file = ci_test_dir / STDOUT_GOLDEN
85+
if not golden_file.is_file():
86+
# Skip invalid test cases
87+
return
88+
kcl_command = ["kcl"]
89+
if has_settings_file(ci_test_dir):
90+
kcl_command.append("-Y")
91+
kcl_command.append(f"{CI_TEST_DIR}/{SETTINGS_FILE}")
92+
kcl_command.append(f"kcl.yaml")
93+
else:
94+
kcl_command.append(f"{TEST_FILE}")
95+
kcl_command.append("--target")
96+
kcl_command.append("native")
97+
process = subprocess.run(
98+
kcl_command, capture_output=True, cwd=test_dir, env=dict(os.environ)
99+
)
100+
stdout, stderr = process.stdout, process.stderr
101+
print(f"STDOUT:\n{stdout.decode()}")
102+
assert (
103+
process.returncode == 0 and len(stderr) == 0
104+
), f"Error executing file {kcl_file_name}.\nexit code = {process.returncode}\nstderr = {stderr}"
105+
if process.returncode == 0 and len(stderr) == 0:
106+
try:
107+
with open(golden_file, "r") as golden:
108+
compare_results(stdout.decode(), golden)
109+
except FileNotFoundError:
110+
raise Exception(f"Error reading expected result from file {golden_file}")

test/konfig

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)