testtrim 0.14.9

Intelligently select automated tests to run via code coverage analysis
// SPDX-FileCopyrightText: 2024 Mathieu Fenniak <mathieu@fenniak.net>
//
// SPDX-License-Identifier: GPL-3.0-or-later

use std::{
    env,
    path::{Path, PathBuf},
};

pub struct ChangeWorkingDirectory {
    current_dir: PathBuf,
}

impl ChangeWorkingDirectory {
    pub fn new(path: &Path) -> Self {
        // FIXME: error handling?
        let current_dir = env::current_dir().unwrap();
        env::set_current_dir(path).unwrap();
        ChangeWorkingDirectory {
            current_dir: current_dir.to_path_buf(),
        }
    }
}

impl Drop for ChangeWorkingDirectory {
    fn drop(&mut self) {
        // FIXME: error handling?
        env::set_current_dir(&self.current_dir).unwrap();
    }
}