Skip to content

Commit

Permalink
using an absolute path to create a file
Browse files Browse the repository at this point in the history
  • Loading branch information
stlankes committed Feb 4, 2024
1 parent 3b0cedd commit 6f5f068
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions examples/demo/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,19 @@ pub fn read_dir() -> Result<(), std::io::Error> {

pub fn create_file() -> Result<(), std::io::Error> {
{
let mut file = File::create("foo.txt")?;
let mut file = File::create("/tmp/foo.txt")?;
file.write_all(b"Hello, world!")?;
}

let content = {
let mut file = File::open("foo.txt")?;
let mut file = File::open("/tmp/foo.txt")?;
let mut content = String::new();
file.read_to_string(&mut content)?;
content
};

// delete temporary file
std::fs::remove_file("foo.txt")?;
std::fs::remove_file("/tmp/foo.txt")?;

if content == "Hello, world!" {
Ok(())
Expand Down

0 comments on commit 6f5f068

Please sign in to comment.