Skip to content

Commit

Permalink
Add a test for rust-lang#2076, preservation of line endings style
Browse files Browse the repository at this point in the history
  • Loading branch information
gkoz committed Oct 30, 2015
1 parent 59b73f1 commit 96c5b8f
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion tests/test_cargo_generate_lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::fs::File;
use std::io::prelude::*;

use support::{project, execs};
use hamcrest::assert_that;
use hamcrest::{assert_that, existing_file};

fn setup() {}

Expand Down Expand Up @@ -122,3 +122,52 @@ foo = "bar"
File::open(&lockfile).unwrap().read_to_string(&mut lock).unwrap();
assert!(lock.contains(metadata.trim()), "{}", lock);
});

test!(preserve_line_endings_issue_2076 {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
authors = []
version = "0.0.1"
"#)
.file("src/main.rs", "fn main() {}")
.file("bar/Cargo.toml", r#"
[package]
name = "bar"
authors = []
version = "0.0.1"
"#)
.file("bar/src/lib.rs", "");

let lockfile = p.root().join("Cargo.lock");
assert_that(p.cargo_process("generate-lockfile"),
execs().with_status(0));
assert_that(&lockfile,
existing_file());
assert_that(p.cargo("generate-lockfile"),
execs().with_status(0));

let mut lock0 = String::new();
{
File::open(&lockfile).unwrap().read_to_string(&mut lock0).unwrap();
}

assert!(lock0.starts_with("[root]\n"));

let lock1 = lock0.replace("\n", "\r\n");
{
File::create(&lockfile).unwrap().write_all(lock1.as_bytes()).unwrap();
}

assert_that(p.cargo("generate-lockfile"),
execs().with_status(0));

let mut lock2 = String::new();
{
File::open(&lockfile).unwrap().read_to_string(&mut lock2).unwrap();
}

assert!(lock2.starts_with("[root]\r\n"));
assert_eq!(lock1, lock2);
});

0 comments on commit 96c5b8f

Please sign in to comment.