filecheck: Use std::fs::read_to_string instead of hand-rolled copy (#1627)

This commit is contained in:
Nick Fitzgerald
2020-04-28 17:54:41 -07:00
committed by GitHub
parent d9d69299bb
commit c9b27b484e

View File

@@ -12,18 +12,9 @@ use cranelift_reader::{parse_test, IsaSpec, ParseOptions};
use log::info; use log::info;
use std::borrow::Cow; use std::borrow::Cow;
use std::fs; use std::fs;
use std::io::{self, Read};
use std::path::Path; use std::path::Path;
use std::time; use std::time;
/// Read an entire file into a string.
fn read_to_string<P: AsRef<Path>>(path: P) -> io::Result<String> {
let mut file = fs::File::open(path)?;
let mut buffer = String::new();
file.read_to_string(&mut buffer)?;
Ok(buffer)
}
/// Load `path` and run the test in it. /// Load `path` and run the test in it.
/// ///
/// If running this test causes a panic, it will propagate as normal. /// If running this test causes a panic, it will propagate as normal.
@@ -31,7 +22,7 @@ pub fn run(path: &Path, passes: Option<&[String]>, target: Option<&str>) -> Test
let _tt = timing::process_file(); let _tt = timing::process_file();
info!("---\nFile: {}", path.to_string_lossy()); info!("---\nFile: {}", path.to_string_lossy());
let started = time::Instant::now(); let started = time::Instant::now();
let buffer = read_to_string(path).map_err(|e| e.to_string())?; let buffer = fs::read_to_string(path).map_err(|e| e.to_string())?;
let options = ParseOptions { let options = ParseOptions {
target, target,
passes, passes,