From fd075c6f2144b33385a596b36eece02ed5d8be62 Mon Sep 17 00:00:00 2001 From: Pulkit Goyal <7895pulkit@gmail.com> Date: Tue, 16 Jan 2018 14:37:05 +0530 Subject: [PATCH 1/4] implement "only-" for test headers This patch implements "only-" for tests headers using which one can specify just the platforms on which the test should run rather than listing all the platforms to ignore using "ignore-". This is a fix for issues #33581 and #47459. --- src/tools/compiletest/src/header.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index 1f736e33c8b2a..475991d7b8be4 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -44,6 +44,8 @@ impl EarlyProps { props.ignore = props.ignore || config.parse_cfg_name_directive(ln, "ignore") || + (config.parse_cfg_prefix(ln, "only") && + !config.parse_cfg_name_directive(ln, "only")) || ignore_gdb(config, ln) || ignore_lldb(config, ln) || ignore_llvm(config, ln); @@ -564,6 +566,17 @@ impl Config { } } + fn parse_cfg_prefix(&self, line: &str, prefix: &str) -> bool { + // returns whether this line contains this prefix or not. For prefix + // "ignore", returns true if line says "ignore-x86_64", "ignore-arch", + // "ignore-andorid" etc. + if line.starts_with(prefix) && line.as_bytes().get(prefix.len()) == Some(&b'-') { + true + } else { + false + } + } + fn parse_name_directive(&self, line: &str, directive: &str) -> bool { // Ensure the directive is a whole word. Do not match "ignore-x86" when // the line says "ignore-x86_64". From 1e436eb236b2f6ae37971669d2a633cb0a778be6 Mon Sep 17 00:00:00 2001 From: Pulkit Goyal <7895pulkit@gmail.com> Date: Tue, 16 Jan 2018 15:02:29 +0530 Subject: [PATCH 2/4] return the boolean value directly instead of using if-else Previous patch introduced something like if x {true} else {false} which can be simply replaced by returning x here. Thanks to @kennytm for spotting it. --- src/tools/compiletest/src/header.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index 475991d7b8be4..478a692df9190 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -570,11 +570,7 @@ impl Config { // returns whether this line contains this prefix or not. For prefix // "ignore", returns true if line says "ignore-x86_64", "ignore-arch", // "ignore-andorid" etc. - if line.starts_with(prefix) && line.as_bytes().get(prefix.len()) == Some(&b'-') { - true - } else { - false - } + line.starts_with(prefix) && line.as_bytes().get(prefix.len()) == Some(&b'-') } fn parse_name_directive(&self, line: &str, directive: &str) -> bool { From 567b07c9e693758b3f4607573a2f276f43116f7b Mon Sep 17 00:00:00 2001 From: Pulkit Goyal <7895pulkit@gmail.com> Date: Tue, 16 Jan 2018 19:00:42 +0530 Subject: [PATCH 3/4] rename parse_cfg_prefix() to has_cfg_prefix() The function parse_cfg_prefix() is not really parsing. It's just checking whether the prefix is present or not. So the new function name as suggested by @Mark-Simulacrum is better. --- src/tools/compiletest/src/header.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index 478a692df9190..a10372fd74597 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -44,7 +44,7 @@ impl EarlyProps { props.ignore = props.ignore || config.parse_cfg_name_directive(ln, "ignore") || - (config.parse_cfg_prefix(ln, "only") && + (config.has_cfg_prefix(ln, "only") && !config.parse_cfg_name_directive(ln, "only")) || ignore_gdb(config, ln) || ignore_lldb(config, ln) || @@ -566,7 +566,7 @@ impl Config { } } - fn parse_cfg_prefix(&self, line: &str, prefix: &str) -> bool { + fn has_cfg_prefix(&self, line: &str, prefix: &str) -> bool { // returns whether this line contains this prefix or not. For prefix // "ignore", returns true if line says "ignore-x86_64", "ignore-arch", // "ignore-andorid" etc. From bd70f0fa66853125797bfa4cdea37b9ca2120159 Mon Sep 17 00:00:00 2001 From: Pulkit Goyal <7895pulkit@gmail.com> Date: Tue, 16 Jan 2018 19:09:32 +0530 Subject: [PATCH 4/4] add a comment about parsing only prefix in header.rs --- src/tools/compiletest/src/header.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index a10372fd74597..ff662736bdd1b 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -41,6 +41,8 @@ impl EarlyProps { iter_header(testfile, None, &mut |ln| { + // we should check if any only- exists and if it exists + // and does not matches the current platform, skip the test props.ignore = props.ignore || config.parse_cfg_name_directive(ln, "ignore") ||