Skip to content

Commit

Permalink
Merge pull request #527 from stlankes/file
Browse files Browse the repository at this point in the history
using an absolute path to create a file
  • Loading branch information
stlankes authored Feb 4, 2024
2 parents c9b59b7 + 6f5f068 commit 5e6d779
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 5e6d779

Please sign in to comment.