rust: add tests for dependency inference

This commit is contained in:
figsoda 2023-03-18 11:31:24 -04:00
parent b0326efce0
commit 1f00dc5091
24 changed files with 698 additions and 1 deletions

53
Cargo.lock generated
View File

@ -459,6 +459,18 @@ dependencies = [
"libc",
]
[[package]]
name = "console"
version = "0.15.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3d79fbe8970a77e3e34151cc13d3b3e248aa0faaecb9f6091fa07ebefe5ad60"
dependencies = [
"encode_unicode",
"lazy_static",
"libc",
"windows-sys 0.42.0",
]
[[package]]
name = "const-oid"
version = "0.9.2"
@ -888,6 +900,12 @@ dependencies = [
"zeroize",
]
[[package]]
name = "encode_unicode"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f"
[[package]]
name = "encoding_rs"
version = "0.8.32"
@ -1436,6 +1454,19 @@ version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f2cb48b81b1dc9f39676bf99f5499babfec7cd8fe14307f7b3d747208fb5690"
[[package]]
name = "insta"
version = "1.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fea5b3894afe466b4bcf0388630fc15e11938a6074af0cd637c825ba2ec8a099"
dependencies = [
"console",
"lazy_static",
"linked-hash-map",
"similar",
"yaml-rust",
]
[[package]]
name = "instant"
version = "0.1.12"
@ -1599,6 +1630,12 @@ dependencies = [
"cc",
]
[[package]]
name = "linked-hash-map"
version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f"
[[package]]
name = "linux-raw-sys"
version = "0.1.4"
@ -1736,6 +1773,7 @@ dependencies = [
"flate2",
"heck",
"indoc",
"insta",
"is-terminal",
"itertools",
"once_cell",
@ -2667,6 +2705,12 @@ dependencies = [
"rand_core",
]
[[package]]
name = "similar"
version = "2.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "420acb44afdae038210c99e69aae24109f32f15500aa708e81d46c9f29d55fcf"
[[package]]
name = "sized-chunks"
version = "0.6.5"
@ -3587,6 +3631,15 @@ dependencies = [
"dirs",
]
[[package]]
name = "yaml-rust"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85"
dependencies = [
"linked-hash-map",
]
[[package]]
name = "zeroize"
version = "1.5.7"

View File

@ -80,6 +80,11 @@ clap = { version = "4.1.9", features = ["derive"] }
clap_complete = "4.1.5"
clap_mangen = "0.2.10"
[dev-dependencies]
heck = "0.4.1"
insta = "1.28.0"
tempfile = "3.4.0"
[features]
default = ["vendored", "reqwest/rustls-tls"]
vendored = ["cargo/vendored-libgit2", "cargo/vendored-openssl"]

11
scripts/lock-rust-fixture Executable file
View File

@ -0,0 +1,11 @@
#!/bin/sh
set -eu
dir=$(mktemp -d)
cp "src/lang/rust/fixtures/$1.toml" "$dir/Cargo.toml"
mkdir "$dir/src"
touch "$dir/src/lib.rs"
cargo generate-lockfile --manifest-path "$dir/Cargo.toml"
cp "$dir/Cargo.lock" "src/lang/rust/fixtures/$1-lock.toml"
rm -r "$dir"

View File

@ -5,7 +5,7 @@ use std::{
fmt::Write,
};
#[derive(Default)]
#[derive(Debug, Default)]
pub struct AllInputs {
pub native_build_inputs: Inputs,
pub build_inputs: Inputs,

View File

@ -0,0 +1,56 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "cc"
version = "1.0.79"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f"
[[package]]
name = "cmake"
version = "0.1.49"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db34956e100b30725f2eb215f90d4871051239535632f84fea3bc92722c66b7c"
dependencies = [
"cc",
]
[[package]]
name = "libc"
version = "0.2.140"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c"
[[package]]
name = "libz-ng"
version = "0.1.0"
dependencies = [
"libz-sys",
]
[[package]]
name = "libz-sys"
version = "1.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9702761c3935f8cc2f101793272e202c72b99da8f4224a19ddcf1279a6450bbf"
dependencies = [
"cc",
"cmake",
"libc",
"pkg-config",
"vcpkg",
]
[[package]]
name = "pkg-config"
version = "0.3.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160"
[[package]]
name = "vcpkg"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"

View File

@ -0,0 +1,8 @@
[package]
name = "libz-ng"
version = "0.1.0"
edition = "2021"
publish = false
[dependencies]
libz-sys = { version = "1.1.8", default-features = false, features = ["zlib-ng"] }

View File

@ -0,0 +1,46 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "cc"
version = "1.0.79"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f"
[[package]]
name = "libc"
version = "0.2.140"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c"
[[package]]
name = "libz-static"
version = "0.1.0"
dependencies = [
"libz-sys",
]
[[package]]
name = "libz-sys"
version = "1.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9702761c3935f8cc2f101793272e202c72b99da8f4224a19ddcf1279a6450bbf"
dependencies = [
"cc",
"libc",
"pkg-config",
"vcpkg",
]
[[package]]
name = "pkg-config"
version = "0.3.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160"
[[package]]
name = "vcpkg"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"

View File

@ -0,0 +1,8 @@
[package]
name = "libz-static"
version = "0.1.0"
edition = "2021"
publish = false
[dependencies]
libz-sys = { version = "1.1.8", features = ["static"] }

View File

@ -0,0 +1,56 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "cc"
version = "1.0.79"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f"
[[package]]
name = "cmake"
version = "0.1.49"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db34956e100b30725f2eb215f90d4871051239535632f84fea3bc92722c66b7c"
dependencies = [
"cc",
]
[[package]]
name = "libc"
version = "0.2.140"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c"
[[package]]
name = "libz-stock"
version = "0.1.0"
dependencies = [
"libz-sys",
]
[[package]]
name = "libz-sys"
version = "1.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9702761c3935f8cc2f101793272e202c72b99da8f4224a19ddcf1279a6450bbf"
dependencies = [
"cc",
"cmake",
"libc",
"pkg-config",
"vcpkg",
]
[[package]]
name = "pkg-config"
version = "0.3.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160"
[[package]]
name = "vcpkg"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"

View File

@ -0,0 +1,8 @@
[package]
name = "libz-stock"
version = "0.1.0"
edition = "2021"
publish = false
[dependencies]
libz-sys = { version = "1.1.8", features = ["zlib-ng"] }

View File

@ -0,0 +1,70 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "cc"
version = "1.0.79"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f"
dependencies = [
"jobserver",
]
[[package]]
name = "jobserver"
version = "0.1.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "936cfd212a0155903bcbc060e316fb6cc7cbf2e1907329391ebadc1fe0ce77c2"
dependencies = [
"libc",
]
[[package]]
name = "libc"
version = "0.2.140"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c"
[[package]]
name = "pkg-config"
version = "0.3.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160"
[[package]]
name = "zstd"
version = "0.12.3+zstd.1.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76eea132fb024e0e13fd9c2f5d5d595d8a967aa72382ac2f9d39fcc95afd0806"
dependencies = [
"zstd-safe",
]
[[package]]
name = "zstd-env"
version = "0.1.0"
dependencies = [
"zstd",
]
[[package]]
name = "zstd-safe"
version = "6.0.4+zstd.1.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7afb4b54b8910cf5447638cb54bf4e8a65cbedd783af98b98c62ffe91f185543"
dependencies = [
"libc",
"zstd-sys",
]
[[package]]
name = "zstd-sys"
version = "2.0.7+zstd.1.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94509c3ba2fe55294d752b79842c530ccfab760192521df74a081a78d2b3c7f5"
dependencies = [
"cc",
"libc",
"pkg-config",
]

View File

@ -0,0 +1,8 @@
[package]
name = "zstd-env"
version = "0.1.0"
edition = "2021"
publish = false
[dependencies]
zstd = "0.12.3"

View File

@ -0,0 +1,64 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "cc"
version = "1.0.79"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f"
dependencies = [
"jobserver",
]
[[package]]
name = "jobserver"
version = "0.1.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "936cfd212a0155903bcbc060e316fb6cc7cbf2e1907329391ebadc1fe0ce77c2"
dependencies = [
"libc",
]
[[package]]
name = "libc"
version = "0.2.140"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c"
[[package]]
name = "zstd"
version = "0.12.3+zstd.1.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76eea132fb024e0e13fd9c2f5d5d595d8a967aa72382ac2f9d39fcc95afd0806"
dependencies = [
"zstd-safe",
]
[[package]]
name = "zstd-old"
version = "0.1.0"
dependencies = [
"zstd",
"zstd-sys",
]
[[package]]
name = "zstd-safe"
version = "6.0.3+zstd.1.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68e4a3f57d13d0ab7e478665c60f35e2a613dcd527851c2c7287ce5c787e134a"
dependencies = [
"libc",
"zstd-sys",
]
[[package]]
name = "zstd-sys"
version = "2.0.4+zstd.1.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fa202f2ef00074143e219d15b62ffc317d17cc33909feac471c044087cad7b0"
dependencies = [
"cc",
"libc",
]

View File

@ -0,0 +1,9 @@
[package]
name = "zstd-old"
version = "0.1.0"
edition = "2021"
publish = false
[dependencies]
zstd = "0.12.3"
zstd-sys = "=2.0.4"

View File

@ -0,0 +1,71 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "cc"
version = "1.0.79"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f"
dependencies = [
"jobserver",
]
[[package]]
name = "jobserver"
version = "0.1.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "936cfd212a0155903bcbc060e316fb6cc7cbf2e1907329391ebadc1fe0ce77c2"
dependencies = [
"libc",
]
[[package]]
name = "libc"
version = "0.2.140"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c"
[[package]]
name = "pkg-config"
version = "0.3.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160"
[[package]]
name = "zstd"
version = "0.12.3+zstd.1.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76eea132fb024e0e13fd9c2f5d5d595d8a967aa72382ac2f9d39fcc95afd0806"
dependencies = [
"zstd-safe",
]
[[package]]
name = "zstd-old"
version = "0.1.0"
dependencies = [
"zstd",
"zstd-sys",
]
[[package]]
name = "zstd-safe"
version = "6.0.3+zstd.1.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68e4a3f57d13d0ab7e478665c60f35e2a613dcd527851c2c7287ce5c787e134a"
dependencies = [
"libc",
"zstd-sys",
]
[[package]]
name = "zstd-sys"
version = "2.0.4+zstd.1.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fa202f2ef00074143e219d15b62ffc317d17cc33909feac471c044087cad7b0"
dependencies = [
"cc",
"libc",
"pkg-config",
]

View File

@ -0,0 +1,9 @@
[package]
name = "zstd-pkg-config"
version = "0.1.0"
edition = "2021"
publish = false
[dependencies]
zstd = { version = "0.12.3", features = ["pkg-config"] }
zstd-sys = "=2.0.4"

View File

@ -1,4 +1,6 @@
mod deps;
#[cfg(test)]
mod tests;
use anyhow::{anyhow, Context, Result};
use cargo::{

View File

@ -0,0 +1,27 @@
---
source: src/lang/rust/tests.rs
expression: run(stringify!(libz_ng))
---
AllInputs {
native_build_inputs: Inputs {
always: {
"pkg-config",
},
darwin: {},
aarch64_darwin: {},
x86_64_darwin: {},
linux: {},
aarch64_linux: {},
x86_64_linux: {},
},
build_inputs: Inputs {
always: {},
darwin: {},
aarch64_darwin: {},
x86_64_darwin: {},
linux: {},
aarch64_linux: {},
x86_64_linux: {},
},
env: {},
}

View File

@ -0,0 +1,27 @@
---
source: src/lang/rust/tests.rs
expression: run(stringify!(libz_static))
---
AllInputs {
native_build_inputs: Inputs {
always: {
"pkg-config",
},
darwin: {},
aarch64_darwin: {},
x86_64_darwin: {},
linux: {},
aarch64_linux: {},
x86_64_linux: {},
},
build_inputs: Inputs {
always: {},
darwin: {},
aarch64_darwin: {},
x86_64_darwin: {},
linux: {},
aarch64_linux: {},
x86_64_linux: {},
},
env: {},
}

View File

@ -0,0 +1,29 @@
---
source: src/lang/rust/tests.rs
expression: run(stringify!(libz_stock))
---
AllInputs {
native_build_inputs: Inputs {
always: {
"pkg-config",
},
darwin: {},
aarch64_darwin: {},
x86_64_darwin: {},
linux: {},
aarch64_linux: {},
x86_64_linux: {},
},
build_inputs: Inputs {
always: {
"zlib",
},
darwin: {},
aarch64_darwin: {},
x86_64_darwin: {},
linux: {},
aarch64_linux: {},
x86_64_linux: {},
},
env: {},
}

View File

@ -0,0 +1,31 @@
---
source: src/lang/rust/tests.rs
expression: run(stringify!(zstd_env))
---
AllInputs {
native_build_inputs: Inputs {
always: {
"pkg-config",
},
darwin: {},
aarch64_darwin: {},
x86_64_darwin: {},
linux: {},
aarch64_linux: {},
x86_64_linux: {},
},
build_inputs: Inputs {
always: {
"zstd",
},
darwin: {},
aarch64_darwin: {},
x86_64_darwin: {},
linux: {},
aarch64_linux: {},
x86_64_linux: {},
},
env: {
"ZSTD_SYS_USE_PKG_CONFIG": "true",
},
}

View File

@ -0,0 +1,25 @@
---
source: src/lang/rust/tests.rs
expression: run(stringify!(zstd_old))
---
AllInputs {
native_build_inputs: Inputs {
always: {},
darwin: {},
aarch64_darwin: {},
x86_64_darwin: {},
linux: {},
aarch64_linux: {},
x86_64_linux: {},
},
build_inputs: Inputs {
always: {},
darwin: {},
aarch64_darwin: {},
x86_64_darwin: {},
linux: {},
aarch64_linux: {},
x86_64_linux: {},
},
env: {},
}

View File

@ -0,0 +1,29 @@
---
source: src/lang/rust/tests.rs
expression: run(stringify!(zstd_pkg_config))
---
AllInputs {
native_build_inputs: Inputs {
always: {
"pkg-config",
},
darwin: {},
aarch64_darwin: {},
x86_64_darwin: {},
linux: {},
aarch64_linux: {},
x86_64_linux: {},
},
build_inputs: Inputs {
always: {
"zstd",
},
darwin: {},
aarch64_darwin: {},
x86_64_darwin: {},
linux: {},
aarch64_linux: {},
x86_64_linux: {},
},
env: {},
}

45
src/lang/rust/tests.rs Normal file
View File

@ -0,0 +1,45 @@
use heck::AsKebabCase;
use insta::assert_debug_snapshot;
use tempfile::tempdir;
use super::resolve_workspace;
use crate::{inputs::AllInputs, lang::rust::load_rust_dependencies};
use std::fs::{copy, create_dir, File};
macro_rules! tests {
($($name:ident)+) => {
$(
#[test]
fn $name() {
assert_debug_snapshot!(run(stringify!($name)));
}
)+
};
}
tests! {
libz_ng
libz_static
libz_stock
zstd_env
zstd_old
zstd_pkg_config
}
fn run(name: &str) -> AllInputs {
let dir = tempdir().unwrap();
let dir = dir.path();
let fixture = format!("src/lang/rust/fixtures/{}", AsKebabCase(name));
copy(format!("{fixture}.toml"), dir.join("Cargo.toml")).unwrap();
copy(format!("{fixture}-lock.toml"), dir.join("Cargo.lock")).unwrap();
let src = dir.join("src");
create_dir(&src).unwrap();
File::create(src.join("lib.rs")).unwrap();
let mut inputs = AllInputs::default();
load_rust_dependencies(&mut inputs, &resolve_workspace(dir).unwrap());
inputs
}