1test_env = environment() 2test_env.set('PYTHONPATH', meson.source_root() / 'scripts') 3test_env.set('PYTHONIOENCODING', 'utf-8') 4 5schemas = [ 6 'alternate-any.json', 7 'alternate-array.json', 8 'alternate-base.json', 9 'alternate-branch-if-invalid.json', 10 'alternate-clash.json', 11 'alternate-conflict-dict.json', 12 'alternate-conflict-enum-bool.json', 13 'alternate-conflict-enum-int.json', 14 'alternate-conflict-string.json', 15 'alternate-conflict-bool-string.json', 16 'alternate-conflict-num-string.json', 17 'alternate-empty.json', 18 'alternate-invalid-dict.json', 19 'alternate-nested.json', 20 'alternate-unknown.json', 21 'args-alternate.json', 22 'args-any.json', 23 'args-array-empty.json', 24 'args-array-unknown.json', 25 'args-bad-boxed.json', 26 'args-boxed-anon.json', 27 'args-boxed-string.json', 28 'args-int.json', 29 'args-invalid.json', 30 'args-member-array-bad.json', 31 'args-member-case.json', 32 'args-member-unknown.json', 33 'args-name-clash.json', 34 'args-union.json', 35 'args-unknown.json', 36 'bad-base.json', 37 'bad-data.json', 38 'bad-ident.json', 39 'bad-if.json', 40 'bad-if-empty.json', 41 'bad-if-empty-list.json', 42 'bad-if-list.json', 43 'bad-type-bool.json', 44 'bad-type-dict.json', 45 'bad-type-int.json', 46 'base-cycle-direct.json', 47 'base-cycle-indirect.json', 48 'command-int.json', 49 'comments.json', 50 'doc-bad-alternate-member.json', 51 'doc-bad-boxed-command-arg.json', 52 'doc-bad-command-arg.json', 53 'doc-bad-enum-member.json', 54 'doc-bad-event-arg.json', 55 'doc-bad-feature.json', 56 'doc-bad-indent.json', 57 'doc-bad-section.json', 58 'doc-bad-symbol.json', 59 'doc-bad-union-member.json', 60 'doc-before-include.json', 61 'doc-before-pragma.json', 62 'doc-duplicated-arg.json', 63 'doc-duplicated-return.json', 64 'doc-duplicated-since.json', 65 'doc-empty-arg.json', 66 'doc-empty-section.json', 67 'doc-empty-symbol.json', 68 'doc-good.json', 69 'doc-interleaved-section.json', 70 'doc-invalid-end.json', 71 'doc-invalid-end2.json', 72 'doc-invalid-return.json', 73 'doc-invalid-section.json', 74 'doc-invalid-start.json', 75 'doc-missing-colon.json', 76 'doc-missing-expr.json', 77 'doc-missing-space.json', 78 'doc-missing.json', 79 'doc-no-symbol.json', 80 'doc-undoc-feature.json', 81 'double-type.json', 82 'duplicate-key.json', 83 'empty.json', 84 'enum-bad-member.json', 85 'enum-bad-name.json', 86 'enum-bad-prefix.json', 87 'enum-clash-member.json', 88 'enum-dict-member-unknown.json', 89 'enum-if-invalid.json', 90 'enum-int-member.json', 91 'enum-member-case.json', 92 'enum-missing-data.json', 93 'enum-wrong-data.json', 94 'event-boxed-empty.json', 95 'event-case.json', 96 'event-member-invalid-dict.json', 97 'event-nest-struct.json', 98 'features-bad-type.json', 99 'features-deprecated-type.json', 100 'features-duplicate-name.json', 101 'features-if-invalid.json', 102 'features-missing-name.json', 103 'features-name-bad-type.json', 104 'features-no-list.json', 105 'features-unknown-key.json', 106 'flat-union-array-branch.json', 107 'flat-union-bad-base.json', 108 'flat-union-bad-discriminator.json', 109 'flat-union-base-any.json', 110 'flat-union-base-union.json', 111 'flat-union-clash-member.json', 112 'flat-union-discriminator-bad-name.json', 113 'flat-union-empty.json', 114 'flat-union-inline.json', 115 'flat-union-inline-invalid-dict.json', 116 'flat-union-int-branch.json', 117 'flat-union-invalid-branch-key.json', 118 'flat-union-invalid-discriminator.json', 119 'flat-union-invalid-if-discriminator.json', 120 'flat-union-no-base.json', 121 'flat-union-optional-discriminator.json', 122 'flat-union-string-discriminator.json', 123 'funny-char.json', 124 'funny-word.json', 125 'ident-with-escape.json', 126 'include-before-err.json', 127 'include-cycle.json', 128 'include-extra-junk.json', 129 'include-nested-err.json', 130 'include-no-file.json', 131 'include-non-file.json', 132 'include-repetition.json', 133 'include-self-cycle.json', 134 'include-simple.json', 135 'indented-expr.json', 136 'leading-comma-list.json', 137 'leading-comma-object.json', 138 'missing-colon.json', 139 'missing-comma-list.json', 140 'missing-comma-object.json', 141 'missing-type.json', 142 'nested-struct-data.json', 143 'nested-struct-data-invalid-dict.json', 144 'non-objects.json', 145 'oob-test.json', 146 'allow-preconfig-test.json', 147 'pragma-doc-required-crap.json', 148 'pragma-extra-junk.json', 149 'pragma-name-case-whitelist-crap.json', 150 'pragma-non-dict.json', 151 'pragma-unknown.json', 152 'pragma-returns-whitelist-crap.json', 153 'qapi-schema-test.json', 154 'quoted-structural-chars.json', 155 'redefined-builtin.json', 156 'redefined-command.json', 157 'redefined-event.json', 158 'redefined-type.json', 159 'reserved-command-q.json', 160 'reserved-enum-q.json', 161 'reserved-member-has.json', 162 'reserved-member-q.json', 163 'reserved-member-u.json', 164 'reserved-member-underscore.json', 165 'reserved-type-kind.json', 166 'reserved-type-list.json', 167 'returns-alternate.json', 168 'returns-array-bad.json', 169 'returns-dict.json', 170 'returns-unknown.json', 171 'returns-whitelist.json', 172 'string-code-point-31.json', 173 'string-code-point-127.json', 174 'struct-base-clash-deep.json', 175 'struct-base-clash.json', 176 'struct-data-invalid.json', 177 'struct-member-if-invalid.json', 178 'struct-member-invalid-dict.json', 179 'struct-member-invalid.json', 180 'trailing-comma-list.json', 181 'trailing-comma-object.json', 182 'type-bypass-bad-gen.json', 183 'unclosed-list.json', 184 'unclosed-object.json', 185 'unclosed-string.json', 186 'union-base-empty.json', 187 'union-base-no-discriminator.json', 188 'union-branch-case.json', 189 'union-branch-if-invalid.json', 190 'union-branch-invalid-dict.json', 191 'union-clash-branches.json', 192 'union-empty.json', 193 'union-invalid-base.json', 194 'union-optional-branch.json', 195 'union-unknown.json', 196 'unknown-escape.json', 197 'unknown-expr-key.json', 198] 199 200# Because people may want to use test-qapi.py from the command line, we 201# are not using the "#! /usr/bin/env python3" trick here. See 202# docs/devel/build-system.txt 203test('QAPI schema regression tests', python, args: files('test-qapi.py', schemas), 204 env: test_env, suite: ['qapi-schema', 'qapi-frontend']) 205 206diff = find_program('diff') 207 208qapi_doc = custom_target('QAPI doc', 209 output: ['doc-good-qapi-commands.c', 'doc-good-qapi-commands.h', 210 'doc-good-qapi-emit-events.c', 'doc-good-qapi-emit-events.h', 211 'doc-good-qapi-events.c', 'doc-good-qapi-events.h', 212 'doc-good-qapi-init-commands.c', 'doc-good-qapi-init-commands.h', 213 'doc-good-qapi-introspect.c', 'doc-good-qapi-introspect.h', 214 'doc-good-qapi-types.c', 'doc-good-qapi-types.h', 215 'doc-good-qapi-visit.c', 'doc-good-qapi-visit.h' ], 216 input: files('doc-good.json'), 217 command: [ qapi_gen, '-o', meson.current_build_dir(), 218 '-p', 'doc-good-', '@INPUT0@' ], 219 depend_files: qapi_gen_depends) 220 221# Test the document-comment document generation code by running a test schema 222# file through Sphinx's plain-text builder and comparing the result against 223# a golden reference. This is in theory susceptible to failures if Sphinx 224# changes its output, but the text output has historically been very stable 225# (no changes between Sphinx 1.6 and 3.0), so it is a better bet than 226# texinfo or HTML generation, both of which have had changes. We might 227# need to add more sophisticated logic here in future for some sort of 228# fuzzy comparison if future Sphinx versions produce different text, 229# but for now the simple comparison suffices. 230qapi_doc_out = custom_target('QAPI rST doc', 231 output: ['doc-good.txt'], 232 input: files('doc-good.json', 'doc-good.rst'), 233 build_by_default: build_docs, 234 depend_files: sphinx_extn_depends, 235 # We use -E to suppress Sphinx's caching, because 236 # we want it to always really run the QAPI doc 237 # generation code. It also means we don't 238 # clutter up the build dir with the cache. 239 command: [SPHINX_ARGS, 240 '-b', 'text', '-E', 241 '-c', meson.source_root() / 'docs', 242 '-D', 'master_doc=doc-good', 243 meson.current_source_dir(), 244 meson.current_build_dir()]) 245 246# Fix possible inconsistency in line endings in generated output and 247# in the golden reference (which could otherwise cause test failures 248# on Windows hosts). Unfortunately diff --strip-trailing-cr 249# is GNU-diff only. The odd-looking perl is because we must avoid 250# using an explicit '\' character in the command arguments to 251# a custom_target(), as Meson will unhelpfully replace it with a '/' 252# (https://github.com/mesonbuild/meson/issues/1564) 253qapi_doc_out_nocr = custom_target('QAPI rST doc newline-sanitized', 254 output: ['doc-good.txt.nocr'], 255 input: qapi_doc_out[0], 256 build_by_default: build_docs, 257 command: ['perl', '-pe', '$x = chr 13; s/$x$//', '@INPUT@'], 258 capture: true) 259 260qapi_doc_ref_nocr = custom_target('QAPI rST doc reference newline-sanitized', 261 output: ['doc-good.ref.nocr'], 262 input: files('doc-good.txt'), 263 build_by_default: build_docs, 264 command: ['perl', '-pe', '$x = chr 13; s/$x$//', '@INPUT@'], 265 capture: true) 266 267if build_docs 268 # "full_path()" needed here to work around 269 # https://github.com/mesonbuild/meson/issues/7585 270 test('QAPI rST doc', diff, args: ['-u', qapi_doc_ref_nocr[0].full_path(), 271 qapi_doc_out_nocr[0].full_path()], 272 depends: [qapi_doc_ref_nocr, qapi_doc_out_nocr], 273 suite: ['qapi-schema', 'qapi-doc']) 274endif 275