Skip to content

Commit

Permalink
Use named struct arguments instead of comment named args
Browse files Browse the repository at this point in the history
  • Loading branch information
Urgau committed Apr 28, 2024
1 parent 607497d commit 006c94c
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 60 deletions.
64 changes: 35 additions & 29 deletions tests/run-make/print-cfg/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,42 @@ use std::iter::FromIterator;

use run_make_support::{rustc, tmp_dir};

struct PrintCfg {
target: &'static str,
includes: &'static [&'static str],
disallow: &'static [&'static str],
}

fn main() {
check(
/*target*/ "x86_64-pc-windows-gnu",
/*includes*/ &["windows", "target_arch=\"x86_64\""],
/*disallow*/ &["unix"],
);
check(
/*target*/ "i686-pc-windows-msvc",
/*includes*/ &["windows", "target_env=\"msvc\""],
/*disallow*/ &["unix"],
);
check(
/*target*/ "i686-apple-darwin",
/*includes*/ &["unix", "target_os=\"macos\"", "target_vendor=\"apple\""],
/*disallow*/ &["windows"],
);
check(
/*target*/ "i686-unknown-linux-gnu",
/*includes*/ &["unix", "target_env=\"gnu\""],
/*disallow*/ &["windows"],
);
check(
/*target*/ "arm-unknown-linux-gnueabihf",
/*includes*/ &["unix", "target_abi=\"eabihf\""],
/*disallow*/ &["windows"],
);
check(PrintCfg {
target: "x86_64-pc-windows-gnu",
includes: &["windows", "target_arch=\"x86_64\""],
disallow: &["unix"],
});
check(PrintCfg {
target: "i686-pc-windows-msvc",
includes: &["windows", "target_env=\"msvc\""],
disallow: &["unix"],
});
check(PrintCfg {
target: "i686-apple-darwin",
includes: &["unix", "target_os=\"macos\"", "target_vendor=\"apple\""],
disallow: &["windows"],
});
check(PrintCfg {
target: "i686-unknown-linux-gnu",
includes: &["unix", "target_env=\"gnu\""],
disallow: &["windows"],
});
check(PrintCfg {
target: "arm-unknown-linux-gnueabihf",
includes: &["unix", "target_abi=\"eabihf\""],
disallow: &["windows"],
});
}

fn check(target: &str, includes: &[&str], disallow: &[&str]) {
fn _inner(output: &str, includes: &[&str], disallow: &[&str]) {
fn check(PrintCfg { target, includes, disallow }: PrintCfg) {
fn check_(output: &str, includes: &[&str], disallow: &[&str]) {
let mut found = HashSet::<String>::new();
let mut recorded = HashSet::<String>::new();

Expand Down Expand Up @@ -82,7 +88,7 @@ fn check(target: &str, includes: &[&str], disallow: &[&str]) {

let stdout = String::from_utf8(output.stdout).unwrap();

_inner(&stdout, includes, disallow);
check_(&stdout, includes, disallow);
}

// --print=cfg=PATH
Expand All @@ -95,6 +101,6 @@ fn check(target: &str, includes: &[&str], disallow: &[&str]) {

let output = std::fs::read_to_string(&tmp_path).unwrap();

_inner(&output, includes, disallow);
check_(&output, includes, disallow);
}
}
63 changes: 32 additions & 31 deletions tests/run-make/print-to-output/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,61 +7,62 @@ use std::ffi::OsString;

use run_make_support::{rustc, target, tmp_dir};

struct Option<'a> {
target: &'a str,
option: &'static str,
includes: &'static [&'static str],
}

fn main() {
// Printed from CodegenBackend trait impl in rustc_codegen_llvm/src/lib.rs
check(
/*target*/ &target(),
/*option*/ "relocation-models",
/*includes*/ &["dynamic-no-pic"],
);
check(Option {
target: &target(),
option: "relocation-models",
includes: &["dynamic-no-pic"],
});

// Printed by compiler/rustc_codegen_llvm/src/llvm_util.rs
check(
/*target*/ "wasm32-unknown-unknown",
/*option*/ "target-features",
/*includes*/ &["reference-types"],
);
check(Option {
target: "wasm32-unknown-unknown",
option: "target-features",
includes: &["reference-types"],
});

// Printed by C++ code in rustc_llvm/llvm-wrapper/PassWrapper.cpp
check(
/*target*/ "wasm32-unknown-unknown",
/*option*/ "target-cpus",
/*includes*/ &["generic"],
);
check(Option {
target: "wasm32-unknown-unknown",
option: "target-cpus",
includes: &["generic"],
});
}

fn check(target: &str, option: &str, includes: &[&str]) {
fn _inner(output: &str, includes: &[&str]) {
fn check(args: Option) {
fn check_(output: &str, includes: &[&str]) {
for i in includes {
assert!(output.contains(i), "output doesn't contains: {}", i);
}
}

// --print={option}
let stdout = {
let output = rustc().target(target).print(option).run();

let stdout = String::from_utf8(output.stdout).unwrap();

_inner(&stdout, includes);
let output = rustc().target(args.target).print(args.option).run();

stdout
String::from_utf8(output.stdout).unwrap()
};

// --print={option}=PATH
let output = {
let tmp_path = tmp_dir().join(format!("{option}.txt"));
let mut print_arg = OsString::from(format!("--print={option}="));
let tmp_path = tmp_dir().join(format!("{}.txt", args.option));
let mut print_arg = OsString::from(format!("--print={}=", args.option));
print_arg.push(tmp_path.as_os_str());

let _output = rustc().target(target).arg(print_arg).run();
let _output = rustc().target(args.target).arg(print_arg).run();

let output = std::fs::read_to_string(&tmp_path).unwrap();

_inner(&output, includes);

output
std::fs::read_to_string(&tmp_path).unwrap()
};

check_(&stdout, args.includes);
check_(&output, args.includes);

assert_eq!(&stdout, &output);
}

0 comments on commit 006c94c

Please sign in to comment.