diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /vendor/sysinfo/tests/code_checkers/headers.rs | |
parent | Initial commit. (diff) | |
download | rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip |
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/sysinfo/tests/code_checkers/headers.rs')
-rw-r--r-- | vendor/sysinfo/tests/code_checkers/headers.rs | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/vendor/sysinfo/tests/code_checkers/headers.rs b/vendor/sysinfo/tests/code_checkers/headers.rs new file mode 100644 index 000000000..ac7a34ddb --- /dev/null +++ b/vendor/sysinfo/tests/code_checkers/headers.rs @@ -0,0 +1,59 @@ +// Take a look at the license at the top of the repository in the LICENSE file. + +use super::utils::{show_error, TestResult}; +use std::path::Path; + +pub fn check_license_header(content: &str, p: &Path) -> TestResult { + let mut lines = content.lines(); + let next = lines.next(); + let header = "// Take a look at the license at the top of the repository in the LICENSE file."; + + match next { + Some(s) if s == header => { + let next = lines.next(); + match next { + Some("") => TestResult { + nb_tests: 1, + nb_errors: 0, + }, + Some(s) => { + show_error( + p, + &format!("Expected empty line after license header, found `{}`", s), + ); + TestResult { + nb_tests: 1, + nb_errors: 1, + } + } + None => { + show_error(p, "This file should very likely not exist..."); + TestResult { + nb_tests: 1, + nb_errors: 1, + } + } + } + } + Some(s) => { + show_error( + p, + &format!( + "Expected license header at the top of the file (`{}`), found: `{}`", + header, s + ), + ); + TestResult { + nb_tests: 1, + nb_errors: 1, + } + } + None => { + show_error(p, "This (empty?) file should very likely not exist..."); + TestResult { + nb_tests: 1, + nb_errors: 1, + } + } + } +} |