summaryrefslogtreecommitdiffstats
path: root/Tests/RunCMake/FileAPI/cmakeFiles-v1-check.py
blob: 54ca3949692a4ed03e644f81ba27457c9d908342 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
from check_index import *

def check_objects(o):
    assert is_list(o)
    assert len(o) == 1
    check_index_object(o[0], "cmakeFiles", 1, 1, check_object_cmakeFiles)

def check_input(actual, expected):
    assert is_dict(actual)
    expected_keys = ["path"]

    if expected["isGenerated"] is not None:
        expected_keys.append("isGenerated")
        assert is_bool(actual["isGenerated"], expected["isGenerated"])

    if expected["isExternal"] is not None:
        expected_keys.append("isExternal")
        assert is_bool(actual["isExternal"], expected["isExternal"])

    if expected["isCMake"] is not None:
        expected_keys.append("isCMake")
        assert is_bool(actual["isCMake"], expected["isCMake"])

    assert sorted(actual.keys()) == sorted(expected_keys)

def check_glob_dependent(actual, expected):
    assert is_dict(actual)

    if "followSymlinks" in expected:
        assert is_bool(actual["followSymlinks"], expected["followSymlinks"])

    if "listDirectories" in expected:
        assert is_bool(actual["listDirectories"], expected["listDirectories"])

    if "recurse" in expected:
        assert is_bool(actual["recurse"], expected["recurse"])

    if "relative" in expected:
        assert matches(actual["relative"], expected["relative"])

    check_list_match(lambda a, e: matches(a, e), actual["paths"], expected["paths"], allow_extra=True)

    assert sorted(actual.keys()) == sorted(expected.keys())

def check_object_cmakeFiles(o):
    assert sorted(o.keys()) == ["globsDependent", "inputs", "kind", "paths", "version"]
    # The "kind" and "version" members are handled by check_index_object.
    assert is_dict(o["paths"])
    assert sorted(o["paths"].keys()) == ["build", "source"]
    assert matches(o["paths"]["build"], "^.*/Tests/RunCMake/FileAPI/cmakeFiles-v1-build$")
    assert matches(o["paths"]["source"], "^.*/Tests/RunCMake/FileAPI$")

    expected = [
        {
            "path": "^CMakeLists\\.txt$",
            "isGenerated": None,
            "isExternal": None,
            "isCMake": None,
        },
        {
            "path": "^cmakeFiles-v1\\.cmake$",
            "isGenerated": None,
            "isExternal": None,
            "isCMake": None,
        },
        {
            "path": "^dir/CMakeLists\\.txt$",
            "isGenerated": None,
            "isExternal": None,
            "isCMake": None,
        },
        {
            "path": "^dir/dir/CMakeLists\\.txt$",
            "isGenerated": None,
            "isExternal": None,
            "isCMake": None,
        },
        {
            "path": "^dir/very-long/CMakeLists\\.txt$",
            "isGenerated": None,
            "isExternal": None,
            "isCMake": None,
        },
        {
            "path": "^dir/dirtest\\.cmake$",
            "isGenerated": None,
            "isExternal": None,
            "isCMake": None,
        },
        {
            "path": "^.*/Tests/RunCMake/FileAPIDummyFile\\.cmake$",
            "isGenerated": None,
            "isExternal": True,
            "isCMake": None,
        },
        {
            "path": "^.*/Tests/RunCMake/FileAPI/cmakeFiles-v1-build/generated\\.cmake",
            "isGenerated": True,
            "isExternal": None,
            "isCMake": None,
        },
        {
            "path": "^.*/Modules/CMakeParseArguments\\.cmake$",
            "isGenerated": None,
            "isExternal": True,
            "isCMake": True,
        },
    ]

    expected_globs = [
        {
            "expression": "^.*/Tests/RunCMake/FileAPI/dir/\\*$",
            "paths": [
                "^.*/Tests/RunCMake/FileAPI/dir/dir$",
                "^.*/Tests/RunCMake/FileAPI/dir/dirtest\\.cmake$"
            ],
            "listDirectories": True,
        },
        {
            "expression": "^.*/Tests/RunCMake/FileAPI/dir/\\*\\.cmake$",
            "paths": [
                "^dir/dirtest\\.cmake$"
            ],
            "followSymlinks": True,
            "recurse": True,
            "relative": "^.*/Tests/RunCMake/FileAPI$"
        }
    ]

    inSource = os.path.dirname(o["paths"]["build"]) == o["paths"]["source"]
    if inSource:
        for e in expected:
            e["path"] = e["path"].replace("^.*/Tests/RunCMake/FileAPI/", "^", 1)

    check_list_match(lambda a, e: matches(a["path"], e["path"]), o["inputs"], expected, check=check_input, allow_extra=True)
    check_list_match(lambda a, e: matches(a["expression"], e["expression"]), o["globsDependent"], expected_globs, check=check_glob_dependent, allow_extra=True)

assert is_dict(index)
assert sorted(index.keys()) == ["cmake", "objects", "reply"]
check_objects(index["objects"])