Repository: astral-sh/ruff
File: crates/ty/tests/cli/main.rs (Rust)

Code before:
    assert_cmd_snapshot!(case.command(), @r###"
    success: true
    exit_code: 0
    ----- stdout -----
    info[revealed-type]: Revealed type
     --> test.py:4:13
      |
    2 | from typing_extensions import reveal_type
    3 | total = 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 +…
    4 | reveal_type(total)
      |             ^^^^^ `Literal[2000]`
      |

    Found 1 diagnostic

    ----- stderr -----
    "###);

    Ok(())
}

#[test_case::test_case("concise")]
#[test_case::test_case("full")]
#[test_case::test_case("github")]
#[test_case::test_case("gitlab")]
fn output_format(output_format: &str) -> anyhow::Result<()> {
    let case = CliTest::with_file(
        "test.py",
        "
        from typing_extensions import reveal_type
        reveal_type('str'.lower())  # revealed-type
        match 42:  # invalid-syntax
            case _: ...
        ",
    )?;

    let snapshot = format!("output_format_{output_format}");

    assert_cmd_snapshot!(
        snapshot,
        case.command()
            .args(["--output-format", output_format, "--target-version", "3.9"])
    );

    Ok(())
}

pub(crate) struct CliTest {
    _temp_dir: TempDir,
    settings: Settings,
    settings_scope: Option<SettingsBindDropGuard>,

Review comment (suggestion):
I probably should have looked around a little harder. I forgot that I added separate tests for these in earlier PRs. We could probably just combine the separate [`gitlab_diagnostics`](https://github.com/astral-sh/ruff/blob/ed64c4d943d5a29c017550a6fc015922666002ac/crates/ty/tests/cli/main.rs#L656) and [`github_diagnostics`](https://github.com/astral-sh/ruff/blob/ed64c4d943d5a29c017550a6fc015922666002ac/crates/ty/tests/cli/main.rs#L721) tests with this one? And maybe also [`concise_diagnostics`](https://github.com/astral-sh/ruff/blob/ed64c4d943d5a29c017550a6fc015922666002ac/crates/ty/tests/cli/main.rs#L632) and [`concise_revealed_type`](https://github.com/astral-sh/ruff/blob/ed64c4d943d5a29c017550a6fc015922666002ac/crates/ty/tests/cli/main.rs#L752). Or I can add the `reveal_type` call back to the pre-existing tests.

Code after:
    test.py:5:13: info[revealed-type] Revealed type: `Literal["hello"]`
    Found 1 diagnostic

    ----- stderr -----
    "###);

    Ok(())
}

#[test]
fn can_handle_large_binop_expressions() -> anyhow::Result<()> {
    let mut content = String::new();
    writeln!(
        &mut content,
        "
        from typing_extensions import reveal_type
        total = 1{plus_one_repeated}
        reveal_type(total)
        ",
        plus_one_repeated = " + 1".repeat(2000 - 1)
    )?;

    let case = CliTest::with_file("test.py", &ruff_python_trivia::textwrap::dedent(&content))?;

    assert_cmd_snapshot!(case.command(), @r###"
    success: true
    exit_code: 0
    ----- stdout -----
    info[revealed-type]: Revealed type
     --> test.py:4:13
      |
    2 | from typing_extensions import reveal_type
    3 | total = 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 +…
    4 | reveal_type(total)
      |             ^^^^^ `Literal[2000]`
      |

    Found 1 diagnostic

    ----- stderr -----
    "###);

    Ok(())
}

pub(crate) struct CliTest {
    _temp_dir: TempDir,
    settings: Settings,
    settings_scope: Option<SettingsBindDropGuard>,
    project_dir: PathBuf,
    ty_binary_path: PathBuf,