Repository: starship/starship
File: src/test/mod.rs (Rust)

Code before:
    pub fn collect(self) -> Option<String> {
        let ret = crate::print::get_module(self.name, self.context);
        // all tests rely on the fact that an empty module produces None as output as the
        // convention was that there would be no module but None. This is nowadays not anymore
        // the case (to get durations for all modules). So here we make it so, that an empty
        // module returns None in the tests...
        ret.filter(|s| !s.is_empty())
    }
}

#[derive(Clone, Copy)]
pub enum FixtureProvider {
    Fossil,
    Git,
    Hg,
    Pijul,
}

pub fn fixture_repo(provider: FixtureProvider) -> io::Result<TempDir> {
    match provider {
        FixtureProvider::Fossil => {
            let path = tempfile::tempdir()?;
            fs::OpenOptions::new()
                .create(true)
                .write(true)
                .open(path.path().join(".fslckout"))?;
            Ok(path)
        }
        FixtureProvider::Git => {
            let path = tempfile::tempdir()?;

            create_command("git")?
                .current_dir(path.path())
                .args(["clone", "-b", "master"])
                .arg(GIT_FIXTURE.as_os_str())
                .arg(path.path())
                .output()?;

            create_command("git")?
                .args(["config", "--local", "user.email", "starship@example.com"])
                .current_dir(path.path())
                .output()?;

            create_command("git")?
                .args(["config", "--local", "user.name", "starship"])
                .current_dir(path.path())
                .output()?;

            // Prevent intermittent test failures and ensure that the result of git commands
            // are available during I/O-contentious tests, by having git run `fsync`.
            // This is especially important on Windows.

Review comment (bug):
To reduce intermittent test failures:
```suggestion
                .open(path.path().join(".fslckout"))?
                .sync_all()?;
```

Code after:
    pub fn collect(self) -> Option<String> {
        let ret = crate::print::get_module(self.name, self.context);
        // all tests rely on the fact that an empty module produces None as output as the
        // convention was that there would be no module but None. This is nowadays not anymore
        // the case (to get durations for all modules). So here we make it so, that an empty
        // module returns None in the tests...
        ret.filter(|s| !s.is_empty())
    }
}

#[derive(Clone, Copy)]
pub enum FixtureProvider {
    Fossil,
    Git,
    Hg,
    Pijul,
}

pub fn fixture_repo(provider: FixtureProvider) -> io::Result<TempDir> {
    match provider {
        FixtureProvider::Fossil => {
            let path = tempfile::tempdir()?;
            fs::OpenOptions::new()
                .create(true)
                .write(true)
                .open(path.path().join(".fslckout"))?
                .sync_all()?;
            Ok(path)
        }
        FixtureProvider::Git => {
            let path = tempfile::tempdir()?;

            create_command("git")?
                .current_dir(path.path())
                .args(["clone", "-b", "master"])
                .arg(GIT_FIXTURE.as_os_str())
                .arg(path.path())
                .output()?;

            create_command("git")?
                .args(["config", "--local", "user.email", "starship@example.com"])
                .current_dir(path.path())
                .output()?;

            create_command("git")?
                .args(["config", "--local", "user.name", "starship"])
                .current_dir(path.path())
                .output()?;

            // Prevent intermittent test failures and ensure that the result of git commands
            // are available during I/O-contentious tests, by having git run `fsync`.