about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2018-05-08 07:32:00 -0700
committerAlex Crichton <alex@alexcrichton.com>2018-05-08 07:32:00 -0700
commita72be170d7048e4f9d8c14d35b93b05f1cb98dd1 (patch)
treebfc38b61cb6d302fc73e451d65a1c8bad930778f /src/test
parentf46f4b5f665675826bf9756c0e0896d5a5ef92d1 (diff)
Fix rustfmt tests in the Rust repo
Two tests were executing `cargo run` but `cargo` is not ambiently available to
execute. Instead it's best to execute the rustfmt binary directly, which is
always assembled as part of `cargo test`.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/mod.rs19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/test/mod.rs b/src/test/mod.rs
index 06fd1e5a98f..e2b371c611d 100644
--- a/src/test/mod.rs
+++ b/src/test/mod.rs
@@ -11,6 +11,7 @@
 extern crate assert_cli;
 
 use std::collections::{HashMap, HashSet};
+use std::env;
 use std::fs;
 use std::io::{self, BufRead, BufReader, Read};
 use std::iter::{Enumerate, Peekable};
@@ -892,14 +893,19 @@ impl Drop for TempFile {
     }
 }
 
+fn rustfmt() -> PathBuf {
+    let mut me = env::current_exe().expect("failed to get current executable");
+    me.pop(); // chop of the test name
+    me.pop(); // chop off `deps`
+    me.push("rustfmt");
+    return me;
+}
+
 #[test]
 fn verify_check_works() {
     let temp_file = make_temp_file("temp_check.rs");
     assert_cli::Assert::command(&[
-        "cargo",
-        "run",
-        "--bin=rustfmt",
-        "--",
+        rustfmt().to_str().unwrap(),
         "--write-mode=check",
         temp_file.path.to_str().unwrap(),
     ]).succeeds()
@@ -910,10 +916,7 @@ fn verify_check_works() {
 fn verify_diff_works() {
     let temp_file = make_temp_file("temp_diff.rs");
     assert_cli::Assert::command(&[
-        "cargo",
-        "run",
-        "--bin=rustfmt",
-        "--",
+        rustfmt().to_str().unwrap(),
         "--write-mode=diff",
         temp_file.path.to_str().unwrap(),
     ]).succeeds()