#[deriving(Eq,Clone)]
struct FileBuilder {
path: Path,
- body: ~str
+ body: String
}
impl FileBuilder {
FileBuilder { path: path, body: body.to_owned() }
}
- fn mk(&self) -> Result<(), ~str> {
+ fn mk(&self) -> Result<(), String> {
try!(mkdir_recursive(&self.dirname()));
let mut file = try!(
#[deriving(Eq,Clone)]
struct ProjectBuilder {
- name: ~str,
+ name: String,
root: Path,
files: Vec<FileBuilder>
}
}
}
- pub fn build_with_result(&self) -> Result<(), ~str> {
+ pub fn build_with_result(&self) -> Result<(), String> {
// First, clean the directory if it already exists
try!(self.rm_root());
Ok(())
}
- fn rm_root(&self) -> Result<(), ~str> {
+ fn rm_root(&self) -> Result<(), String> {
if self.root.exists() {
rmdir_recursive(&self.root)
}
// === Helpers ===
-pub fn mkdir_recursive(path: &Path) -> Result<(), ~str> {
+pub fn mkdir_recursive(path: &Path) -> Result<(), String> {
fs::mkdir_recursive(path, io::UserDir)
.with_err_msg(format!("could not create directory; path={}", path.display()))
}
-pub fn rmdir_recursive(path: &Path) -> Result<(), ~str> {
+pub fn rmdir_recursive(path: &Path) -> Result<(), String> {
fs::rmdir_recursive(path)
.with_err_msg(format!("could not rm directory; path={}", path.display()))
}
trait ErrMsg<T> {
- fn with_err_msg(self, val: ~str) -> Result<T, ~str>;
+ fn with_err_msg(self, val: String) -> Result<T, String>;
}
impl<T, E: Show> ErrMsg<T> for Result<T, E> {
- fn with_err_msg(self, val: ~str) -> Result<T, ~str> {
+ fn with_err_msg(self, val: String) -> Result<T, String> {
match self {
Ok(val) => Ok(val),
Err(err) => Err(format!("{}; original={}", val, err))
#[deriving(Clone,Eq)]
struct Execs {
- expect_stdout: Option<~str>,
- expect_stdin: Option<~str>,
- expect_stderr: Option<~str>,
+ expect_stdout: Option<String>,
+ expect_stdin: Option<String>,
+ expect_stderr: Option<String>,
expect_exit_code: Option<int>
}
self.match_std(&self.expect_stderr, actual, "stderr")
}
- fn match_std(&self, expected: &Option<~str>, actual: &Vec<u8>, description: &str) -> ham::MatchResult {
+ fn match_std(&self, expected: &Option<String>, actual: &Vec<u8>, description: &str) -> ham::MatchResult {
match expected.as_ref().map(|s| s.as_slice()) {
None => ham::success(),
Some(out) => {
}
impl ham::SelfDescribing for Execs {
- fn describe(&self) -> ~str {
+ fn describe(&self) -> String {
"execs".to_owned()
}
}
fn setup() {
}
-fn basic_bin_manifest(name: &str) -> ~str {
+fn basic_bin_manifest(name: &str) -> String {
format!(r#"
[project]
test!(cargo_compile {
let p = project("foo")
- .file("Cargo.toml", basic_bin_manifest("foo"))
- .file("src/foo.rs", main_file(r#""i am foo""#, []));
+ .file("Cargo.toml", basic_bin_manifest("foo").as_slice())
+ .file("src/foo.rs", main_file(r#""i am foo""#, []).as_slice());
assert_that(p.cargo_process("cargo-compile"), execs());
assert_that(&p.root().join("target/foo"), existing_file());
test!(cargo_compile_with_invalid_code {
let p = project("foo")
- .file("Cargo.toml", basic_bin_manifest("foo"))
+ .file("Cargo.toml", basic_bin_manifest("foo").as_slice())
.file("src/foo.rs", "invalid rust code!");
let target = p.root().join("target");
assert_that(p.cargo_process("cargo-compile"),
execs()
.with_status(101)
- .with_stderr(format!("src/foo.rs:1:1: 1:8 error: expected item but found `invalid`\nsrc/foo.rs:1 invalid rust code!\n ^~~~~~~\nfailed to execute: `rustc src/foo.rs --crate-type bin --out-dir {} -L {}`", target.display(), target.display())));
+ .with_stderr(format!("src/foo.rs:1:1: 1:8 error: expected item but found `invalid`\nsrc/foo.rs:1 invalid rust code!\n ^~~~~~~\nfailed to execute: `rustc src/foo.rs --crate-type bin --out-dir {} -L {}`", target.display(), target.display()).as_slice()));
})
test!(cargo_compile_with_warnings_in_the_root_package {
let p = project("foo")
- .file("Cargo.toml", basic_bin_manifest("foo"))
+ .file("Cargo.toml", basic_bin_manifest("foo").as_slice())
.file("src/foo.rs", "fn main() {} fn dead() {}");
assert_that(p.cargo_process("cargo-compile"),
p = p
.file(".cargo/config", format!(r#"
paths = ["{}"]
- "#, bar.display()))
+ "#, bar.display()).as_slice())
.file("Cargo.toml", r#"
[project]
name = "foo"
"#)
- .file("src/foo.rs", main_file(r#""{}", bar::gimme()"#, ["bar"]))
+ .file("src/foo.rs", main_file(r#""{}", bar::gimme()"#, ["bar"]).as_slice())
.file("bar/Cargo.toml", r#"
[project]
name = "bar"
"#)
.file("bar/src/bar.rs", r#"
- pub fn gimme() -> ~str {
+ pub fn gimme() -> String {
"test passed".to_owned()
}
p = p
.file(".cargo/config", format!(r#"
paths = ["{}", "{}"]
- "#, bar.display(), baz.display()))
+ "#, bar.display(), baz.display()).as_slice())
.file("Cargo.toml", r#"
[project]
name = "foo"
"#)
- .file("src/foo.rs", main_file(r#""{}", bar::gimme()"#, ["bar"]))
+ .file("src/foo.rs", main_file(r#""{}", bar::gimme()"#, ["bar"]).as_slice())
.file("bar/Cargo.toml", r#"
[project]
.file("bar/src/bar.rs", r#"
extern crate baz;
- pub fn gimme() -> ~str {
+ pub fn gimme() -> String {
baz::gimme()
}
"#)
name = "baz"
"#)
.file("baz/src/baz.rs", r#"
- pub fn gimme() -> ~str {
+ pub fn gimme() -> String {
"test passed".to_owned()
}
"#);
execs().with_stdout("test passed\n"));
})
-fn main_file(println: &str, deps: &[&str]) -> ~str {
- let mut buf = StrBuf::new();
+fn main_file(println: &str, deps: &[&str]) -> String {
+ let mut buf = String::new();
for dep in deps.iter() {
- buf.push_str(format!("extern crate {};\n", dep));
+ buf.push_str(format!("extern crate {};\n", dep).as_slice());
}
buf.push_str("fn main() { println!(");