This repository has been archived by the owner. It is now read-only.
Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Setup initial layout of codebase. Began work on cd utility for shell.…
… Created tests for cd.
- Loading branch information
Showing
with
64 additions
and 0 deletions.
- +1 −0 .gitignore
- +4 −0 Cargo.lock
- +4 −0 Cargo.toml
- 0 README.md
- +1 −0 src/lib.rs
- +10 −0 src/main.rs
- +43 −0 src/utils/cd.rs
- +1 −0 src/utils/mod.rs
@@ -0,0 +1 @@ | ||
target |
@@ -0,0 +1,4 @@ | ||
[package] | ||
name = "rusty" | ||
version = "0.1.0" | ||
authors = ["Michael Gattozzi <mgattozzi@gmail.com>"] |
Empty file.
@@ -0,0 +1 @@ | ||
pub mod utils; |
@@ -0,0 +1,10 @@ | ||
|
||
extern crate rusty; | ||
|
||
use rusty::utils::cd; | ||
use std::path::Path; | ||
|
||
fn main() { | ||
println!("Hello, world!"); | ||
cd::change_directory(Path::new("..")); | ||
} |
@@ -0,0 +1,43 @@ | ||
use std::path::Path; | ||
use std::env; | ||
|
||
pub fn change_directory(directory: &Path){ | ||
let mut dir = directory; | ||
if dir.is_relative(){ | ||
println!("dir is relative"); | ||
} else { | ||
println!("dir is absolute"); | ||
} | ||
|
||
env::set_current_dir(dir).unwrap(); | ||
} | ||
|
||
|
||
|
||
#[cfg(test)] | ||
mod tests { | ||
use std::path::Path; | ||
use std::env; | ||
use super::*; | ||
|
||
#[test] | ||
#[should_panic] | ||
fn test_change_directory_ok(){ | ||
let mut dir = Path::new("/tmp").to_str(); | ||
change_directory(Path::new("/")); | ||
let new_dir = env::current_dir().unwrap(); | ||
let new_dir = new_dir.to_str(); | ||
assert_eq!(dir, new_dir); | ||
} | ||
|
||
#[test] | ||
fn test_change_directory_fail(){ | ||
let mut dir = Path::new("/").to_str(); | ||
change_directory(Path::new("/")); | ||
let new_dir = env::current_dir().unwrap(); | ||
let new_dir = new_dir.to_str(); | ||
assert_eq!(dir, new_dir); | ||
} | ||
|
||
} | ||
|
@@ -0,0 +1 @@ | ||
pub mod cd; |