Skip to content

Commit

Permalink
current_dir (#20)
Browse files Browse the repository at this point in the history
* current_dir

* current_dir test

* lib
  • Loading branch information
sergey-shandar authored Mar 10, 2024
1 parent 71c01d7 commit 6ef2dd5
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 6 deletions.
4 changes: 2 additions & 2 deletions io-impl/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "io-impl"
version = "0.9.0"
version = "0.10.0"
edition = "2021"
description = "I/O implementations"
authors.workspace = true
Expand All @@ -10,5 +10,5 @@ repository.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
io-trait = { path = "../io-trait", version = "0.9.0" }
io-trait = { path = "../io-trait", version = "0.10.0" }
libc.workspace = true
12 changes: 11 additions & 1 deletion io-impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mod windows;
mod windows_api;

use std::{
env::{args, Args},
env::{args, current_dir, Args},
fs::{self, create_dir, File},
io::{self, Stdout},
time::Instant,
Expand Down Expand Up @@ -57,6 +57,10 @@ impl Io for RealIo {
fn now(&self) -> Instant {
Instant::now()
}

fn current_dir(&self) -> io::Result<String> {
current_dir().map(|x| x.to_string_lossy().to_string())
}
}

#[cfg(test)]
Expand Down Expand Up @@ -104,4 +108,10 @@ mod test {
let io = super::RealIo::default();
let _ = io.now();
}

#[test]
fn test_current_dir() {
let io = super::RealIo::default();
let _ = io.current_dir();
}
}
4 changes: 2 additions & 2 deletions io-test/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "io-test"
version = "0.9.0"
version = "0.10.0"
edition = "2021"
description = "I/O implementations for testing"
authors.workspace = true
Expand All @@ -10,7 +10,7 @@ repository.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
io-trait = { path = "../io-trait", version = "0.9.0" }
io-trait = { path = "../io-trait", version = "0.10.0" }

[dev-dependencies]
wasm-bindgen-test.workspace = true
5 changes: 5 additions & 0 deletions io-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,10 @@ impl Io for VirtualIo {
*d = d.add(Duration::from_millis(1));
result
}

fn current_dir(&self) -> io::Result<String> {
Ok(String::default())
}
}

#[cfg(test)]
Expand All @@ -316,6 +320,7 @@ mod test {
let result = io.read_to_string("test.txt").unwrap();
assert_eq!(result, "Hello, world!");
assert_eq!(io.metadata("test.txt").unwrap().len(), 13);
assert_eq!(io.current_dir().unwrap(), "");
}

#[wasm_bindgen_test]
Expand Down
2 changes: 1 addition & 1 deletion io-trait/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "io-trait"
version = "0.9.0"
version = "0.10.0"
edition = "2021"
description = "I/O traits"
authors.workspace = true
Expand Down
1 change: 1 addition & 0 deletions io-trait/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,5 @@ pub trait Io: Sized {
}
Ok(result)
}
fn current_dir(&self) -> io::Result<String>;
}

0 comments on commit 6ef2dd5

Please sign in to comment.