Move tests/rustdoc testsuite to //@ syntax · rust-lang/rust@d3ec92e (original) (raw)

`@@ -241,11 +241,236 @@ def concat_multi_lines(f):

`

241

241

``

242

242

``

243

243

`LINE_PATTERN = re.compile(r'''

`

244

``

`-

(?<=(?<!\S))(?P!?)@(?P!?)

`

245

``

`-

(?P[A-Za-z]+(?:-[A-Za-z]+)*)

`

``

244

`+

//@\s+

`

``

245

`+

(?P!?)(?P[A-Za-z]+(?:-[A-Za-z]+)*)

`

246

246

` (?P.*)$

`

247

247

`''', re.X | re.UNICODE)

`

248

248

``

``

249

`` +

Equivalent to src/tools/compiletest/src/header.rs constant of the same name.

``

``

250

`+

KNOWN_DIRECTIVE_NAMES = [

`

``

251

`+

tidy-alphabetical-start

`

``

252

`+

"assembly-output",

`

``

253

`+

"aux-bin",

`

``

254

`+

"aux-build",

`

``

255

`+

"aux-codegen-backend",

`

``

256

`+

"aux-crate",

`

``

257

`+

"build-aux-docs",

`

``

258

`+

"build-fail",

`

``

259

`+

"build-pass",

`

``

260

`+

"check-fail",

`

``

261

`+

"check-pass",

`

``

262

`+

"check-run-results",

`

``

263

`+

"check-stdout",

`

``

264

`+

"check-test-line-numbers-match",

`

``

265

`+

"compare-output-lines-by-subset",

`

``

266

`+

"compile-flags",

`

``

267

`+

"dont-check-compiler-stderr",

`

``

268

`+

"dont-check-compiler-stdout",

`

``

269

`+

"dont-check-failure-status",

`

``

270

`+

"edition",

`

``

271

`+

"error-pattern",

`

``

272

`+

"exec-env",

`

``

273

`+

"failure-status",

`

``

274

`+

"filecheck-flags",

`

``

275

`+

"forbid-output",

`

``

276

`+

"force-host",

`

``

277

`+

"ignore-16bit",

`

``

278

`+

"ignore-32bit",

`

``

279

`+

"ignore-64bit",

`

``

280

`+

"ignore-aarch64",

`

``

281

`+

"ignore-aarch64-unknown-linux-gnu",

`

``

282

`+

"ignore-android",

`

``

283

`+

"ignore-apple",

`

``

284

`+

"ignore-arm",

`

``

285

`+

"ignore-avr",

`

``

286

`+

"ignore-beta",

`

``

287

`+

"ignore-cdb",

`

``

288

`+

"ignore-compare-mode-next-solver",

`

``

289

`+

"ignore-compare-mode-polonius",

`

``

290

`+

"ignore-cross-compile",

`

``

291

`+

"ignore-debug",

`

``

292

`+

"ignore-eabi",

`

``

293

`+

"ignore-emscripten",

`

``

294

`+

"ignore-endian-big",

`

``

295

`+

"ignore-freebsd",

`

``

296

`+

"ignore-fuchsia",

`

``

297

`+

"ignore-gdb",

`

``

298

`+

"ignore-gdb-version",

`

``

299

`+

"ignore-gnu",

`

``

300

`+

"ignore-haiku",

`

``

301

`+

"ignore-horizon",

`

``

302

`+

"ignore-i686-pc-windows-msvc",

`

``

303

`+

"ignore-ios",

`

``

304

`+

"ignore-linux",

`

``

305

`+

"ignore-lldb",

`

``

306

`+

"ignore-llvm-version",

`

``

307

`+

"ignore-loongarch64",

`

``

308

`+

"ignore-macabi",

`

``

309

`+

"ignore-macos",

`

``

310

`+

"ignore-mode-assembly",

`

``

311

`+

"ignore-mode-codegen",

`

``

312

`+

"ignore-mode-codegen-units",

`

``

313

`+

"ignore-mode-coverage-map",

`

``

314

`+

"ignore-mode-coverage-run",

`

``

315

`+

"ignore-mode-crashes",

`

``

316

`+

"ignore-mode-debuginfo",

`

``

317

`+

"ignore-mode-incremental",

`

``

318

`+

"ignore-mode-js-doc-test",

`

``

319

`+

"ignore-mode-mir-opt",

`

``

320

`+

"ignore-mode-pretty",

`

``

321

`+

"ignore-mode-run-make",

`

``

322

`+

"ignore-mode-run-pass-valgrind",

`

``

323

`+

"ignore-mode-rustdoc",

`

``

324

`+

"ignore-mode-rustdoc-json",

`

``

325

`+

"ignore-mode-ui",

`

``

326

`+

"ignore-mode-ui-fulldeps",

`

``

327

`+

"ignore-msp430",

`

``

328

`+

"ignore-msvc",

`

``

329

`+

"ignore-musl",

`

``

330

`+

"ignore-netbsd",

`

``

331

`+

"ignore-nightly",

`

``

332

`+

"ignore-none",

`

``

333

`+

"ignore-nto",

`

``

334

`+

"ignore-nvptx64",

`

``

335

`+

"ignore-nvptx64-nvidia-cuda",

`

``

336

`+

"ignore-openbsd",

`

``

337

`+

"ignore-pass",

`

``

338

`+

"ignore-remote",

`

``

339

`+

"ignore-riscv64",

`

``

340

`+

"ignore-s390x",

`

``

341

`+

"ignore-sgx",

`

``

342

`+

"ignore-spirv",

`

``

343

`+

"ignore-stable",

`

``

344

`+

"ignore-stage1",

`

``

345

`+

"ignore-stage2",

`

``

346

`+

"ignore-test",

`

``

347

`+

"ignore-thumb",

`

``

348

`+

"ignore-thumbv8m.base-none-eabi",

`

``

349

`+

"ignore-thumbv8m.main-none-eabi",

`

``

350

`+

"ignore-tvos",

`

``

351

`+

"ignore-unix",

`

``

352

`+

"ignore-unknown",

`

``

353

`+

"ignore-uwp",

`

``

354

`+

"ignore-visionos",

`

``

355

`+

"ignore-vxworks",

`

``

356

`+

"ignore-wasi",

`

``

357

`+

"ignore-wasm",

`

``

358

`+

"ignore-wasm32",

`

``

359

`+

"ignore-wasm32-bare",

`

``

360

`+

"ignore-wasm64",

`

``

361

`+

"ignore-watchos",

`

``

362

`+

"ignore-windows",

`

``

363

`+

"ignore-windows-gnu",

`

``

364

`+

"ignore-x32",

`

``

365

`+

"ignore-x86",

`

``

366

`+

"ignore-x86_64",

`

``

367

`+

"ignore-x86_64-unknown-linux-gnu",

`

``

368

`+

"incremental",

`

``

369

`+

"known-bug",

`

``

370

`+

"llvm-cov-flags",

`

``

371

`+

"min-cdb-version",

`

``

372

`+

"min-gdb-version",

`

``

373

`+

"min-lldb-version",

`

``

374

`+

"min-llvm-version",

`

``

375

`+

"min-system-llvm-version",

`

``

376

`+

"needs-asm-support",

`

``

377

`+

"needs-dlltool",

`

``

378

`+

"needs-dynamic-linking",

`

``

379

`+

"needs-force-clang-based-tests",

`

``

380

`+

"needs-git-hash",

`

``

381

`+

"needs-llvm-components",

`

``

382

`+

"needs-profiler-support",

`

``

383

`+

"needs-relocation-model-pic",

`

``

384

`+

"needs-run-enabled",

`

``

385

`+

"needs-rust-lld",

`

``

386

`+

"needs-rust-lldb",

`

``

387

`+

"needs-sanitizer-address",

`

``

388

`+

"needs-sanitizer-cfi",

`

``

389

`+

"needs-sanitizer-dataflow",

`

``

390

`+

"needs-sanitizer-hwaddress",

`

``

391

`+

"needs-sanitizer-kcfi",

`

``

392

`+

"needs-sanitizer-leak",

`

``

393

`+

"needs-sanitizer-memory",

`

``

394

`+

"needs-sanitizer-memtag",

`

``

395

`+

"needs-sanitizer-safestack",

`

``

396

`+

"needs-sanitizer-shadow-call-stack",

`

``

397

`+

"needs-sanitizer-support",

`

``

398

`+

"needs-sanitizer-thread",

`

``

399

`+

"needs-threads",

`

``

400

`+

"needs-unwind",

`

``

401

`+

"needs-wasmtime",

`

``

402

`+

"needs-xray",

`

``

403

`+

"no-auto-check-cfg",

`

``

404

`+

"no-prefer-dynamic",

`

``

405

`+

"normalize-stderr-32bit",

`

``

406

`+

"normalize-stderr-64bit",

`

``

407

`+

"normalize-stderr-test",

`

``

408

`+

"normalize-stdout-test",

`

``

409

`+

"only-16bit",

`

``

410

`+

"only-32bit",

`

``

411

`+

"only-64bit",

`

``

412

`+

"only-aarch64",

`

``

413

`+

"only-apple",

`

``

414

`+

"only-arm",

`

``

415

`+

"only-avr",

`

``

416

`+

"only-beta",

`

``

417

`+

"only-bpf",

`

``

418

`+

"only-cdb",

`

``

419

`+

"only-gnu",

`

``

420

`+

"only-i686-pc-windows-msvc",

`

``

421

`+

"only-ios",

`

``

422

`+

"only-linux",

`

``

423

`+

"only-loongarch64",

`

``

424

`+

"only-loongarch64-unknown-linux-gnu",

`

``

425

`+

"only-macos",

`

``

426

`+

"only-mips",

`

``

427

`+

"only-mips64",

`

``

428

`+

"only-msp430",

`

``

429

`+

"only-msvc",

`

``

430

`+

"only-nightly",

`

``

431

`+

"only-nvptx64",

`

``

432

`+

"only-riscv64",

`

``

433

`+

"only-sparc",

`

``

434

`+

"only-sparc64",

`

``

435

`+

"only-stable",

`

``

436

`+

"only-thumb",

`

``

437

`+

"only-tvos",

`

``

438

`+

"only-unix",

`

``

439

`+

"only-visionos",

`

``

440

`+

"only-wasm32",

`

``

441

`+

"only-wasm32-bare",

`

``

442

`+

"only-wasm32-wasip1",

`

``

443

`+

"only-watchos",

`

``

444

`+

"only-windows",

`

``

445

`+

"only-x86",

`

``

446

`+

"only-x86_64",

`

``

447

`+

"only-x86_64-fortanix-unknown-sgx",

`

``

448

`+

"only-x86_64-pc-windows-gnu",

`

``

449

`+

"only-x86_64-pc-windows-msvc",

`

``

450

`+

"only-x86_64-unknown-linux-gnu",

`

``

451

`+

"pp-exact",

`

``

452

`+

"pretty-compare-only",

`

``

453

`+

"pretty-expanded",

`

``

454

`+

"pretty-mode",

`

``

455

`+

"regex-error-pattern",

`

``

456

`+

"remap-src-base",

`

``

457

`+

"revisions",

`

``

458

`+

"run-fail",

`

``

459

`+

"run-flags",

`

``

460

`+

"run-pass",

`

``

461

`+

"run-rustfix",

`

``

462

`+

"rustc-env",

`

``

463

`+

"rustfix-only-machine-applicable",

`

``

464

`+

"should-fail",

`

``

465

`+

"should-ice",

`

``

466

`+

"stderr-per-bitwidth",

`

``

467

`+

"test-mir-pass",

`

``

468

`+

"unset-exec-env",

`

``

469

`+

"unset-rustc-env",

`

``

470

`` +

Used by the tidy check unknown_revision.

``

``

471

`+

"unused-revision-names",

`

``

472

`+

tidy-alphabetical-end

`

``

473

`+

]

`

249

474

``

250

475

`def get_commands(template):

`

251

476

`with io.open(template, encoding='utf-8') as f:

`

`@@ -254,17 +479,9 @@ def get_commands(template):

`

254

479

`if not m:

`

255

480

`continue

`

256

481

``

257

``

`-

negated = (m.group('negated') == '!')

`

258

482

`cmd = m.group('cmd')

`

259

``

`-

if m.group('invalid') == '!':

`

260

``

`-

print_err(

`

261

``

`-

lineno,

`

262

``

`-

line,

`

263

``

`` -

'Invalid command: !@{0}{1}, (help: try with @!{1})'.format(

``

264

``

`-

'!' if negated else '',

`

265

``

`-

cmd,

`

266

``

`-

),

`

267

``

`-

)

`

``

483

`+

negated = (m.group('negated') == '!')

`

``

484

`+

if not negated and cmd in KNOWN_DIRECTIVE_NAMES:

`

268

485

`continue

`

269

486

`args = m.group('args')

`

270

487

`if args and not args[:1].isspace():

`

`@@ -549,7 +766,7 @@ def get_nb_matching_elements(cache, c, regexp, stop_at_first):

`

549

766

`def check_files_in_folder(c, cache, folder, files):

`

550

767

`files = files.strip()

`

551

768

`if not files.startswith('[') or not files.endswith(']'):

`

552

``

`-

raise InvalidCheck("Expected list as second argument of @{} (ie '[]')".format(c.cmd))

`

``

769

`+

raise InvalidCheck("Expected list as second argument of {} (ie '[]')".format(c.cmd))

`

553

770

``

554

771

`folder = cache.get_absolute_path(folder)

`

555

772

``

`@@ -558,7 +775,7 @@ def check_files_in_folder(c, cache, folder, files):

`

558

775

`files_set = set()

`

559

776

`for file in files:

`

560

777

`if file in files_set:

`

561

``

`` -

raise InvalidCheck("Duplicated file {} in @{}".format(file, c.cmd))

``

``

778

`` +

raise InvalidCheck("Duplicated file {} in {}".format(file, c.cmd))

``

562

779

`files_set.add(file)

`

563

780

`folder_set = set([f for f in os.listdir(folder) if f != "." and f != ".."])

`

564

781

``

`@@ -590,48 +807,48 @@ def check_command(c, cache):

`

590

807

`if c.cmd in ['has', 'hasraw', 'matches', 'matchesraw']: # string test

`

591

808

`regexp = c.cmd.startswith('matches')

`

592

809

``

593

``

`-

@has = file existence

`

``

810

`+

has = file existence

`

594

811

`if len(c.args) == 1 and not regexp and 'raw' not in c.cmd:

`

595

812

`try:

`

596

813

`cache.get_file(c.args[0])

`

597

814

`ret = True

`

598

815

`except FailedCheck as err:

`

599

816

`cerr = str(err)

`

600

817

`ret = False

`

601

``

`-

@hasraw/matchesraw = string test

`

``

818

`+

hasraw/matchesraw = string test

`

602

819

`elif len(c.args) == 2 and 'raw' in c.cmd:

`

603

820

`` cerr = "PATTERN did not match"

``

604

821

`ret = check_string(cache.get_file(c.args[0]), c.args[1], regexp)

`

605

``

`-

@has/matches = XML tree test

`

``

822

`+

has/matches = XML tree test

`

606

823

`elif len(c.args) == 3 and 'raw' not in c.cmd:

`

607

824

`` cerr = "XPATH PATTERN did not match"

``

608

825

`ret = get_nb_matching_elements(cache, c, regexp, True) != 0

`

609

826

`else:

`

610

``

`-

raise InvalidCheck('Invalid number of @{} arguments'.format(c.cmd))

`

``

827

`+

raise InvalidCheck('Invalid number of {} arguments'.format(c.cmd))

`

611

828

``

612

829

`elif c.cmd == 'files': # check files in given folder

`

613

``

`-

if len(c.args) != 2: # @files

`

614

``

`-

raise InvalidCheck("Invalid number of @{} arguments".format(c.cmd))

`

``

830

`+

if len(c.args) != 2: # files

`

``

831

`+

raise InvalidCheck("Invalid number of {} arguments".format(c.cmd))

`

615

832

`elif c.negated:

`

616

``

`-

raise InvalidCheck("@{} doesn't support negative check".format(c.cmd))

`

``

833

`+

raise InvalidCheck("{} doesn't support negative check".format(c.cmd))

`

617

834

`ret = check_files_in_folder(c, cache, c.args[0], c.args[1])

`

618

835

``

619

836

`elif c.cmd == 'count': # count test

`

620

``

`-

if len(c.args) == 3: # @count = count test

`

``

837

`+

if len(c.args) == 3: # count = count test

`

621

838

`expected = int(c.args[2])

`

622

839

`found = get_tree_count(cache.get_tree(c.args[0]), c.args[1])

`

623

840

`cerr = "Expected {} occurrences but found {}".format(expected, found)

`

624

841

`ret = expected == found

`

625

``

`-

elif len(c.args) == 4: # @count = count test

`

``

842

`+

elif len(c.args) == 4: # count = count test

`

626

843

`expected = int(c.args[3])

`

627

844

`found = get_nb_matching_elements(cache, c, False, False)

`

628

845

`cerr = "Expected {} occurrences but found {}".format(expected, found)

`

629

846

`ret = found == expected

`

630

847

`else:

`

631

``

`-

raise InvalidCheck('Invalid number of @{} arguments'.format(c.cmd))

`

``

848

`+

raise InvalidCheck('Invalid number of {} arguments'.format(c.cmd))

`

632

849

``

633

850

`elif c.cmd == 'snapshot': # snapshot test

`

634

``

`-

if len(c.args) == 3: # @snapshot

`

``

851

`+

if len(c.args) == 3: # snapshot

`

635

852

` [snapshot_name, html_path, pattern] = c.args

`

636

853

`tree = cache.get_tree(html_path)

`

637

854

`xpath = normalize_xpath(pattern)

`

`@@ -654,33 +871,33 @@ def check_command(c, cache):

`

654

871

`else:

`

655

872

`raise FailedCheck('Expected 1 match, but found {}'.format(len(subtrees)))

`

656

873

`else:

`

657

``

`-

raise InvalidCheck('Invalid number of @{} arguments'.format(c.cmd))

`

``

874

`+

raise InvalidCheck('Invalid number of {} arguments'.format(c.cmd))

`

658

875

``

659

876

`elif c.cmd == 'has-dir': # has-dir test

`

660

``

`-

if len(c.args) == 1: # @has-dir = has-dir test

`

``

877

`+

if len(c.args) == 1: # has-dir = has-dir test

`

661

878

`try:

`

662

879

`cache.get_dir(c.args[0])

`

663

880

`ret = True

`

664

881

`except FailedCheck as err:

`

665

882

`cerr = str(err)

`

666

883

`ret = False

`

667

884

`else:

`

668

``

`-

raise InvalidCheck('Invalid number of @{} arguments'.format(c.cmd))

`

``

885

`+

raise InvalidCheck('Invalid number of {} arguments'.format(c.cmd))

`

669

886

``

670

887

`elif c.cmd == 'valid-html':

`

671

``

`-

raise InvalidCheck('Unimplemented @valid-html')

`

``

888

`+

raise InvalidCheck('Unimplemented valid-html')

`

672

889

``

673

890

`elif c.cmd == 'valid-links':

`

674

``

`-

raise InvalidCheck('Unimplemented @valid-links')

`

``

891

`+

raise InvalidCheck('Unimplemented valid-links')

`

675

892

``

676

893

`else:

`

677

``

`-

raise InvalidCheck('Unrecognized @{}'.format(c.cmd))

`

``

894

`+

raise InvalidCheck('Unrecognized {}'.format(c.cmd))

`

678

895

``

679

896

`if ret == c.negated:

`

680

897

`raise FailedCheck(cerr)

`

681

898

``

682

899

`except FailedCheck as err:

`

683

``

`-

message = '@{}{} check failed'.format('!' if c.negated else '', c.cmd)

`

``

900

`+

message = '{}{} check failed'.format('!' if c.negated else '', c.cmd)

`

684

901

`print_err(c.lineno, c.context, str(err), message)

`

685

902

`except InvalidCheck as err:

`

686

903

`print_err(c.lineno, c.context, str(err))

`