Skip to content

Commit 5837296

Browse files
committed
Fix tests on OSX
Closes #20
1 parent 072eb8a commit 5837296

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

src/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ impl Config {
220220
/// let cfg = Config::new().unwrap();
221221
///
222222
/// for entry in &cfg.entries(None).unwrap() {
223-
/// println!("{} => {}", entry.name(), entry.value());
223+
/// println!("{} => {:?}", entry.name(), entry.value());
224224
/// }
225225
/// ```
226226
pub fn entries(&self, glob: Option<&str>) -> Result<ConfigEntries, Error> {

src/repo.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1251,7 +1251,8 @@ mod tests {
12511251
assert!(!repo.is_bare());
12521252
assert!(!repo.is_shallow());
12531253
assert!(repo.is_empty().unwrap());
1254-
assert_eq!(repo.path(), td.path().join(".git"));
1254+
assert_eq!(::test::realpath(&repo.path()),
1255+
::test::realpath(&td.path().join(".git")));
12551256
assert_eq!(repo.state(), ::RepositoryState::Clean);
12561257
}
12571258

@@ -1263,7 +1264,8 @@ mod tests {
12631264

12641265
let repo = Repository::open(path).unwrap();
12651266
assert!(repo.is_bare());
1266-
assert_eq!(repo.path(), *td.path());
1267+
assert_eq!(::test::realpath(&repo.path()),
1268+
::test::realpath(td.path()));
12671269
}
12681270

12691271
#[test]
@@ -1301,7 +1303,8 @@ mod tests {
13011303
let subdir = TempDir::new_in(td.path(), "subdir").unwrap();
13021304
Repository::init_bare(td.path()).unwrap();
13031305
let repo = Repository::discover(subdir.path()).unwrap();
1304-
assert_eq!(repo.path(), *td.path());
1306+
assert_eq!(::test::realpath(&repo.path()),
1307+
::test::realpath(td.path()));
13051308
}
13061309

13071310
fn graph_repo_init() -> (TempDir, Repository) {

src/test.rs

+34
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
use std::io::TempDir;
2+
use std::io::{self, fs};
3+
use std::os;
24
use Repository;
35

46
pub fn repo_init() -> (TempDir, Repository) {
@@ -18,3 +20,35 @@ pub fn repo_init() -> (TempDir, Repository) {
1820
}
1921
(td, repo)
2022
}
23+
24+
// Copied from rustc
25+
pub fn realpath(original: &Path) -> io::IoResult<Path> {
26+
static MAX_LINKS_FOLLOWED: u32 = 256;
27+
let original = os::make_absolute(original).unwrap();
28+
// Right now lstat on windows doesn't work quite well
29+
if cfg!(windows) {
30+
return Ok(original)
31+
}
32+
let result = original.root_path();
33+
let mut result = result.expect("make_absolute has no root_path");
34+
let mut followed = 0;
35+
for part in original.components() {
36+
result.push(part);
37+
loop {
38+
if followed == MAX_LINKS_FOLLOWED {
39+
return Err(io::standard_error(io::InvalidInput))
40+
}
41+
match fs::lstat(&result) {
42+
Err(..) => break,
43+
Ok(ref stat) if stat.kind != io::FileType::Symlink => break,
44+
Ok(..) => {
45+
followed += 1;
46+
let path = try!(fs::readlink(&result));
47+
result.pop();
48+
result.push(path);
49+
}
50+
}
51+
}
52+
}
53+
return Ok(result);
54+
}

0 commit comments

Comments
 (0)