ruff/crates
Carl Meyer 93eff7f174
[red-knot] type inference/checking test framework (#13636)
## Summary

Adds a markdown-based test framework for writing tests of type inference
and type checking. Fixes #11664.

Implements the basic required features. A markdown test file is a suite
of tests, each test can contain one or more Python files, with
optionally specified path/name. The test writes all files to an
in-memory file system, runs red-knot, and matches the resulting
diagnostics against `Type: ` and `Error: ` assertions embedded in the
Python source as comments.

We will want to add features like incremental tests, setting custom
configuration for tests, writing non-Python files, testing syntax
errors, capturing full diagnostic output, etc. There's also plenty of
room for improved UX (colored output?).

## Test Plan

Lots of tests!

Sample of the current output when a test fails:

```
     Running tests/inference.rs (target/debug/deps/inference-7c96590aa84de2a4)

running 1 test
test inference::path_1_resources_inference_numbers_md ... FAILED

failures:

---- inference::path_1_resources_inference_numbers_md stdout ----
inference/numbers.md - Numbers - Floats
  /src/test.py
    line 2: unexpected error: [invalid-assignment] "Object of type `Literal["str"]` is not assignable to `int`"

thread 'inference::path_1_resources_inference_numbers_md' panicked at crates/red_knot_test/src/lib.rs:60:5:
Some tests failed.
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    inference::path_1_resources_inference_numbers_md

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.19s

error: test failed, to rerun pass `-p red_knot_test --test inference`
```

---------

Co-authored-by: Micha Reiser <micha@reiser.io>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2024-10-08 12:33:19 -07:00
..
red_knot Use backticks for code in red-knot messages (#13599) 2024-10-02 03:14:28 +00:00
red_knot_python_semantic [red-knot] type inference/checking test framework (#13636) 2024-10-08 12:33:19 -07:00
red_knot_server Use backticks for code in red-knot messages (#13599) 2024-10-02 03:14:28 +00:00
red_knot_test [red-knot] type inference/checking test framework (#13636) 2024-10-08 12:33:19 -07:00
red_knot_vendored Rename the `ruff_vendored` crate to `red_knot_vendored` (#13586) 2024-10-01 16:16:59 +01:00
red_knot_wasm Use backticks for code in red-knot messages (#13599) 2024-10-02 03:14:28 +00:00
red_knot_workspace Use backticks for code in red-knot messages (#13599) 2024-10-02 03:14:28 +00:00
ruff Bump version to 0.6.9 (#13624) 2024-10-04 18:51:13 +05:30
ruff_benchmark Use backticks for code in red-knot messages (#13599) 2024-10-02 03:14:28 +00:00
ruff_cache Fix cache key collisions for paths with separators (#12159) 2024-07-03 07:36:46 -05:00
ruff_db Use backticks for code in red-knot messages (#13599) 2024-10-02 03:14:28 +00:00
ruff_dev Fix parentheses around return type annotations (#13381) 2024-09-20 09:23:53 +02:00
ruff_diagnostics [Minor typo] Fix article in "an fix" (#12797) 2024-08-10 21:22:00 -04:00
ruff_formatter Use backticks for code in red-knot messages (#13599) 2024-10-02 03:14:28 +00:00
ruff_graph Don't skip over imports and other nodes containing nested statements in import collector (#13521) 2024-09-26 11:57:05 +00:00
ruff_index [red-knot] small efficiency improvements and bugfixes to use-def map building (#12373) 2024-07-18 09:24:58 -07:00
ruff_linter Add known limitation to `C416` with dictionaries (#13627) 2024-10-07 16:20:45 +00:00
ruff_macros Drop deprecated `nursery` rule group (#10172) 2024-06-27 13:44:11 +02:00
ruff_notebook Fallback to kernelspec to check if it's a Python notebook (#12875) 2024-08-14 12:36:09 +05:30
ruff_python_ast [refurb] Count codepoints not bytes for `slice-to-remove-prefix-or-suffix (FURB188)` (#13631) 2024-10-07 16:13:28 +02:00
ruff_python_ast_integration_tests [internal] `ComparableExpr` (f)strings and bytes made invariant under concatenation (#13301) 2024-09-25 16:58:57 +02:00
ruff_python_codegen Implement `iter()`, `len()` and `is_empty()` for all display-literal AST nodes (#12807) 2024-08-12 10:39:28 +00:00
ruff_python_formatter Normalize implicit concatenated f-string quotes per part (#13539) 2024-10-08 09:59:17 +00:00
ruff_python_index Enable token-based rules on source with syntax errors (#11950) 2024-07-02 08:57:46 +00:00
ruff_python_literal Remove some unused `pub` functions (#11576) 2024-05-28 09:56:51 -04:00
ruff_python_parser Expose internal types as public access (#13509) 2024-09-26 17:34:30 +02:00
ruff_python_resolver chore(deps): update rust crate insta to v1.38.0 (#10701) 2024-04-01 15:44:30 +00:00
ruff_python_semantic Fix `PTH123` false positive when `open` is passed a file descriptor (#13616) 2024-10-04 08:48:47 -05:00
ruff_python_stdlib Remove allocation from `ruff_python_stdlib::builtins::python_builtins` (#13317) 2024-09-10 16:34:24 -04:00
ruff_python_trivia [red-knot] type inference/checking test framework (#13636) 2024-10-08 12:33:19 -07:00
ruff_python_trivia_integration_tests Build `CommentRanges` outside the parser (#11792) 2024-06-09 09:55:17 +00:00
ruff_server Add support for extensionless Python files for server (#13326) 2024-09-12 00:35:26 +05:30
ruff_source_file Fix off-by one error in the `LineIndex::offset` calculation (#13407) 2024-09-19 11:58:45 +00:00
ruff_text_size [red-knot] type inference/checking test framework (#13636) 2024-10-08 12:33:19 -07:00
ruff_wasm Bump version to 0.6.9 (#13624) 2024-10-04 18:51:13 +05:30
ruff_workspace Fix typo in `allow-unused-imports` documentation (#13669) 2024-10-07 14:08:36 -05:00