Skip to main content

Source tests/integration.rs

1mod support;2use scraper::{Html, Selector};3use support::*;4#[test]5fn finding_summary_preserves_identity_and_location_with_native_no_js_details() {6    let f = Fixture::new("warning");7    assert_success(&f.run(&[]));8    for path in ["lint/clippy/clone_on_copy.html", "src/lib.rs.html"] {9        let doc = Html::parse_document(&f.html(path));10        let finding = doc11            .select(&Selector::parse("section.finding[id]").unwrap())12            .next()13            .unwrap();14        let toggle = finding15            .select(&Selector::parse("details.finding-toggle[open] > summary").unwrap())16            .next()17            .expect("native initially open finding summary");18        assert!(19            toggle20                .select(&Selector::parse(".severity").unwrap())21                .next()22                .is_some()23        );24        assert!(25            toggle26                .select(&Selector::parse("code").unwrap())27                .next()28                .unwrap()29                .text()30                .collect::<String>()31                .contains("clone_on_copy")32        );33        assert!(34            toggle35                .select(&Selector::parse(".finding-message").unwrap())36                .next()37                .is_some()38        );39        assert!(40            toggle41                .select(&Selector::parse(".finding-location a").unwrap())42                .next()43                .unwrap()44                .text()45                .collect::<String>()46                .contains("src/lib.rs:3:")47        );48        assert!(49            finding50                .select(&Selector::parse(".finding-body .diagnostic-location").unwrap())51                .next()52                .is_some()53        );54        assert_eq!(55            doc.select(&Selector::parse("#toggle-all-docs").unwrap())56                .count(),57            0,58            "global control requires JS"59        );60    }61}62#[test]63fn reports_embed_circle_clip_assets_without_retired_rust_logo_notice() {64    let f = Fixture::new("clean");65    assert_success(&f.run(&[]));66    let svg = f.html("static.files/favicon.svg");67    let doc = Html::parse_document(&svg);68    assert_eq!(69        doc.select(&Selector::parse("circle[fill=\"#000000\"]").unwrap())70            .count(),71        172    );73    assert_eq!(74        doc.select(&Selector::parse("path[stroke=\"#ffffff\"]").unwrap())75            .count(),76        177    );78    assert_eq!(79        doc.select(&Selector::parse("mask,g,metadata").unwrap())80            .count(),81        082    );83    for name in ["favicon.svg", "favicon.ico"] {84        assert_eq!(85            std::fs::read(f.report().join("static.files").join(name)).unwrap(),86            std::fs::read(87                std::path::Path::new(env!("CARGO_MANIFEST_DIR"))88                    .join("assets/favicon")89                    .join(name)90            )91            .unwrap()92        );93    }94    assert!(!f.report().join("licenses/favicon-CC-BY-4.0.txt").exists());95    let licenses = f.html("licenses/index.html");96    assert!(!licenses.contains("favicon-CC-BY") && !licenses.contains("modified Rust logo"));97    assert!(f.html("licenses/FAVICON.md").contains("MIT OR Apache-2.0"));98}99#[test]100fn help_is_readable_without_js_and_linked_from_nested_pages() {101    let f = Fixture::new("warning");102    assert_success(&f.run(&[]));103    let doc = Html::parse_document(&f.html("help.html"));104    assert_eq!(doc.select(&Selector::parse("#help").unwrap()).count(), 1);105    assert_eq!(106        doc.select(&Selector::parse("#help .shortcuts dt").unwrap())107            .count(),108        8109    );110    assert_eq!(111        doc.select(&Selector::parse("#back").unwrap())112            .next()113            .unwrap()114            .value()115            .attr("href"),116        Some("index.html")117    );118    let text = doc119        .select(&Selector::parse("#help").unwrap())120        .next()121        .unwrap()122        .text()123        .collect::<String>();124    assert!(text.contains("case-insensitive") && text.contains("⏎"));125    assert!(!text.contains("Escape"));126    assert_eq!(127        doc.select(&Selector::parse("#help .bottom code").unwrap())128            .next()129            .unwrap()130            .text()131            .collect::<String>(),132        format!("cargo-clippy-html {}", env!("CARGO_PKG_VERSION"))133    );134    assert!(135        !text.contains("Expand all") && !text.contains("fn:") && !text.contains("rustdoc book")136    );137    for path in [138        "index.html",139        "lint/clippy/clone_on_copy.html",140        "src/lib.rs.html",141    ] {142        let doc = Html::parse_document(&f.html(path));143        let toolbar = doc144            .select(&Selector::parse("rustdoc-toolbar").unwrap())145            .next()146            .unwrap();147        assert!(!toolbar.value().classes().any(|c| c == "hidden"));148        assert_eq!(149            toolbar150                .select(&Selector::parse("a > .label").unwrap())151                .map(|e| e.text().collect::<String>())152                .collect::<Vec<_>>(),153            ["Search", "Settings", "Help"]154        );155        let link = doc156            .select(&Selector::parse(".help-menu > a").unwrap())157            .next()158            .unwrap();159        assert!(link.value().attr("href").unwrap().ends_with("help.html"));160        assert_eq!(161            doc.select(&Selector::parse("template#help-content").unwrap())162                .count(),163            1164        );165    }166}167#[test]168fn settings_page_has_local_bootstrap_and_valid_report_navigation() {169    let f = Fixture::new("clean");170    assert_success(&f.run(&[]));171    let html = f.html("settings.html");172    let doc = Html::parse_document(&html);173    assert!(174        doc.select(&Selector::parse("noscript").unwrap())175            .next()176            .is_some()177    );178    assert_eq!(179        doc.select(&Selector::parse("#back").unwrap())180            .next()181            .unwrap()182            .value()183            .attr("href"),184        Some("index.html")185    );186    assert!(html.contains("Clippy HTML settings"));187    assert!(f.html("licenses/index.html").contains("SETTINGS.md"));188    for path in html_files(&f.report()) {189        let html = std::fs::read_to_string(path).unwrap();190        let doc = Html::parse_document(&html);191        let boot = doc192            .select(&Selector::parse("head script").unwrap())193            .next()194            .unwrap();195        assert!(196            boot.value()197                .attr("src")198                .unwrap()199                .ends_with("static.files/settings-storage.js")200        );201        assert!(boot.value().attr("defer").is_none());202        assert!(203            html.find("settings-storage.js").unwrap()204                < html.find("static.files/normalize.css").unwrap()205        );206    }207}208#[test]209fn search_index_links_all_report_kinds_without_copying_source_bodies() {210    let f = Fixture::new("warning");211    assert_success(&f.run(&[]));212    let script = f.html("static.files/search-index.js");213    let json = script214        .strip_prefix("globalThis.CLIPPY_HTML_SEARCH_DATA=")215        .unwrap()216        .trim_end()217        .strip_suffix(';')218        .unwrap();219    let entries: Vec<serde_json::Value> = serde_json::from_str(json).unwrap();220    for kind in ["lint", "file", "finding", "category"] {221        assert!(entries.iter().any(|e| e["kind"] == kind), "missing {kind}");222    }223    assert_eq!(entries.iter().filter(|e| e["kind"] == "finding").count(), 1);224    let finding = entries.iter().find(|e| e["kind"] == "finding").unwrap();225    assert!(226        finding["href"]227            .as_str()228            .unwrap()229            .starts_with("lint/clippy/clone_on_copy.html#finding-")230    );231    assert!(finding["context"].as_str().unwrap().contains("src/lib.rs"));232    assert!(233        finding["description"]234            .as_str()235            .unwrap()236            .contains("for further information visit")237    );238    assert!(!script.contains("pub fn copy_number"));239    for path in html_files(&f.report()) {240        let html = std::fs::read_to_string(&path).unwrap();241        let doc = Html::parse_document(&html);242        let scripts: Vec<_> = doc.select(&Selector::parse("script").unwrap()).collect();243        assert_eq!(scripts.len(), 8);244        for (script, name) in scripts.iter().zip([245            "settings-storage.js",246            "search-index.js",247            "search-engine.js",248            "search.js",249            "settings.js",250            "suggestions.js",251            "help.js",252            "summary.js",253        ]) {254            assert!(255                script256                    .value()257                    .attr("src")258                    .unwrap()259                    .ends_with(&format!("static.files/{name}"))260            );261            assert_eq!(262                script.value().attr("defer").is_some(),263                name != "settings-storage.js"264            );265            assert!(script.text().collect::<String>().is_empty()); warning: clippy::assert_is_empty266        }267        assert_eq!(268            doc.select(269                &Selector::parse(".main-heading > rustdoc-toolbar #search-button.hidden a")270                    .unwrap()271            )272            .count(),273            if html.contains("id=\"back\"") { 0 } else { 1 } warning: clippy::bool_to_int_with_if274        );275        assert!(276            doc.select(&Selector::parse("body[data-report-root]").unwrap())277                .next()278                .is_some()279        );280    }281}282#[test]283fn categories_link_to_lints_sources_and_record_the_bundled_origin() {284    let f = Fixture::new("warning");285    assert_success(&f.run(&[]));286    let category = f.report().join("category/complexity.html");287    assert!(288        category.is_file(),289        "known Clippy category should have a page"290    );291    let doc = Html::parse_document(&f.html("category/complexity.html"));292    assert!(293        doc.select(&Selector::parse("a").unwrap())294            .any(|a| a.value().attr("href") == Some("../lint/clippy/clone_on_copy.html"))295    );296    let lint = Html::parse_document(&f.html("lint/clippy/clone_on_copy.html"));297    assert!(298        lint.select(&Selector::parse("a").unwrap())299            .any(|a| a.value().attr("href") == Some("../../category/complexity.html"))300    );301    let index = f.html("index.html");302    assert!(index.contains("category/complexity.html"));303    assert!(index.contains("bundled"));304    assert!(index.contains("rust-1.97.0"));305    assert!(index.contains("Explicit tool --offline"));306    assert!(!f.report().join("category/unknown.html").exists());307    assert!(f.html("licenses/index.html").contains("Clippy category"));308}309#[test]310fn multiline_highlighting_preserves_source_text_without_creating_html() {311    let f = Fixture::new("warning");312    let source = "#![warn(clippy::clone_on_copy)]\n#[allow(dead_code)]\npub fn copy_number(value: i32) -> i32 {\n    let _ = r##\"</span><script>alert('bad')</script>&\nfn fake() {}\"##;\n    /* outer /* nested */\n       still a comment */\n    value.clone()\n}\n";313    std::fs::write(f.root.join("src/lib.rs"), source).unwrap();314    assert_success(&f.run(&[]));315    let path = html_files(&f.report().join("src")).pop().unwrap();316    let doc = Html::parse_document(&std::fs::read_to_string(path).unwrap());317    let text = doc318        .select(&Selector::parse(".line-text").unwrap())319        .map(|line| line.text().collect::<String>())320        .collect::<Vec<_>>()321        .join("\n");322    assert_eq!(text, source);323    assert_eq!(324        doc.select(&Selector::parse("script:not([src]),[onclick],[onerror]").unwrap())325            .count(),326        0327    );328    let keywords: Vec<_> = doc329        .select(&Selector::parse(".line-text .kw").unwrap())330        .map(|span| span.text().collect::<String>())331        .collect();332    assert_eq!(333        keywords.iter().filter(|text| text.as_str() == "fn").count(),334        1335    );336    assert!(337        doc.select(&Selector::parse(".line-text .string").unwrap())338            .any(|span| span.text().collect::<String>().contains("fn fake"))339    );340    assert!(341        doc.select(&Selector::parse(".line-text .comment").unwrap())342            .any(|span| span.text().collect::<String>().contains("still a comment"))343    );344    assert!(345        doc.select(&Selector::parse("#L8.diagnostic-line .diagnostic-marker").unwrap())346            .any(|link| link347                .text()348                .collect::<String>()349                .contains("clippy::clone_on_copy"))350    );351    let marked = doc352        .select(&Selector::parse("#L8 .diagnostic-span.primary").unwrap())353        .flat_map(|span| span.text())354        .collect::<String>();355    assert!(marked.contains("clone"));356    assert!(!marked.contains("pub fn"));357}358#[test]359fn reports_bundle_original_fonts_and_separate_licenses() {360    let f = Fixture::new("clean");361    assert_success(&f.run(&[]));362    let names = [363        "FiraSans-Regular-0fe48ade.woff2",364        "FiraSans-Italic-81dc35de.woff2",365        "FiraSans-Medium-e1aa3f0a.woff2",366        "FiraSans-MediumItalic-ccf7e434.woff2",367        "SourceSerif4-Regular-6b053e98.ttf.woff2",368        "SourceSerif4-It-ca3b17ed.ttf.woff2",369        "SourceSerif4-Semibold-457a13ac.ttf.woff2",370        "SourceSerif4-Bold-6d4fd4c0.ttf.woff2",371        "SourceCodePro-Regular-8badfe75.ttf.woff2",372        "SourceCodePro-It-fc8b9304.ttf.woff2",373        "SourceCodePro-Semibold-aa29a496.ttf.woff2",374        "NanumBarunGothic-13b3dcba.ttf.woff2",375    ];376    let mut total = 0;377    for name in names {378        let bytes =379            std::fs::read(f.report().join("static.files").join(name)).expect("bundled WOFF2");380        assert_eq!(&bytes[..4], b"wOF2");381        assert_eq!(382            bytes,383            std::fs::read(384                std::path::Path::new(env!("CARGO_MANIFEST_DIR"))385                    .join("assets/vendor/rustdoc/fonts")386                    .join(name)387            )388            .unwrap()389        );390        total += bytes.len();391    }392    assert_eq!(total, 1_386_044);393    let css = f.html("static.files/fonts.css");394    assert_eq!(css.matches("@font-face").count(), 12);395    assert!(!css.contains("Fira Mono"));396    for name in [397        "Fira-LICENSE.txt",398        "SourceSerif4-LICENSE.md",399        "SourceCodePro-LICENSE.txt",400        "NanumBarunGothic-LICENSE.txt",401    ] {402        let license = f.html(&format!("licenses/{name}"));403        assert!(license.contains("SIL OPEN FONT LICENSE Version 1.1"));404        assert!(license.contains("Reserved Font Name"));405        assert_eq!(406            license.as_bytes(),407            std::fs::read(408                std::path::Path::new(env!("CARGO_MANIFEST_DIR"))409                    .join("assets/vendor/rustdoc/fonts")410                    .join(name)411            )412            .unwrap()413        );414    }415    let doc = Html::parse_document(&f.html("index.html"));416    assert!(417        doc.select(&Selector::parse("link[rel=stylesheet]").unwrap())418            .any(|link| link.value().attr("href") == Some("static.files/fonts.css"))419    );420    assert!(f.html("licenses/index.html").contains("OFL-1.1"));421    assert!(422        f.html("licenses/generator-MIT.txt")423            .contains("Imagination12357")424    );425    assert!(426        f.html("licenses/THIRD-PARTY-NOTICES.md")427            .contains("OFL-1.1")428    );429}430#[test]431fn excluded_nested_dependency_is_snippet_only() {432    let f = Fixture::new("nested-dependency");433    assert_eq!(f.run(&[]).status.code(), Some(101));434    let files = html_files(&f.report().join("src"));435    assert!(!files.is_empty()); warning: clippy::assert_is_empty436    for path in files {437        let html = std::fs::read_to_string(path).unwrap();438        let doc = Html::parse_document(&html);439        assert_eq!(440            doc.select(&Selector::parse(".code-line").unwrap()).count(),441            0442        );443        assert!(!html.contains("DEPENDENCY_FULL_SOURCE_SENTINEL"));444        assert_eq!(445            doc.select(&Selector::parse(".source-tree a[aria-current=\"page\"]").unwrap())446                .count(),447            1448        );449        assert!(450            doc.select(&Selector::parse(".source-findings a").unwrap())451                .all(|a| a.value().attr("href").unwrap().starts_with("#finding-"))452        );453    }454}455#[test]456fn clean_cached_and_uncached_reports() {457    let f = Fixture::new("clean");458    for _ in 0..2 {459        assert_success(&f.run(&[]));460        let html = f.html("index.html");461        assert!(html.contains("Succeeded"));462        assert!(html.contains("0 unique"));463        assert!(html.contains("Complete"));464        assert!(html.contains("fixture-clean"));465    }466    assert!(!f.report().join("metadata.json").exists());467    assert!(f.report().join("licenses/rustdoc-MIT.txt").exists());468}469#[test]470fn warning_source_and_suggestion_are_escaped() { warning: clippy::too_many_lines471    let f = Fixture::new("warning");472    assert_success(&f.run(&[]));473    let lint = html_files(&f.report().join("lint"));474    assert_eq!(lint.len(), 1);475    assert!(f.report().join("lint/clippy/clone_on_copy.html").is_file());476    let doc = Html::parse_document(&std::fs::read_to_string(&lint[0]).unwrap());477    assert_eq!(doc.select(&Selector::parse(".finding").unwrap()).count(), 1);478    let diff = doc479        .select(&Selector::parse(".suggestion-diff[data-patch]").unwrap())480        .next()481        .expect("validated suggestion diff");482    let patch: String = serde_json::from_str(diff.value().attr("data-patch").unwrap()).unwrap();483    assert!(patch.contains("--- \"a/src/lib.rs\""));484    assert!(patch.contains("-pub fn copy_number(value: i32) -> i32 { value.clone() }"));485    assert!(patch.contains("+pub fn copy_number(value: i32) -> i32 { value }"));486    assert_eq!(487        diff.select(&Selector::parse("button").unwrap()).count(),488        0,489        "no-JS report keeps the diff readable without an inactive copy button"490    );491    assert_eq!(492        doc.select(&Selector::parse(".suggestion-unavailable").unwrap())493            .count(),494        0495    );496    assert!(497        doc.root_element()498            .text()499            .collect::<String>()500            .contains("MachineApplicable")501    );502    assert!(503        doc.select(&Selector::parse(".diagnostic-note a").unwrap())504            .any(|link| {505                link.value().attr("href").is_some_and(|href| {506                    href.starts_with("https://rust-lang.github.io/rust-clippy/")507                        && href.ends_with("/index.html#clone_on_copy")508                        && href == link.text().collect::<String>()509                })510            }),511        "Clippy's emitted further-information URL must remain clickable and unchanged"512    );513    let src = html_files(&f.report().join("src"));514    assert_eq!(src.len(), 1);515    assert!(f.report().join("src/lib.rs.html").is_file());516    let doc = Html::parse_document(&std::fs::read_to_string(&src[0]).unwrap());517    assert_eq!(518        doc.select(519            &Selector::parse(520                "#src-sidebar .dir-entry > .files > a.selected[aria-current=\"page\"]"521            )522            .unwrap()523        )524        .count(),525        1526    );527    assert_eq!(528        doc.select(&Selector::parse("#src-sidebar ul, #src-sidebar li").unwrap())529            .count(),530        0531    );532    assert_eq!(533        doc.select(&Selector::parse("#main-content > p > code").unwrap())534            .count(),535        0536    );537    assert_eq!(538        doc.select(&Selector::parse(".sidebar-elems #src-sidebar").unwrap())539            .count(),540        0541    );542    let active = doc543        .select(&Selector::parse(".source-tree a[aria-current=\"page\"]").unwrap())544        .next()545        .expect("active source file");546    assert!(active.text().collect::<String>().contains("lib.rs"));547    assert!(active.text().collect::<String>().contains("1")); warning: clippy::single_char_pattern548    let finding = doc549        .select(&Selector::parse(".source-findings a").unwrap())550        .next()551        .expect("finding line navigation");552    assert_eq!(finding.value().attr("href"), Some("#L3"));553    assert_eq!(554        doc.select(&Selector::parse("script:not([src]),[onclick],[onerror]").unwrap())555            .count(),556        0557    );558    assert!(559        doc.root_element()560            .text()561            .collect::<String>()562            .contains("<script>")563    );564    assert_eq!(565        doc.select(&Selector::parse(".code-line").unwrap()).count(),566        4567    );568    assert!(569        doc.select(&Selector::parse(".line-text .kw").unwrap())570            .any(|span| span.text().collect::<String>() == "fn")571    );572    assert!(573        doc.select(&Selector::parse(".line-text .doccomment").unwrap())574            .any(|span| span.text().collect::<String>().contains("<script>"))575    );576    let rendered_source = doc577        .select(&Selector::parse(".line-text").unwrap())578        .map(|line| line.text().collect::<String>())579        .collect::<Vec<_>>()580        .join("\n");581    assert_eq!(582        rendered_source,583        std::fs::read_to_string(f.root.join("src/lib.rs"))584            .unwrap()585            .replace("\r\n", "\n")586    );587}588#[test]589fn lint_and_compile_failure_keep_reports_and_exit_codes() {590    let f = Fixture::new("warning");591    let out = f.run(&["--", "--", "-D", "warnings"]);592    assert_eq!(593        out.status.code(),594        Some(101),595        "{}",596        String::from_utf8_lossy(&out.stderr)597    );598    assert!(f.html("index.html").contains("Failed"));599    assert!(f.html("index.html").contains("1 errors"));600    let e = Fixture::new("compile-error");601    let out = e.run(&[]);602    assert_eq!(out.status.code(), Some(101));603    assert!(e.html("index.html").contains("Failed"));604    assert!(e.report().join("lint/rustc/E0308.html").is_file());605    assert!(!html_files(&e.report().join("lint")).is_empty()); warning: clippy::assert_is_empty606}607#[test]608fn workspace_paths_unicode_and_multi_target_dedup() {609    let f = Fixture::new("workspace");610    assert_success(&f.run(&["--", "--workspace", "--all-targets"]));611    let html = f.html("index.html");612    assert!(html.contains("fixture-one"));613    assert!(html.contains("fixture-two"));614    let doc = Html::parse_document(&html);615    let crate_entries: Vec<_> = doc616        .select(&Selector::parse(".sidebar-crate .crate-info").unwrap())617        .map(|entry| entry.text().collect::<String>())618        .collect();619    assert!(620        crate_entries621            .iter()622            .any(|entry| entry.contains("fixture-one") && entry.contains("0.1.0"))623    );624    assert!(625        crate_entries626            .iter()627            .any(|entry| entry.contains("fixture-two") && entry.contains("0.2.0"))628    );629    assert_eq!(html_files(&f.report().join("src")).len(), 3);630    assert!(f.report().join("src/one/src/lib.rs.html").is_file());631    assert!(f.report().join("src/one/src/한글.rs.html").is_file());632    assert!(!html.contains("one/one/"));633    for file in html_files(&f.report().join("src")) {634        let source = std::fs::read_to_string(file).unwrap();635        let doc = Html::parse_document(&source);636        assert!(637            doc.select(638                &Selector::parse("#src-sidebar .dir-entry > summary + .folders + .files").unwrap()639            )640            .count()641                >= 2642        );643        assert_eq!(644            doc.select(&Selector::parse(".source-tree a[aria-current=\"page\"]").unwrap())645                .count(),646            1647        );648        assert!(649            doc.select(&Selector::parse(".source-tree details[open]").unwrap())650                .count()651                >= 2652        );653        assert!(654            doc.select(&Selector::parse(".source-tree details:not([open])").unwrap())655                .count()656                >= 1657        );658        assert!(659            doc.select(&Selector::parse(".code-line").unwrap()).count() > 0,660            "workspace source unexpectedly fell back"661        );662    }663    let lint = html_files(&f.report().join("lint"));664    assert_eq!(lint.len(), 1);665    let doc = Html::parse_document(&std::fs::read_to_string(&lint[0]).unwrap());666    assert_eq!(doc.select(&Selector::parse(".finding").unwrap()).count(), 5);667}668#[test]669fn output_and_target_dir_paths_follow_invocation_directory() {670    let f = Fixture::new("clean");671    assert_success(&f.run(&["--output", "report space", "--", "--target-dir", "cache"]));672    assert!(f.root.join("report space/index.html").is_file());673    assert!(!f.root.join("cache/clippy-html").exists());674    assert_success(&f.run(&["--", "--target-dir=cache"]));675    assert!(f.root.join("cache/clippy-html/index.html").is_file());676    let elsewhere = f.temp.path().join("elsewhere");677    std::fs::create_dir(&elsewhere).unwrap();678    let out = std::process::Command::new(env!("CARGO_BIN_EXE_cargo-clippy-html"))679        .current_dir(&elsewhere)680        .args(["--output", "relative-report", "--", "--manifest-path"])681        .arg(f.root.join("Cargo.toml"))682        .output()683        .unwrap();684    assert_success(&out);685    assert!(elsewhere.join("relative-report/index.html").exists());686}687#[test]688fn requires_metadata_path_and_preserves_unowned_directory() {689    let f = Fixture::new("clean");690    assert_eq!(f.run(&["--metadata"]).status.code(), Some(2));691    let folder = f.root.join("notes");692    std::fs::create_dir(&folder).unwrap();693    std::fs::write(folder.join("important.txt"), "keep").unwrap();694    assert!(!f.run(&["--output", "notes"]).status.success());695    assert_eq!(696        std::fs::read_to_string(folder.join("important.txt")).unwrap(),697        "keep"698    );699}700

Findings in this file§

warning clippy::assert_is_empty §

used `assert!` to check that a value is empty

tests/integration.rs:265:13

Clippy · Category: pedantic · cargo-clippy-html

Official Clippy documentation

Targets (1)
  • integration (test)

Primary: tests/integration.rs:265:13

            assert!(script.text().collect::<String>().is_empty());

Primary: tests/integration.rs:265:19

            assert!(script.text().collect::<String>().is_empty());

Primary: tests/integration.rs:265:21

            assert!(script.text().collect::<String>().is_empty());

help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.100.0/index.html#assert_is_empty

note: `-W clippy::assert-is-empty` implied by `-W clippy::pedantic`

help: to override `-W clippy::pedantic` add `#[allow(clippy::assert_is_empty)]`

help: use `assert_eq!` to show the value on failure

Suggestion: use `assert_eq!` to show the value on failure

MachineApplicable

--- "a/tests/integration.rs"
+++ "b/tests/integration.rs"
@@ -262,7 +262,7 @@
                 script.value().attr("defer").is_some(),
                 name != "settings-storage.js"
             );
-            assert!(script.text().collect::<String>().is_empty());
+            assert_eq!(script.text().collect::<String>(), "");
         }
         assert_eq!(
             doc.select(
Rendered diagnostic (text)
warning: used `assert!` to check that a value is empty
   --> tests/integration.rs:265:13
    |
265 |             assert!(script.text().collect::<String>().is_empty());
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.100.0/index.html#assert_is_empty
    = note: `-W clippy::assert-is-empty` implied by `-W clippy::pedantic`
    = help: to override `-W clippy::pedantic` add `#[allow(clippy::assert_is_empty)]`
help: use `assert_eq!` to show the value on failure
    |
265 -             assert!(script.text().collect::<String>().is_empty());
265 +             assert_eq!(script.text().collect::<String>(), "");
    |

warning clippy::bool_to_int_with_if §

boolean to int conversion using if

tests/integration.rs:273:13

Clippy · Category: pedantic · cargo-clippy-html

Official Clippy documentation

Targets (1)
  • integration (test)

Primary: tests/integration.rs:273:13

            if html.contains("id=\"back\"") { 0 } else { 1 }

note: `!html.contains("id=\"back\"") as usize` or `(!html.contains("id=\"back\"")).into()` can also be valid options

help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.100.0/index.html#bool_to_int_with_if

note: `-W clippy::bool-to-int-with-if` implied by `-W clippy::pedantic`

help: to override `-W clippy::pedantic` add `#[allow(clippy::bool_to_int_with_if)]`

help: replace with from

Suggestion: replace with from

MachineApplicable

--- "a/tests/integration.rs"
+++ "b/tests/integration.rs"
@@ -270,7 +270,7 @@
                     .unwrap()
             )
             .count(),
-            if html.contains("id=\"back\"") { 0 } else { 1 }
+            usize::from(!html.contains("id=\"back\""))
         );
         assert!(
             doc.select(&Selector::parse("body[data-report-root]").unwrap())
Rendered diagnostic (text)
warning: boolean to int conversion using if
   --> tests/integration.rs:273:13
    |
273 |             if html.contains("id=\"back\"") { 0 } else { 1 }
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with from: `usize::from(!html.contains("id=\"back\""))`
    |
    = note: `!html.contains("id=\"back\"") as usize` or `(!html.contains("id=\"back\"")).into()` can also be valid options
    = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.100.0/index.html#bool_to_int_with_if
    = note: `-W clippy::bool-to-int-with-if` implied by `-W clippy::pedantic`
    = help: to override `-W clippy::pedantic` add `#[allow(clippy::bool_to_int_with_if)]`

warning clippy::assert_is_empty §

used `assert!` to check that a value is not empty

tests/integration.rs:435:5

Clippy · Category: pedantic · cargo-clippy-html

Official Clippy documentation

Targets (1)
  • integration (test)

Primary: tests/integration.rs:435:5

    assert!(!files.is_empty());

Primary: tests/integration.rs:435:11

    assert!(!files.is_empty());

Primary: tests/integration.rs:435:13

    assert!(!files.is_empty());

help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.100.0/index.html#assert_is_empty

help: use `assert_ne!` to show the value on failure

Suggestion: use `assert_ne!` to show the value on failure

MachineApplicable

--- "a/tests/integration.rs"
+++ "b/tests/integration.rs"
@@ -432,7 +432,7 @@
     let f = Fixture::new("nested-dependency");
     assert_eq!(f.run(&[]).status.code(), Some(101));
     let files = html_files(&f.report().join("src"));
-    assert!(!files.is_empty());
+    assert_ne!(files, [] as [std::path::PathBuf; 0]);
     for path in files {
         let html = std::fs::read_to_string(path).unwrap();
         let doc = Html::parse_document(&html);
Rendered diagnostic (text)
warning: used `assert!` to check that a value is not empty
   --> tests/integration.rs:435:5
    |
435 |     assert!(!files.is_empty());
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.100.0/index.html#assert_is_empty
help: use `assert_ne!` to show the value on failure
    |
435 -     assert!(!files.is_empty());
435 +     assert_ne!(files, [] as [std::path::PathBuf; 0]);
    |

warning clippy::too_many_lines §

this function has too many lines (116/100)

tests/integration.rs:470:1

Clippy · Category: pedantic · cargo-clippy-html

Official Clippy documentation

Targets (1)
  • integration (test)

Primary: tests/integration.rs:470:1

fn warning_source_and_suggestion_are_escaped() {

help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.100.0/index.html#too_many_lines

note: `-W clippy::too-many-lines` implied by `-W clippy::pedantic`

help: to override `-W clippy::pedantic` add `#[allow(clippy::too_many_lines)]`

Rendered diagnostic (text)
warning: this function has too many lines (116/100)
   --> tests/integration.rs:470:1
    |
470 | fn warning_source_and_suggestion_are_escaped() {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.100.0/index.html#too_many_lines
    = note: `-W clippy::too-many-lines` implied by `-W clippy::pedantic`
    = help: to override `-W clippy::pedantic` add `#[allow(clippy::too_many_lines)]`

warning clippy::single_char_pattern §

single-character string constant used as pattern

tests/integration.rs:547:56

Clippy · Category: pedantic · cargo-clippy-html

Official Clippy documentation

Targets (1)
  • integration (test)

Primary: tests/integration.rs:547:56

    assert!(active.text().collect::<String>().contains("1"));

help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.100.0/index.html#single_char_pattern

note: `-W clippy::single-char-pattern` implied by `-W clippy::pedantic`

help: to override `-W clippy::pedantic` add `#[allow(clippy::single_char_pattern)]`

help: consider using a `char`

Suggestion: consider using a `char`

MachineApplicable

--- "a/tests/integration.rs"
+++ "b/tests/integration.rs"
@@ -544,7 +544,7 @@
         .next()
         .expect("active source file");
     assert!(active.text().collect::<String>().contains("lib.rs"));
-    assert!(active.text().collect::<String>().contains("1"));
+    assert!(active.text().collect::<String>().contains('1'));
     let finding = doc
         .select(&Selector::parse(".source-findings a").unwrap())
         .next()
Rendered diagnostic (text)
warning: single-character string constant used as pattern
   --> tests/integration.rs:547:56
    |
547 |     assert!(active.text().collect::<String>().contains("1"));
    |                                                        ^^^ help: consider using a `char`: `'1'`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.100.0/index.html#single_char_pattern
    = note: `-W clippy::single-char-pattern` implied by `-W clippy::pedantic`
    = help: to override `-W clippy::pedantic` add `#[allow(clippy::single_char_pattern)]`

warning clippy::assert_is_empty §

used `assert!` to check that a value is not empty

tests/integration.rs:605:5

Clippy · Category: pedantic · cargo-clippy-html

Official Clippy documentation

Targets (1)
  • integration (test)

Primary: tests/integration.rs:605:5

    assert!(!html_files(&e.report().join("lint")).is_empty());

Primary: tests/integration.rs:605:11

    assert!(!html_files(&e.report().join("lint")).is_empty());

Primary: tests/integration.rs:605:13

    assert!(!html_files(&e.report().join("lint")).is_empty());

help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.100.0/index.html#assert_is_empty

help: use `assert_ne!` to show the value on failure

Suggestion: use `assert_ne!` to show the value on failure

MachineApplicable

--- "a/tests/integration.rs"
+++ "b/tests/integration.rs"
@@ -602,7 +602,7 @@
     assert_eq!(out.status.code(), Some(101));
     assert!(e.html("index.html").contains("Failed"));
     assert!(e.report().join("lint/rustc/E0308.html").is_file());
-    assert!(!html_files(&e.report().join("lint")).is_empty());
+    assert_ne!(html_files(&e.report().join("lint")), [] as [std::path::PathBuf; 0]);
 }
 #[test]
 fn workspace_paths_unicode_and_multi_target_dedup() {
Rendered diagnostic (text)
warning: used `assert!` to check that a value is not empty
   --> tests/integration.rs:605:5
    |
605 |     assert!(!html_files(&e.report().join("lint")).is_empty());
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.100.0/index.html#assert_is_empty
help: use `assert_ne!` to show the value on failure
    |
605 -     assert!(!html_files(&e.report().join("lint")).is_empty());
605 +     assert_ne!(html_files(&e.report().join("lint")), [] as [std::path::PathBuf; 0]);
    |