Permalink
Browse files

Setup initial layout of codebase. Began work on cd utility for shell.…

… Created tests for cd.
  • Loading branch information...
mgattozzi committed Jun 7, 2015
0 parents commit 9dd157da9ac6c104d46b1ac2fc3a00ae5a8485b3
Showing with 64 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +4 −0 Cargo.lock
  3. +4 −0 Cargo.toml
  4. 0 README.md
  5. +1 −0 src/lib.rs
  6. +10 −0 src/main.rs
  7. +43 −0 src/utils/cd.rs
  8. +1 −0 src/utils/mod.rs
@@ -0,0 +1 @@
target

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -0,0 +1,4 @@
[package]
name = "rusty"
version = "0.1.0"
authors = ["Michael Gattozzi <mgattozzi@gmail.com>"]
No changes.
@@ -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;

0 comments on commit 9dd157d

Please sign in to comment.