Skip to content

Commit

Permalink
Add test-harness fs helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
9999years committed Aug 28, 2023
1 parent 5c23795 commit d098ec2
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

members = [
"ghcid-ng",
"test-harness",
]

resolver = "2"
10 changes: 10 additions & 0 deletions test-harness/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "test-harness"
version = "0.1.0"
edition = "2021"
description = "Test harness for ghcid-ng"
publish = false

[dependencies]
miette = { version = "5.9.0", features = ["fancy"] }
tokio = { version = "1.28.2", features = ["full", "tracing"] }
35 changes: 35 additions & 0 deletions test-harness/src/fs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use std::fmt::Display;
use std::path::Path;

use miette::Context;
use miette::IntoDiagnostic;
use tokio::fs::OpenOptions;
use tokio::io::AsyncWriteExt;

/// Touch a path.
pub async fn touch(path: impl AsRef<Path>) -> miette::Result<()> {
let path = path.as_ref();
OpenOptions::new()
.create(true)
.write(true)
.open(path)
.await
.into_diagnostic()
.wrap_err_with(|| format!("Failed to touch {path:?}"))
.map(|_| ())
}

/// Append some data to a path.
pub async fn append(path: impl AsRef<Path>, data: impl Display) -> miette::Result<()> {
let path = path.as_ref();
let mut file = OpenOptions::new()
.append(true)
.open(path)
.await
.into_diagnostic()
.wrap_err_with(|| format!("Failed to open {path:?}"))?;
file.write_all(data.to_string().as_bytes())
.await
.into_diagnostic()?;
Ok(())
}
1 change: 1 addition & 0 deletions test-harness/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod fs;

0 comments on commit d098ec2

Please sign in to comment.