From 3931dfebf835f73eb9ea63ad5317722307f6cd09 Mon Sep 17 00:00:00 2001 From: Michael Buesch Date: Mon, 30 Dec 2024 12:45:38 +0100 Subject: [PATCH] Build the test stubs with Cargo --- Cargo.lock | 4 ++++ Cargo.toml | 1 + tests/run-tests.sh | 13 +------------ tests/stubs/nft/Cargo.toml | 20 ++++++++++++++++++++ tests/stubs/{ => nft/src/bin}/nft.rs | 0 5 files changed, 26 insertions(+), 12 deletions(-) create mode 100644 tests/stubs/nft/Cargo.toml rename tests/stubs/{ => nft/src/bin}/nft.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 15bd194..3b6ecca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -676,6 +676,10 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "nft-stub" +version = "0.0.0" + [[package]] name = "nftables" version = "0.5.0" diff --git a/Cargo.toml b/Cargo.toml index 13d0c91..0abfb2e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ members = [ "letmein-systemd", "letmeind", "letmeinfwd", + "tests/stubs/nft", ] resolver = "2" diff --git a/tests/run-tests.sh b/tests/run-tests.sh index 2180685..4daa1ad 100755 --- a/tests/run-tests.sh +++ b/tests/run-tests.sh @@ -38,15 +38,6 @@ cargo_clippy() cargo clippy --tests -- --deny warnings || die "cargo clippy --tests failed" } -build_stubs() -{ - info "Building stubs..." - mkdir -p "$tmpbin" \ - || die "Failed to create tmpbin directory" - rustc --edition 2021 -o "$tmpbin/nft" "$stubdir/nft.rs" \ - || die "Failed to build nft stub" -} - run_tests() { local test_type="$1" @@ -152,14 +143,13 @@ pid_letmeind= [ -n "$TMPDIR" ] || export TMPDIR=/tmp tmpdir="$(mktemp --tmpdir="$TMPDIR" -d letmein-test.XXXXXXXXXX)" [ -d "$tmpdir" ] || die "Failed to create temporary directory" -tmpbin="$tmpdir/bin" rundir="$tmpdir/run" target="$basedir/target/debug" testdir="$basedir/tests" stubdir="$testdir/stubs" -export PATH="$tmpbin:$PATH" +export PATH="$target:$PATH" trap cleanup_and_exit INT TERM trap cleanup EXIT @@ -167,7 +157,6 @@ trap cleanup EXIT info "Temporary directory is: $tmpdir" build_project cargo_clippy -build_stubs run_tests tcp run_tests udp info "All tests Ok." diff --git a/tests/stubs/nft/Cargo.toml b/tests/stubs/nft/Cargo.toml new file mode 100644 index 0000000..392d501 --- /dev/null +++ b/tests/stubs/nft/Cargo.toml @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- + +[package] +name = "nft-stub" +description = "letmein: nft stub for testing" +version = "0.0.0" +publish = false +edition = { workspace = true } +rust-version = { workspace = true } +license = { workspace = true } +authors = { workspace = true } +homepage = { workspace = true } +repository = { workspace = true } + +[[bin]] +name = "nft" + +[dependencies] + +# vim: ts=4 sw=4 expandtab diff --git a/tests/stubs/nft.rs b/tests/stubs/nft/src/bin/nft.rs similarity index 100% rename from tests/stubs/nft.rs rename to tests/stubs/nft/src/bin/nft.rs