Repository: astral-sh/ruff
File: crates/ruff/src/lib.rs (Rust)

Code before:
            }),
        );
        assert_eq!(
            Some(ChangeKind::Configuration),
            change_detected(&notify::Event {
                kind: notify::EventKind::Create(notify::event::CreateKind::File),
                paths: vec![
                    PathBuf::from("tmp/rule.py"),
                    PathBuf::from("pyproject.toml"),
                ],
                attrs: notify::event::EventAttributes::default(),
            }),
        );
        assert_eq!(
            None,
            change_detected(&notify::Event {
                kind: notify::EventKind::Create(notify::event::CreateKind::File),
                paths: vec![
                    PathBuf::from("tmp/rule.js"),
                    PathBuf::from("tmp/bin/ruff.rs"),
                ],
                attrs: notify::event::EventAttributes::default(),
            }),
        );
    }
}

#[cfg(test)]
mod test_set_colored_override {
    use crate::{args::TerminalColor, set_colored_override};

    #[test]
    fn force_color_env_is_respected() {
        colored::control::unset_override();
        set_colored_override(true, None);
        assert!(colored::control::SHOULD_COLORIZE.should_colorize());
        colored::control::unset_override();
    }

    #[test]
    fn cli_args_takes_precedences_over_force_color_env() {
        colored::control::unset_override();
        set_colored_override(true, Some(TerminalColor::Never));
        assert!(!colored::control::SHOULD_COLORIZE.should_colorize());

        colored::control::unset_override();
        set_colored_override(false, Some(TerminalColor::Always));
        assert!(colored::control::SHOULD_COLORIZE.should_colorize());

        colored::control::unset_override();
    }

Review comment (suggestion):
Unfortunately, we can't keep those unit tests as they'll mess up the colored output of other tests (they modify global state). 

If you want to test this code, I suggest changing `set_colored_override` to `colored_override(color_option: Option<TerminalColor>, force_color_env: Option<OsString>) -> Option<bool>`

Code after:
            Some(ChangeKind::Configuration),
            change_detected(&notify::Event {
                kind: notify::EventKind::Create(notify::event::CreateKind::File),
                paths: vec![
                    PathBuf::from("tmp/rule.py"),
                    PathBuf::from("pyproject.toml"),
                ],
                attrs: notify::event::EventAttributes::default(),
            }),
        );
        assert_eq!(
            None,
            change_detected(&notify::Event {
                kind: notify::EventKind::Create(notify::event::CreateKind::File),
                paths: vec![
                    PathBuf::from("tmp/rule.js"),
                    PathBuf::from("tmp/bin/ruff.rs"),
                ],
                attrs: notify::event::EventAttributes::default(),
            }),
        );
    }
}

#[cfg(test)]
mod test_set_colored_override {
    use crate::{args::TerminalColor, colored_override};

    #[test]
    fn force_color_env_is_respected() {
        assert_eq!(colored_override(None, Some("1".into())), Some(true));
    }

    #[test]
    fn cli_args_takes_precedences_over_force_color_env() {
        assert_eq!(
            colored_override(Some(TerminalColor::Never), Some("1".into())),
            Some(false)
        );

        assert_eq!(
            colored_override(Some(TerminalColor::Always), None),
            Some(true)
        );
    }
}