Skip to content

Rewrite fileinput tests to use std::rt::io #9141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions src/libextra/fileinput.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,20 +417,23 @@ mod test {

use super::{FileInput, make_path_option_vec, input_vec, input_vec_state};

use std::io;
use std::rt::io;
use std::rt::io::Writer;
use std::rt::io::file;
use std::uint;
use std::vec;

fn make_file(path : &Path, contents: &[~str]) {
let file = io::file_writer(path, [io::Create, io::Truncate]).unwrap();
let mut file = file::open(path, io::CreateOrTruncate, io::Write).unwrap();

for str in contents.iter() {
file.write_str(*str);
file.write_char('\n');
file.write(str.as_bytes());
file.write(['\n' as u8]);
}
}

#[test]
#[ignore(cfg(windows))] // FIXME(#8810): rt::io::file and windows don't agree
fn test_make_path_option_vec() {
let strs = [~"some/path",
~"some/other/path"];
Expand All @@ -445,6 +448,7 @@ mod test {
}

#[test]
#[ignore(cfg(windows))] // FIXME(#8810): rt::io::file and windows don't agree
fn test_fileinput_read_byte() {
let filenames = make_path_option_vec(vec::from_fn(
3,
Expand Down Expand Up @@ -475,6 +479,7 @@ mod test {
}

#[test]
#[ignore(cfg(windows))] // FIXME(#8810): rt::io::file and windows don't agree
fn test_fileinput_read() {
let filenames = make_path_option_vec(vec::from_fn(
3,
Expand All @@ -495,6 +500,7 @@ mod test {
}

#[test]
#[ignore(cfg(windows))] // FIXME(#8810): rt::io::file and windows don't agree
fn test_input_vec() {
let mut all_lines = ~[];
let filenames = make_path_option_vec(vec::from_fn(
Expand All @@ -518,6 +524,7 @@ mod test {
}

#[test]
#[ignore(cfg(windows))] // FIXME(#8810): rt::io::file and windows don't agree
fn test_input_vec_state() {
let filenames = make_path_option_vec(vec::from_fn(
3,
Expand All @@ -540,6 +547,7 @@ mod test {
}

#[test]
#[ignore(cfg(windows))] // FIXME(#8810): rt::io::file and windows don't agree
fn test_empty_files() {
let filenames = make_path_option_vec(vec::from_fn(
3,
Expand All @@ -564,18 +572,21 @@ mod test {
}

#[test]
#[ignore(cfg(windows))] // FIXME(#8810): rt::io::file and windows don't agree
fn test_no_trailing_newline() {
let f1 =
Some(Path("tmp/lib-fileinput-test-no-trailing-newline-1.tmp"));
let f2 =
Some(Path("tmp/lib-fileinput-test-no-trailing-newline-2.tmp"));

let wr = io::file_writer(f1.get_ref(),
[io::Create, io::Truncate]).unwrap();
wr.write_str("1\n2");
let wr = io::file_writer(f2.get_ref(),
[io::Create, io::Truncate]).unwrap();
wr.write_str("3\n4");
{
let mut wr = file::open(f1.get_ref(), io::CreateOrTruncate,
io::Write).unwrap();
wr.write("1\n2".as_bytes());
let mut wr = file::open(f2.get_ref(), io::CreateOrTruncate,
io::Write).unwrap();
wr.write("3\n4".as_bytes());
}

let mut lines = ~[];
do input_vec(~[f1, f2]) |line| {
Expand All @@ -587,6 +598,7 @@ mod test {


#[test]
#[ignore(cfg(windows))] // FIXME(#8810): rt::io::file and windows don't agree
fn test_next_file() {
let filenames = make_path_option_vec(vec::from_fn(
3,
Expand Down Expand Up @@ -618,6 +630,7 @@ mod test {

#[test]
#[should_fail]
#[ignore(cfg(windows))] // FIXME(#8810): rt::io::file and windows don't agree
fn test_input_vec_missing_file() {
do input_vec(make_path_option_vec([~"this/file/doesnt/exist"], true)) |line| {
println(line);
Expand Down