-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
members = [ | ||
"ghcid-ng", | ||
"test-harness", | ||
] | ||
|
||
resolver = "2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod fs; |