mirror of https://github.com/astral-sh/ruff
Lint test code (#721)
This commit is contained in:
parent
84bf36194b
commit
43cc8bc84e
|
|
@ -77,7 +77,7 @@ jobs:
|
||||||
${{ runner.os }}-build-${{ env.cache-name }}-
|
${{ runner.os }}-build-${{ env.cache-name }}-
|
||||||
${{ runner.os }}-build-
|
${{ runner.os }}-build-
|
||||||
${{ runner.os }}-
|
${{ runner.os }}-
|
||||||
- run: cargo clippy --all -- -D warnings
|
- run: cargo clippy --all-targets --all-features -- -D warnings
|
||||||
|
|
||||||
cargo_test:
|
cargo_test:
|
||||||
name: "cargo test"
|
name: "cargo test"
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
|
use std::fs;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||||
use ropey::Rope;
|
use ropey::Rope;
|
||||||
use ruff::fs;
|
|
||||||
|
|
||||||
fn criterion_benchmark(c: &mut Criterion) {
|
fn criterion_benchmark(c: &mut Criterion) {
|
||||||
let contents = fs::read_file(Path::new("resources/test/fixtures/D.py")).unwrap();
|
let contents = fs::read_to_string(Path::new("resources/test/fixtures/D.py")).unwrap();
|
||||||
c.bench_function("rope", |b| {
|
c.bench_function("rope", |b| {
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
let rope = Rope::from_str(black_box(&contents));
|
let rope = Rope::from_str(black_box(&contents));
|
||||||
|
|
|
||||||
|
|
@ -283,7 +283,7 @@ mod tests {
|
||||||
},
|
},
|
||||||
&fixer::Mode::Generate,
|
&fixer::Mode::Generate,
|
||||||
);
|
);
|
||||||
return checks;
|
checks
|
||||||
};
|
};
|
||||||
assert!(!check_with_max_line_length(6).is_empty());
|
assert!(!check_with_max_line_length(6).is_empty());
|
||||||
assert!(check_with_max_line_length(7).is_empty());
|
assert!(check_with_max_line_length(7).is_empty());
|
||||||
|
|
|
||||||
|
|
@ -517,7 +517,7 @@ mod tests {
|
||||||
let snapshot = format!("{}_{}", check_code.as_ref(), path.to_string_lossy());
|
let snapshot = format!("{}_{}", check_code.as_ref(), path.to_string_lossy());
|
||||||
let mut checks = test_path(
|
let mut checks = test_path(
|
||||||
Path::new("./resources/test/fixtures").join(path).as_path(),
|
Path::new("./resources/test/fixtures").join(path).as_path(),
|
||||||
&settings::Settings::for_rule(check_code.clone()),
|
&settings::Settings::for_rule(check_code),
|
||||||
&fixer::Mode::Generate,
|
&fixer::Mode::Generate,
|
||||||
)?;
|
)?;
|
||||||
checks.sort_by_key(|check| check.location);
|
checks.sort_by_key(|check| check.location);
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,7 @@ mod tests {
|
||||||
use crate::pep8_naming::helpers::{is_acronym, is_camelcase, is_mixed_case};
|
use crate::pep8_naming::helpers::{is_acronym, is_camelcase, is_mixed_case};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_is_camelcase() -> () {
|
fn test_is_camelcase() {
|
||||||
assert!(is_camelcase("Camel"));
|
assert!(is_camelcase("Camel"));
|
||||||
assert!(is_camelcase("CamelCase"));
|
assert!(is_camelcase("CamelCase"));
|
||||||
assert!(!is_camelcase("camel"));
|
assert!(!is_camelcase("camel"));
|
||||||
|
|
@ -93,7 +93,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_is_mixed_case() -> () {
|
fn test_is_mixed_case() {
|
||||||
assert!(is_mixed_case("mixedCase"));
|
assert!(is_mixed_case("mixedCase"));
|
||||||
assert!(is_mixed_case("mixed_Case"));
|
assert!(is_mixed_case("mixed_Case"));
|
||||||
assert!(is_mixed_case("_mixed_Case"));
|
assert!(is_mixed_case("_mixed_Case"));
|
||||||
|
|
@ -104,7 +104,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_is_acronym() -> () {
|
fn test_is_acronym() {
|
||||||
assert!(is_acronym("AB", "AB"));
|
assert!(is_acronym("AB", "AB"));
|
||||||
assert!(is_acronym("AbcDef", "AD"));
|
assert!(is_acronym("AbcDef", "AD"));
|
||||||
assert!(!is_acronym("AbcDef", "Ad"));
|
assert!(!is_acronym("AbcDef", "Ad"));
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ mod tests {
|
||||||
use crate::python::string::{is_lower, is_upper};
|
use crate::python::string::{is_lower, is_upper};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_is_lower() -> () {
|
fn test_is_lower() {
|
||||||
assert!(is_lower("abc"));
|
assert!(is_lower("abc"));
|
||||||
assert!(is_lower("a_b_c"));
|
assert!(is_lower("a_b_c"));
|
||||||
assert!(is_lower("a2c"));
|
assert!(is_lower("a2c"));
|
||||||
|
|
@ -38,7 +38,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_is_upper() -> () {
|
fn test_is_upper() {
|
||||||
assert!(is_upper("ABC"));
|
assert!(is_upper("ABC"));
|
||||||
assert!(is_upper("A_B_C"));
|
assert!(is_upper("A_B_C"));
|
||||||
assert!(is_upper("A2C"));
|
assert!(is_upper("A2C"));
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ use assert_cmd::{crate_name, Command};
|
||||||
#[test]
|
#[test]
|
||||||
fn test_stdin_success() -> Result<()> {
|
fn test_stdin_success() -> Result<()> {
|
||||||
let mut cmd = Command::cargo_bin(crate_name!())?;
|
let mut cmd = Command::cargo_bin(crate_name!())?;
|
||||||
cmd.args(&["-"]).write_stdin("").assert().success();
|
cmd.args(["-"]).write_stdin("").assert().success();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -14,7 +14,7 @@ fn test_stdin_success() -> Result<()> {
|
||||||
fn test_stdin_error() -> Result<()> {
|
fn test_stdin_error() -> Result<()> {
|
||||||
let mut cmd = Command::cargo_bin(crate_name!())?;
|
let mut cmd = Command::cargo_bin(crate_name!())?;
|
||||||
let output = cmd
|
let output = cmd
|
||||||
.args(&["-"])
|
.args(["-"])
|
||||||
.write_stdin("import os\n")
|
.write_stdin("import os\n")
|
||||||
.assert()
|
.assert()
|
||||||
.failure();
|
.failure();
|
||||||
|
|
@ -26,7 +26,7 @@ fn test_stdin_error() -> Result<()> {
|
||||||
fn test_stdin_filename() -> Result<()> {
|
fn test_stdin_filename() -> Result<()> {
|
||||||
let mut cmd = Command::cargo_bin(crate_name!())?;
|
let mut cmd = Command::cargo_bin(crate_name!())?;
|
||||||
let output = cmd
|
let output = cmd
|
||||||
.args(&["-", "--stdin-filename", "F401.py"])
|
.args(["-", "--stdin-filename", "F401.py"])
|
||||||
.write_stdin("import os\n")
|
.write_stdin("import os\n")
|
||||||
.assert()
|
.assert()
|
||||||
.failure();
|
.failure();
|
||||||
|
|
@ -38,7 +38,7 @@ fn test_stdin_filename() -> Result<()> {
|
||||||
fn test_stdin_autofix() -> Result<()> {
|
fn test_stdin_autofix() -> Result<()> {
|
||||||
let mut cmd = Command::cargo_bin(crate_name!())?;
|
let mut cmd = Command::cargo_bin(crate_name!())?;
|
||||||
let output = cmd
|
let output = cmd
|
||||||
.args(&["-", "--fix"])
|
.args(["-", "--fix"])
|
||||||
.write_stdin("import os\nimport sys\n\nprint(sys.version)\n")
|
.write_stdin("import os\nimport sys\n\nprint(sys.version)\n")
|
||||||
.assert()
|
.assert()
|
||||||
.success();
|
.success();
|
||||||
|
|
@ -53,7 +53,7 @@ fn test_stdin_autofix() -> Result<()> {
|
||||||
fn test_stdin_autofix_when_not_fixable_should_still_print_contents() -> Result<()> {
|
fn test_stdin_autofix_when_not_fixable_should_still_print_contents() -> Result<()> {
|
||||||
let mut cmd = Command::cargo_bin(crate_name!())?;
|
let mut cmd = Command::cargo_bin(crate_name!())?;
|
||||||
let output = cmd
|
let output = cmd
|
||||||
.args(&["-", "--fix"])
|
.args(["-", "--fix"])
|
||||||
.write_stdin("import os\nimport sys\n\nif (1, 2):\n print(sys.version)\n")
|
.write_stdin("import os\nimport sys\n\nif (1, 2):\n print(sys.version)\n")
|
||||||
.assert()
|
.assert()
|
||||||
.failure();
|
.failure();
|
||||||
|
|
@ -68,7 +68,7 @@ fn test_stdin_autofix_when_not_fixable_should_still_print_contents() -> Result<(
|
||||||
fn test_stdin_autofix_when_no_issues_should_still_print_contents() -> Result<()> {
|
fn test_stdin_autofix_when_no_issues_should_still_print_contents() -> Result<()> {
|
||||||
let mut cmd = Command::cargo_bin(crate_name!())?;
|
let mut cmd = Command::cargo_bin(crate_name!())?;
|
||||||
let output = cmd
|
let output = cmd
|
||||||
.args(&["-", "--fix"])
|
.args(["-", "--fix"])
|
||||||
.write_stdin("import sys\n\nprint(sys.version)\n")
|
.write_stdin("import sys\n\nprint(sys.version)\n")
|
||||||
.assert()
|
.assert()
|
||||||
.success();
|
.success();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue