summaryrefslogtreecommitdiff
path: root/tests/frontend/configurable_warnings.py
blob: 7f514cd3b9330bfc1c2f88d92f6e190831f919f1 (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
# Pylint doesn't play well with fixtures and dependency injection from pytest
# pylint: disable=redefined-outer-name

import os

import pytest

from buildstream2.plugin import CoreWarnings
from buildstream2._exceptions import ErrorDomain
from buildstream2 import _yaml
from buildstream2.testing.runcli import cli  # pylint: disable=unused-import

TOP_DIR = os.path.join(
    os.path.dirname(os.path.realpath(__file__)),
    "configuredwarning"
)


def get_project(fatal_warnings):
    return {
        "name": "test",
        "version": "2.0",
        "element-path": "elements",
        "plugins": [
            {
                "origin": "local",
                "path": "plugins",
                "elements": {
                    "warninga": 0,
                    "warningb": 0,
                    "corewarn": 0,
                }
            }
        ],
        "fatal-warnings": fatal_warnings
    }


def build_project(datafiles, fatal_warnings):
    project_path = str(datafiles)

    project = get_project(fatal_warnings)

    _yaml.dump(project, os.path.join(project_path, "project.conf"))

    return project_path


@pytest.mark.datafiles(TOP_DIR)
@pytest.mark.parametrize("element_name, fatal_warnings, expect_fatal, error_domain", [
    ("corewarn.bst", [CoreWarnings.OVERLAPS], True, ErrorDomain.STREAM),
    ("warninga.bst", ["warninga:warning-a"], True, ErrorDomain.STREAM),
    ("warningb.bst", ["warningb:warning-b"], True, ErrorDomain.STREAM),
    ("corewarn.bst", [], False, None),
    ("warninga.bst", [], False, None),
    ("warningb.bst", [], False, None),
    ("warninga.bst", [CoreWarnings.OVERLAPS], False, None),
    ("warningb.bst", [CoreWarnings.OVERLAPS], False, None),
])
def test_fatal_warnings(cli, datafiles, element_name,
                        fatal_warnings, expect_fatal, error_domain):
    project_path = build_project(datafiles, fatal_warnings)

    result = cli.run(project=project_path, args=["build", element_name])
    if expect_fatal:
        result.assert_main_error(error_domain, None, "Expected fatal execution")
    else:
        result.assert_success("Unexpected fatal execution")