Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
cli: Add better error for test not found
Alexis Sellier committed 3 years ago
commit e1986e45701972d4630284f095aec6c6bf4178ac
parent b2dbf12862e4f24dc291b1126598c0769c96a74a
1 file changed +10 -1
modified radicle-cli/tests/framework/mod.rs
@@ -15,6 +15,8 @@ const ERROR_PREFIX: &str = "==";
pub enum Error {
    #[error("parsing failed")]
    Parse,
+
    #[error("test file not found: {0:?}")]
+
    TestNotFound(PathBuf),
    #[error("i/o: {0}")]
    Io(#[from] io::Error),
    #[error("snapbox: {0}")]
@@ -92,7 +94,14 @@ impl TestFormula {
    }

    pub fn file(&mut self, path: impl AsRef<Path>) -> Result<&mut Self, Error> {
-
        let contents = fs::read(path)?;
+
        let path = path.as_ref();
+
        let contents = match fs::read(path) {
+
            Ok(bytes) => bytes,
+
            Err(err) if err.kind() == io::ErrorKind::NotFound => {
+
                return Err(Error::TestNotFound(path.to_path_buf()));
+
            }
+
            Err(err) => return Err(err.into()),
+
        };
        self.read(io::Cursor::new(contents))
    }