Skip to content

Commit ad82635

Browse files
committed
improvs
1 parent 02d63cb commit ad82635

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

.github/workflows/failures.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,8 @@ jobs:
102102
- name: Run failing ui pattern tests for ICE
103103
id: ui-tests
104104
run: |
105-
${{ matrix.libgccjit_version.env_extra }} ./y.sh test --release --clean --build-sysroot --test-failing-ui-pattern-tests ${{ matrix.libgccjit_version.extra }} | tee output_log_ui
105+
${{ matrix.libgccjit_version.env_extra }} ./y.sh test --release --test-failing-ui-pattern-tests ${{ matrix.libgccjit_version.extra }} | tee output_log_ui
106106
if grep -q "the compiler unexpectedly panicked" output_log_ui; then
107107
echo "Error: 'the compiler unexpectedly panicked' found in output logs. CI Error!!"
108108
exit 1
109109
fi
110-
rg --text "test result" output_log_ui >> $GITHUB_STEP_SUMMARY

build_system/src/test.rs

+22-12
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ fn extended_sysroot_tests(env: &Env, args: &TestArg) -> Result<(), String> {
812812
Ok(())
813813
}
814814

815-
fn should_not_remove_test(file: &str) -> bool {
815+
fn valid_ui_error_pattern_test(file: &str) -> bool {
816816
// contains //~ERROR, but shouldn't be removed
817817
[
818818
"issues/auxiliary/issue-3136-a.rs",
@@ -828,7 +828,7 @@ fn should_not_remove_test(file: &str) -> bool {
828828
}
829829

830830
#[rustfmt::skip]
831-
fn should_remove_test(file_path: &Path) -> Result<bool, String> {
831+
fn contains_ui_error_patterns(file_path: &Path) -> Result<bool, String> {
832832
// Tests generating errors.
833833
let file = File::open(file_path)
834834
.map_err(|error| format!("Failed to read `{}`: {:?}", file_path.display(), error))?;
@@ -860,6 +860,14 @@ fn should_remove_test(file_path: &Path) -> Result<bool, String> {
860860
Ok(false)
861861
}
862862

863+
// # Parameters
864+
//
865+
// * `env`: An environment variable that provides context for the function.
866+
// * `args`: The arguments passed to the test. This could include things like the flags, config etc.
867+
// * `prepare_files_callback`: A callback function that prepares the files needed for the test. Its used to remove/retain tests giving Error to run various rust test suits.
868+
// * `should_run_test_callback`: An optional callback function that determines whether a test should be run or not. Used to run tests following specific conditions by defining conditions in bool returning function and sending it as an argument.
869+
// * `test_type`: A string that indicates the type of the test being run.
870+
//
863871
fn test_rustc_inner<F>(
864872
env: &Env,
865873
args: &TestArg,
@@ -881,7 +889,9 @@ where
881889
}
882890

883891
if test_type == "ui" {
892+
// uses contains_ui_error_patterns function being sent as callback to run only only error pattern tests
884893
if let Some(callback) = should_run_test_callback {
894+
// Redefining walk_dir to handle subdirectories
885895
fn walk_dir<F, G>(
886896
dir_path: PathBuf,
887897
dir_callback: F,
@@ -955,9 +965,9 @@ where
955965
return Ok(());
956966
}
957967
let path_str = file_path.display().to_string().replace("\\", "/");
958-
if should_not_remove_test(&path_str) {
968+
if valid_ui_error_pattern_test(&path_str) {
959969
return Ok(());
960-
} else if should_remove_test(file_path)? {
970+
} else if contains_ui_error_patterns(file_path)? {
961971
return remove_file(&file_path);
962972
}
963973
Ok(())
@@ -1053,15 +1063,15 @@ fn test_failing_rustc(env: &Env, args: &TestArg) -> Result<(), String> {
10531063
let result1 = test_rustc_inner(
10541064
env,
10551065
args,
1056-
prepare_files_callback_retain("tests/failing-run-make-tests.txt", "run-make"),
1066+
retain_files_callback("tests/failing-run-make-tests.txt", "run-make"),
10571067
None,
10581068
"run-make",
10591069
);
10601070

10611071
let result2 = test_rustc_inner(
10621072
env,
10631073
args,
1064-
prepare_files_callback_retain("tests/failing-ui-tests.txt", "ui"),
1074+
retain_files_callback("tests/failing-ui-tests.txt", "ui"),
10651075
None,
10661076
"ui",
10671077
);
@@ -1073,14 +1083,14 @@ fn test_successful_rustc(env: &Env, args: &TestArg) -> Result<(), String> {
10731083
test_rustc_inner(
10741084
env,
10751085
args,
1076-
prepare_files_callback_remove("tests/failing-ui-tests.txt", "ui"),
1086+
remove_files_callback("tests/failing-ui-tests.txt", "ui"),
10771087
None,
10781088
"ui",
10791089
)?;
10801090
test_rustc_inner(
10811091
env,
10821092
args,
1083-
prepare_files_callback_remove("tests/failing-run-make-tests.txt", "run-make"),
1093+
remove_files_callback("tests/failing-run-make-tests.txt", "run-make"),
10841094
None,
10851095
"run-make",
10861096
)
@@ -1090,13 +1100,13 @@ fn test_failing_ui_pattern_tests(env: &Env, args: &TestArg) -> Result<(), String
10901100
test_rustc_inner(
10911101
env,
10921102
args,
1093-
prepare_files_callback_remove("tests/failing-ice-tests.txt", "ui"),
1094-
Some(Box::new(|path| should_remove_test(path).unwrap_or(false))),
1103+
remove_files_callback("tests/failing-ice-tests.txt", "ui"),
1104+
Some(Box::new(|path| contains_ui_error_patterns(path).unwrap_or(false))),
10951105
"ui",
10961106
)
10971107
}
10981108

1099-
fn prepare_files_callback_retain<'a>(
1109+
fn retain_files_callback<'a>(
11001110
file_path: &'a str,
11011111
test_type: &'a str,
11021112
) -> impl Fn(&Path) -> Result<bool, String> + 'a {
@@ -1159,7 +1169,7 @@ fn prepare_files_callback_retain<'a>(
11591169
}
11601170
}
11611171

1162-
fn prepare_files_callback_remove<'a>(
1172+
fn remove_files_callback<'a>(
11631173
file_path: &'a str,
11641174
test_type: &'a str,
11651175
) -> impl Fn(&Path) -> Result<bool, String> + 'a {

0 commit comments

Comments
 (0)