Skip to content

Commit 22e7ede

Browse files
committed
Fix all tests from the update to rust master
1 parent cbed191 commit 22e7ede

11 files changed

+110
-75
lines changed

Cargo.lock

+18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+8-15
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,16 @@ term = "0.1.13"
2828
regex = "0.1.18"
2929
threadpool = "0.1.1"
3030
libc = "0.1.2"
31+
registry = { path = "src/registry" }
3132

32-
[target.i686-pc-windows-gnu.dependencies]
33-
winapi = "0.1"
34-
advapi32-sys = "*"
33+
[target.i686-pc-windows-gnu]
34+
dependencies = { winapi = "0.1", advapi32-sys = "*" }
35+
[target.x86_64-pc-windows-gnu]
36+
dependencies = { winapi = "0.1", advapi32-sys = "*" }
3537

36-
[target.x86_64-pc-windows-gnu.dependencies]
37-
winapi = "0.1"
38-
advapi32-sys = "*"
39-
40-
[dev-dependencies.hamcrest]
41-
git = "https://github.com/carllerche/hamcrest-rust.git"
42-
43-
[dependencies.registry]
44-
path = "src/registry"
38+
[dev-dependencies]
39+
tempdir = "0.3"
40+
hamcrest = { git = "https://github.com/carllerche/hamcrest-rust.git" }
4541

4642
[[bin]]
4743
name = "cargo"
@@ -50,9 +46,6 @@ doc = false
5046

5147
[[test]]
5248
name = "tests"
53-
[[bench]]
54-
name = "tests"
55-
path = "tests/tests.rs"
5649

5750
[[test]]
5851
name = "resolve"

src/bin/cargo.rs

+28-13
Original file line numberDiff line numberDiff line change
@@ -101,39 +101,54 @@ fn execute(flags: Flags, config: &Config) -> CliResult<Option<()>> {
101101
return Ok(None)
102102
}
103103

104-
let (mut args, command) = match &flags.arg_command[..] {
104+
let args = match &flags.arg_command[..] {
105+
// For the commands `cargo` and `cargo help`, re-execute ourselves as
106+
// `cargo -h` so we can go through the normal process of printing the
107+
// help message.
105108
"" | "help" if flags.arg_args.len() == 0 => {
106109
config.shell().set_verbose(true);
107-
let args = &["foo".to_string(), "-h".to_string()];
110+
let args = &["cargo".to_string(), "-h".to_string()];
108111
let r = cargo::call_main_without_stdin(execute, config, USAGE, args,
109112
false);
110-
cargo::process_executed(r, &mut **config.shell());
113+
cargo::process_executed(r, &mut config.shell());
111114
return Ok(None)
112115
}
116+
117+
// For `cargo help -h` and `cargo help --help`, print out the help
118+
// message for `cargo help`
113119
"help" if flags.arg_args[0] == "-h" ||
114-
flags.arg_args[0] == "--help" =>
115-
(flags.arg_args, "help"),
116-
"help" => (vec!["-h".to_string()], &flags.arg_args[0][..]),
117-
s => (flags.arg_args.clone(), s),
120+
flags.arg_args[0] == "--help" => {
121+
vec!["cargo".to_string(), "help".to_string(), "help".to_string()]
122+
}
123+
124+
// For `cargo help foo`, print out the usage message for the specified
125+
// subcommand by executing the command with the `-h` flag.
126+
"help" => {
127+
vec!["cargo".to_string(), "help".to_string(),
128+
flags.arg_args[0].clone()]
129+
}
130+
131+
// For all other invocations, we're of the form `cargo foo args...`. We
132+
// use the exact environment arguments to preserve tokens like `--` for
133+
// example.
134+
_ => env::args().collect(),
118135
};
119-
args.insert(0, command.to_string());
120-
args.insert(0, "foo".to_string());
121136

122137
macro_rules! cmd{ ($name:ident) => (
123-
if command == stringify!($name).replace("_", "-") {
138+
if args[1] == stringify!($name).replace("_", "-") {
124139
mod $name;
125140
config.shell().set_verbose(true);
126141
let r = cargo::call_main_without_stdin($name::execute, config,
127142
$name::USAGE,
128143
&args,
129144
false);
130-
cargo::process_executed(r, &mut **config.shell());
145+
cargo::process_executed(r, &mut config.shell());
131146
return Ok(None)
132147
}
133148
) }
134149
each_subcommand!(cmd);
135150

136-
execute_subcommand(&command, &args, &mut config.shell());
151+
execute_subcommand(&args[1], &args, &mut config.shell());
137152
Ok(None)
138153
}
139154

@@ -230,7 +245,7 @@ fn is_executable(path: &Path) -> bool {
230245
}
231246
#[cfg(windows)]
232247
fn is_executable(path: &Path) -> bool {
233-
path.is_file()
248+
fs::metadata(path).map(|m| m.is_file()) == Ok(true)
234249
}
235250

236251
/// Get `Command` to run given command.

tests/support/paths.rs

+24-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::env;
22
use std::fs;
33
use std::io::prelude::*;
4-
use std::io;
4+
use std::io::{self, ErrorKind};
55
use std::path::{Path, PathBuf};
66
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
77

@@ -32,7 +32,29 @@ impl CargoPathExt for Path {
3232
*/
3333
fn rm_rf(&self) -> io::Result<()> {
3434
if self.exists() {
35-
fs::remove_dir_all(self)
35+
for file in fs::read_dir(self).unwrap() {
36+
let file = try!(file).path();
37+
38+
if file.is_dir() {
39+
try!(file.rm_rf());
40+
} else {
41+
// On windows we can't remove a readonly file, and git will
42+
// often clone files as readonly. As a result, we have some
43+
// special logic to remove readonly files on windows.
44+
match fs::remove_file(&file) {
45+
Ok(()) => {}
46+
Err(ref e) if cfg!(windows) &&
47+
e.kind() == ErrorKind::PermissionDenied => {
48+
let mut p = file.metadata().unwrap().permissions();
49+
p.set_readonly(false);
50+
fs::set_permissions(&file, p).unwrap();
51+
try!(fs::remove_file(&file));
52+
}
53+
Err(e) => return Err(e)
54+
}
55+
}
56+
}
57+
fs::remove_dir(self)
3658
} else {
3759
Ok(())
3860
}

tests/support/registry.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ pub fn mock_pkg_yank(name: &str, version: &str, deps: &[(&str, &str, &str)],
8888
let file = match name.len() {
8989
1 => format!("1/{}", name),
9090
2 => format!("2/{}", name),
91-
3 => format!("3/{}/{}", name.slice_to(1), name),
92-
_ => format!("{}/{}/{}", name.slice(0, 2), name.slice(2, 4), name),
91+
3 => format!("3/{}/{}", &name[..1], name),
92+
_ => format!("{}/{}/{}", &name[0..2], &name[2..4], name),
9393
};
9494
publish(file.as_slice(), line.as_slice());
9595
}

tests/test_cargo_build_auth.rs

+17-33
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::collections::HashSet;
2-
use std::old_io::net::tcp::TcpAcceptor;
3-
use std::old_io::{TcpListener, Listener, Acceptor, BufferedStream};
2+
use std::io::BufStream;
3+
use std::io::prelude::*;
4+
use std::net::TcpListener;
45
use std::thread;
56
use git2;
67

@@ -11,23 +12,12 @@ use hamcrest::assert_that;
1112
fn setup() {
1213
}
1314

14-
struct Closer { a: TcpAcceptor }
15-
16-
impl Drop for Closer {
17-
fn drop(&mut self) {
18-
let _ = self.a.close_accept();
19-
}
20-
}
21-
2215
// Test that HTTP auth is offered from `credential.helper`
2316
test!(http_auth_offered {
24-
let mut listener = TcpListener::bind("127.0.0.1:0").unwrap();
25-
let addr = listener.socket_name().unwrap();
26-
let mut a = listener.listen().unwrap();
27-
let a2 = a.clone();
28-
let _c = Closer { a: a2 };
17+
let a = TcpListener::bind("127.0.0.1:0").unwrap();
18+
let addr = a.socket_addr().unwrap();
2919

30-
fn headers<R: Buffer>(rdr: &mut R) -> HashSet<String> {
20+
fn headers(rdr: &mut BufRead) -> HashSet<String> {
3121
let valid = ["GET", "Authorization", "Accept", "User-Agent"];
3222
rdr.lines().map(|s| s.unwrap())
3323
.take_while(|s| s.len() > 2)
@@ -39,7 +29,7 @@ test!(http_auth_offered {
3929
}
4030

4131
let t = thread::spawn(move|| {
42-
let mut s = BufferedStream::new(a.accept().unwrap());
32+
let mut s = BufStream::new(a.accept().unwrap().0);
4333
let req = headers(&mut s);
4434
s.write_all(b"\
4535
HTTP/1.1 401 Unauthorized\r\n\
@@ -53,7 +43,7 @@ test!(http_auth_offered {
5343
].into_iter().map(|s| s.to_string()).collect());
5444
drop(s);
5545

56-
let mut s = BufferedStream::new(a.accept().unwrap());
46+
let mut s = BufStream::new(a.accept().unwrap().0);
5747
let req = headers(&mut s);
5848
s.write_all(b"\
5949
HTTP/1.1 401 Unauthorized\r\n\
@@ -91,15 +81,15 @@ test!(http_auth_offered {
9181
script.display().to_string().as_slice()).unwrap();
9282

9383
let p = project("foo")
94-
.file("Cargo.toml", format!(r#"
84+
.file("Cargo.toml", &format!(r#"
9585
[project]
9686
name = "foo"
9787
version = "0.0.1"
9888
authors = []
9989
10090
[dependencies.bar]
10191
git = "http://127.0.0.1:{}/foo/bar"
102-
"#, addr.port).as_slice())
92+
"#, addr.port()))
10393
.file("src/main.rs", "");
10494

10595
assert_that(p.cargo_process("build").arg("-v"),
@@ -125,25 +115,22 @@ Caused by:
125115

126116
// Boy, sure would be nice to have a TLS implementation in rust!
127117
test!(https_something_happens {
128-
let mut listener = TcpListener::bind("127.0.0.1:0").unwrap();
129-
let addr = listener.socket_name().unwrap();
130-
let mut a = listener.listen().unwrap();
131-
let a2 = a.clone();
132-
let _c = Closer { a: a2 };
118+
let a = TcpListener::bind("127.0.0.1:0").unwrap();
119+
let addr = a.socket_addr().unwrap();
133120
let t = thread::spawn(move|| {
134121
drop(a.accept().unwrap());
135122
});
136123

137124
let p = project("foo")
138-
.file("Cargo.toml", format!(r#"
125+
.file("Cargo.toml", &format!(r#"
139126
[project]
140127
name = "foo"
141128
version = "0.0.1"
142129
authors = []
143130
144131
[dependencies.bar]
145132
git = "https://127.0.0.1:{}/foo/bar"
146-
"#, addr.port).as_slice())
133+
"#, addr.port()))
147134
.file("src/main.rs", "");
148135

149136
assert_that(p.cargo_process("build").arg("-v"),
@@ -175,11 +162,8 @@ Caused by:
175162

176163
// Boy, sure would be nice to have an SSH implementation in rust!
177164
test!(ssh_something_happens {
178-
let mut listener = TcpListener::bind("127.0.0.1:0").unwrap();
179-
let addr = listener.socket_name().unwrap();
180-
let mut a = listener.listen().unwrap();
181-
let a2 = a.clone();
182-
let _c = Closer { a: a2 };
165+
let a = TcpListener::bind("127.0.0.1:0").unwrap();
166+
let addr = a.socket_addr().unwrap();
183167
let t = thread::spawn(move|| {
184168
drop(a.accept().unwrap());
185169
});
@@ -193,7 +177,7 @@ test!(ssh_something_happens {
193177
194178
[dependencies.bar]
195179
git = "ssh://127.0.0.1:{}/foo/bar"
196-
"#, addr.port).as_slice())
180+
"#, addr.port()).as_slice())
197181
.file("src/main.rs", "");
198182

199183
assert_that(p.cargo_process("build").arg("-v"),

tests/test_cargo_compile.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::env;
2-
use std::fs::{self, TempDir, File};
2+
use std::fs::{self, File};
33
use std::io::prelude::*;
4+
use tempdir::TempDir;
45

56
use support::{project, execs, main_file, basic_bin_manifest};
67
use support::{COMPILING, RUNNING, ProjectBuilder};

tests/test_cargo_cross_compile.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ test!(plugin_deps {
142142
use rustc::plugin::Registry;
143143
use syntax::ast::TokenTree;
144144
use syntax::codemap::Span;
145-
use syntax::ext::base::{ExtCtxt, MacExpr, MacResult};
145+
use syntax::ext::base::{ExtCtxt, MacEager, MacResult};
146146
147147
#[plugin_registrar]
148148
pub fn foo(reg: &mut Registry) {
@@ -151,7 +151,7 @@ test!(plugin_deps {
151151
152152
fn expand_bar(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree])
153153
-> Box<MacResult + 'static> {
154-
MacExpr::new(quote_expr!(cx, 1))
154+
MacEager::expr(quote_expr!(cx, 1))
155155
}
156156
"#);
157157
let baz = project("baz")
@@ -222,7 +222,7 @@ test!(plugin_to_the_max {
222222
use rustc::plugin::Registry;
223223
use syntax::ast::TokenTree;
224224
use syntax::codemap::Span;
225-
use syntax::ext::base::{ExtCtxt, MacExpr, MacResult};
225+
use syntax::ext::base::{ExtCtxt, MacEager, MacResult};
226226
227227
#[plugin_registrar]
228228
pub fn foo(reg: &mut Registry) {
@@ -231,7 +231,7 @@ test!(plugin_to_the_max {
231231
232232
fn expand_bar(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree])
233233
-> Box<MacResult + 'static> {
234-
MacExpr::new(quote_expr!(cx, baz::baz()))
234+
MacEager::expr(quote_expr!(cx, baz::baz()))
235235
}
236236
"#);
237237
let baz = project("baz")

tests/test_cargo_new.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
use std::fs::{self, File, TempDir};
1+
use std::fs::{self, File};
22
use std::io::prelude::*;
33
use std::env;
4+
use tempdir::TempDir;
45

56
use support::{execs, paths, cargo_dir};
67
use hamcrest::{assert_that, existing_file, existing_dir, is_not};

0 commit comments

Comments
 (0)