Skip to content

Commit

Permalink
Merge pull request #4001 from tertsdiepraam/tests-not-via-build-rs
Browse files Browse the repository at this point in the history
tests: do not generate module structure in `build.rs`
  • Loading branch information
sylvestre authored Oct 5, 2022
2 parents ae7c45d + adf4bab commit 490aa75
Show file tree
Hide file tree
Showing 3 changed files with 411 additions and 66 deletions.
14 changes: 0 additions & 14 deletions .github/workflows/CICD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,20 +138,6 @@ jobs:
# * convert any errors/warnings to GHA UI annotations; ref: <https://help.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-a-warning-message>
S=$(cargo fmt -- --check) && printf "%s\n" "$S" || { printf "%s\n" "$S" ; printf "%s\n" "$S" | sed -E -n -e "s/^Diff[[:space:]]+in[[:space:]]+${PWD//\//\\/}\/(.*)[[:space:]]+at[[:space:]]+[^0-9]+([0-9]+).*$/::${fault_type} file=\1,line=\2::${fault_prefix}: \`cargo fmt\`: style violation (file:'\1', line:\2; use \`cargo fmt -- \"\1\"\`)/p" ; fault=true ; }
if [ -n "${{ steps.vars.outputs.FAIL_ON_FAULT }}" ] && [ -n "$fault" ]; then exit 1 ; fi
- name: "`cargo fmt` testing of integration tests"
if: success() || failure() # run regardless of prior step success/failure
shell: bash
run: |
## `cargo fmt` testing of integration tests
unset fault
fault_type="${{ steps.vars.outputs.FAULT_TYPE }}"
fault_prefix=$(echo "$fault_type" | tr '[:lower:]' '[:upper:]')
# 'tests' is the standard/usual integration test directory
if [ -d tests ]; then
# * convert any errors/warnings to GHA UI annotations; ref: <https://help.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-a-warning-message>
S=$(find tests -name "*.rs" -print0 | xargs -0 cargo fmt -- --check) && printf "%s\n" "$S" || { printf "%s\n" "$S" ; printf "%s\n" "$S" | sed -E -n "s/^Diff[[:space:]]+in[[:space:]]+${PWD//\//\\/}\/(.*)[[:space:]]+at[[:space:]]+[^0-9]+([0-9]+).*$/::${fault_type} file=\1,line=\2::${fault_prefix}: \`cargo fmt\`: style violation (file:'\1', line:\2; use \`cargo fmt \"\1\"\`)/p" ; fault=true ; }
fi
if [ -n "${{ steps.vars.outputs.FAIL_ON_FAULT }}" ] && [ -n "$fault" ]; then exit 1 ; fi
style_lint:
name: Style/lint
Expand Down
51 changes: 0 additions & 51 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ pub fn main() {

let out_dir = env::var("OUT_DIR").unwrap();
// println!("cargo:warning=out_dir={}", out_dir);
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap().replace('\\', "/");
// println!("cargo:warning=manifest_dir={}", manifest_dir);
let util_tests_dir = format!("{}/tests/by-util", manifest_dir);
// println!("cargo:warning=util_tests_dir={}", util_tests_dir);

let mut crates = Vec::new();
for (key, val) in env::vars() {
Expand All @@ -41,7 +37,6 @@ pub fn main() {
crates.sort();

let mut mf = File::create(Path::new(&out_dir).join("uutils_map.rs")).unwrap();
let mut tf = File::create(Path::new(&out_dir).join("test_modules.rs")).unwrap();

mf.write_all(
"type UtilityMap<T> = phf::Map<&'static str, (fn(T) -> i32, fn() -> Command<'static>)>;\n\
Expand All @@ -60,42 +55,15 @@ pub fn main() {
"uu_test" => {
phf_map.entry("test", &map_value);
phf_map.entry("[", &map_value);

tf.write_all(
format!(
"#[path=\"{dir}/test_test.rs\"]\nmod test_test;\n",
dir = util_tests_dir,
)
.as_bytes(),
)
.unwrap();
}
k if k.starts_with(OVERRIDE_PREFIX) => {
phf_map.entry(&k[OVERRIDE_PREFIX.len()..], &map_value);
tf.write_all(
format!(
"#[path=\"{dir}/test_{k}.rs\"]\nmod test_{k};\n",
k = &krate[OVERRIDE_PREFIX.len()..],
dir = util_tests_dir,
)
.as_bytes(),
)
.unwrap();
}
"false" | "true" => {
phf_map.entry(
krate,
&format!("(r#{krate}::uumain, r#{krate}::uu_app)", krate = krate),
);
tf.write_all(
format!(
"#[path=\"{dir}/test_{krate}.rs\"]\nmod test_{krate};\n",
krate = krate,
dir = util_tests_dir,
)
.as_bytes(),
)
.unwrap();
}
"hashsum" => {
phf_map.entry(
Expand Down Expand Up @@ -123,33 +91,14 @@ pub fn main() {
phf_map.entry("shake256sum", &map_value_bits);
phf_map.entry("b2sum", &map_value);
phf_map.entry("b3sum", &map_value_b3sum);
tf.write_all(
format!(
"#[path=\"{dir}/test_{krate}.rs\"]\nmod test_{krate};\n",
krate = krate,
dir = util_tests_dir,
)
.as_bytes(),
)
.unwrap();
}
_ => {
phf_map.entry(krate, &map_value);
tf.write_all(
format!(
"#[path=\"{dir}/test_{krate}.rs\"]\nmod test_{krate};\n",
krate = krate,
dir = util_tests_dir,
)
.as_bytes(),
)
.unwrap();
}
}
}
write!(mf, "{}", phf_map.build()).unwrap();
mf.write_all(b"\n}\n").unwrap();

mf.flush().unwrap();
tf.flush().unwrap();
}
Loading

0 comments on commit 490aa75

Please sign in to comment.