Skip to content

Commit b625a2b

Browse files
authored
Merge pull request #105 from Shopify/add-tests-hash
Add tests for lang.rs and shadowenv.rs
2 parents f89c816 + fccee4c commit b625a2b

File tree

6 files changed

+386
-199
lines changed

6 files changed

+386
-199
lines changed

src/execcmd.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@ use std::vec::Vec;
55

66
/// Execute the provided command (argv) after loading the environment from the current directory
77
pub fn run(pathbuf: PathBuf, shadowenv_data: String, argv: Vec<&str>) -> Result<(), Error> {
8-
match hook::load_env(pathbuf, shadowenv_data, true)? {
9-
Some((shadowenv, _)) => {
10-
hook::mutate_own_env(&shadowenv)?;
11-
}
12-
None => (),
8+
if let Some((shadowenv, _)) = hook::load_env(pathbuf, shadowenv_data, true)? {
9+
hook::mutate_own_env(&shadowenv)?;
1310
}
1411

1512
// exec only returns if it was unable to start the new process, and it's always an error.

src/features.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,7 @@ pub struct Feature {
88

99
impl Feature {
1010
pub fn new(name: String, version: Option<String>) -> Self {
11-
Feature {
12-
name: name,
13-
version: version,
14-
}
15-
}
16-
17-
pub fn name(&self) -> &String {
18-
&self.name
19-
}
20-
21-
pub fn version(&self) -> &Option<String> {
22-
&self.version
11+
Feature { name, version }
2312
}
2413
}
2514

src/hook.rs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
use crate::hash::{Hash, Source};
22
use crate::lang;
3-
use crate::lang::ShadowLang;
43
use crate::loader;
54
use crate::output;
65
use crate::shadowenv::Shadowenv;
76
use crate::trust;
87
use crate::undo;
98
use serde_derive::Serialize;
10-
use serde_json;
119

1210
use std::borrow::Cow;
1311
use std::collections::HashMap;
1412
use std::env;
1513
use std::path::PathBuf;
16-
use std::rc::Rc;
1714
use std::result::Result;
1815
use std::str::FromStr;
1916

17+
use crate::lang::ShadowLang;
2018
use failure::Error;
2119
use shell_escape as shell;
2220

@@ -94,22 +92,19 @@ pub fn load_env(
9492
};
9593

9694
let data = undo::Data::from_str(json_data)?;
97-
let shadowenv = Rc::new(Shadowenv::new(env::vars().collect(), data, target_hash));
95+
let shadowenv = Shadowenv::new(env::vars().collect(), data, target_hash);
9896

99-
let activation = match target {
97+
match target {
10098
Some(target) => {
101-
if let Err(_) = ShadowLang::run_program(shadowenv.clone(), target) {
102-
// no need to return anything descriptive here since we already had ketos print it
103-
// to stderr.
104-
return Err(lang::ShadowlispError {}.into());
99+
match ShadowLang::run_program(shadowenv, target) {
100+
// no need to return anything descriptive here since we already
101+
// had ketos print it to stderr.
102+
Err(_) => Err(lang::ShadowlispError {}.into()),
103+
Ok(shadowenv) => Ok(Some((shadowenv, true))),
105104
}
106-
true
107105
}
108-
None => false,
109-
};
110-
111-
let shadowenv = Rc::try_unwrap(shadowenv).unwrap();
112-
Ok(Some((shadowenv, activation)))
106+
None => Ok(Some((shadowenv, false))),
107+
}
113108
}
114109

115110
/// Load a Source from the current dir, ensuring that it is trusted.

0 commit comments

Comments
 (0)