summaryrefslogtreecommitdiffstats
path: root/tools/lint/test/test_manifest_toml.py
blob: f205a1cd1f9df7bfa839c099f3aeadb12ffefc86 (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
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import mozunit

LINTER = "test-manifest-toml"
fixed = 0


def test_valid(lint, paths):
    results = lint(paths("valid.toml"))
    assert len(results) == 0


def test_invalid(lint, paths):
    results = lint(paths("invalid.toml"))
    assert len(results) == 1
    assert results[0].message == "The manifest is not valid TOML."


def test_no_default(lint, paths):
    """Test verifying [DEFAULT] section."""
    results = lint(paths("no-default.toml"))
    assert len(results) == 1
    assert results[0].message == "The manifest does not start with a [DEFAULT] section."


def test_no_default_fix(lint, paths, create_temp_file):
    """Test fixing missing [DEFAULT] section."""
    contents = "# this Manifest has no DEFAULT section\n"
    path = create_temp_file(contents, "no-default.toml")
    results = lint([path], fix=True)
    assert len(results) == 1
    assert results[0].message == "The manifest does not start with a [DEFAULT] section."
    assert fixed == 1


def test_non_double_quote_sections(lint, paths):
    """Test verifying [DEFAULT] section."""
    results = lint(paths("non-double-quote-sections.toml"))
    assert len(results) == 2
    assert results[0].message.startswith("The section name must be double quoted:")


def test_unsorted(lint, paths):
    """Test sections in alpha order."""
    results = lint(paths("unsorted.toml"))
    assert len(results) == 1
    assert results[0].message == "The manifest sections are not in alphabetical order."


def test_comment_section(lint, paths):
    """Test for commented sections."""
    results = lint(paths("comment-section.toml"))
    assert len(results) == 2
    assert results[0].message.startswith(
        "Use 'disabled = \"<reason>\"' to disable a test instead of a comment:"
    )


def test_skip_if_not_array(lint, paths):
    """Test for non-array skip-if value."""
    results = lint(paths("skip-if-not-array.toml"))
    assert len(results) == 1
    assert results[0].message.startswith("Value for conditional must be an array:")


def test_skip_if_explicit_or(lint, paths):
    """Test for explicit || in skip-if."""
    results = lint(paths("skip-if-explicit-or.toml"))
    assert len(results) == 1
    assert results[0].message.startswith(
        "Value for conditional must not include explicit ||, instead put on multiple lines:"
    )


if __name__ == "__main__":
    mozunit.main()