|
3 | 3 | import os |
4 | 4 | import sys |
5 | 5 | from pathlib import Path |
| 6 | +from textwrap import dedent |
| 7 | +from xml.etree import ElementTree |
6 | 8 |
|
7 | 9 | import pytest |
| 10 | +from conftest import create_project |
8 | 11 |
|
| 12 | +from idf_build_apps.constants import SUPPORTED_TARGETS |
9 | 13 | from idf_build_apps.main import main |
10 | 14 | from idf_build_apps.utils import InvalidCommand |
11 | 15 |
|
@@ -95,3 +99,65 @@ def test_manifest_patterns(tmp_path, monkeypatch, capsys): |
95 | 99 | assert f'Loading manifest file {os.path.join(tmp_path, "manifest.yml")}' in err |
96 | 100 | assert f'"{os.path.join(tmp_path, "foo")}" does not exist' in err |
97 | 101 | assert f'"{os.path.join(tmp_path, "bar")}" does not exist' in err |
| 102 | + |
| 103 | + |
| 104 | +def test_build_include_all_apps(tmp_path, monkeypatch, capsys): |
| 105 | + create_project('foo', tmp_path) |
| 106 | + |
| 107 | + manifest = tmp_path / 'manifest.yml' |
| 108 | + manifest.write_text( |
| 109 | + dedent("""\ |
| 110 | + foo: |
| 111 | + disable: |
| 112 | + - if: IDF_TARGET == "esp32" |
| 113 | + """) |
| 114 | + ) |
| 115 | + |
| 116 | + with monkeypatch.context() as m: |
| 117 | + m.setattr( |
| 118 | + sys, |
| 119 | + 'argv', |
| 120 | + [ |
| 121 | + 'idf-build-apps', |
| 122 | + 'build', |
| 123 | + '--paths', |
| 124 | + 'foo', |
| 125 | + '--manifest-files', |
| 126 | + str(manifest), |
| 127 | + '--check-manifest-rules', |
| 128 | + '--include-all-apps', |
| 129 | + '--junitxml', |
| 130 | + str(tmp_path / 'junit.xml'), |
| 131 | + '--dry-run', |
| 132 | + ], |
| 133 | + ) |
| 134 | + main() |
| 135 | + |
| 136 | + out, err = capsys.readouterr() |
| 137 | + assert err == '' |
| 138 | + assert 'Disabled the following apps' in out |
| 139 | + assert out.count('Disabled by manifest rule: IDF_TARGET == "esp32"') == 1 |
| 140 | + |
| 141 | + with open(str(tmp_path / 'junit.xml')) as f: |
| 142 | + xml = ElementTree.fromstring(f.read()) |
| 143 | + |
| 144 | + test_suite = xml.findall('testsuite')[0] |
| 145 | + assert test_suite.attrib['tests'] == '0' |
| 146 | + assert test_suite.attrib['failures'] == '0' |
| 147 | + assert test_suite.attrib['errors'] == '0' |
| 148 | + assert test_suite.attrib['skipped'] == str(len(SUPPORTED_TARGETS)) |
| 149 | + |
| 150 | + disabled_testcases = 0 |
| 151 | + |
| 152 | + for case in test_suite.findall('testcase'): |
| 153 | + if case.get('name') != 'foo/build': |
| 154 | + continue |
| 155 | + |
| 156 | + skipped = case.find('skipped') |
| 157 | + if skipped is None: |
| 158 | + continue |
| 159 | + |
| 160 | + if skipped.get('message') == 'Disabled by manifest rule: IDF_TARGET == "esp32"': |
| 161 | + disabled_testcases += 1 |
| 162 | + |
| 163 | + assert disabled_testcases == 1 |
0 commit comments