Skip to content

Commit

Permalink
Fix "multiple candidates for rmeta dependency" issues with compilet…
Browse files Browse the repository at this point in the history
…est_rs.
  • Loading branch information
orium committed Jul 20, 2023
1 parent cd3e04e commit da28e35
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 20 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ codecov = { repository = "orium/archery", branch = "master", service = "github"
static_assertions = "1.1.0"

[dev-dependencies]
criterion = { version = "0.4.0", features = ["html_reports"] }
criterion = { version = "0.5.1", features = ["html_reports"] }
pretty_assertions = "1.2.1"
compiletest_rs = { version = "0.9.0", features = [ "tmp" ] }
compiletest_rs = "0.10.2"

[features]
fatal-warnings = []
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
extern crate archery;
extern crate static_assertions;

use archery::*;
use static_assertions::assert_impl_all;
use std::sync::MutexGuard;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
extern crate archery;
extern crate static_assertions;

use archery::*;
use std::rc::Rc;
use static_assertions::assert_impl_all;
use archery::*;

assert_impl_all!(SharedPointer<Rc<i32>, ArcK>: Send);
//~^ ERROR cannot be sent between threads safely
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
extern crate archery;
extern crate static_assertions;

use archery::*;
use static_assertions::assert_impl_all;
use std::cell::Cell;
Expand Down
5 changes: 1 addition & 4 deletions tests/compile-fail/shared_pointer_rc_is_not_send_nor_sync.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
extern crate archery;
extern crate static_assertions;

use static_assertions::assert_impl_all;
use archery::*;
use static_assertions::assert_impl_all;

assert_impl_all!(i32: Send, Sync);

Expand Down
41 changes: 37 additions & 4 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,53 @@

extern crate compiletest_rs as compiletest;

use std::path::PathBuf;

fn find_rlib(dependency_path: &str, dependency_name: &str) -> std::io::Result<Option<PathBuf>> {
use std::fs::read_dir;

for entry in read_dir(dependency_path)? {
let entry = entry?;

if let Some(filename) = entry.path().file_name().and_then(|f| f.to_str()) {
if filename.starts_with(&format!("lib{}", dependency_name))
&& filename.ends_with(".rlib")
{
return Ok(Some(entry.path()));
}
}
}

Ok(None)
}

fn rustc_flags(dependency_path: &str, dependencies: &[&str]) -> String {
let mut flags = format!("--edition=2021 -L dependency={} ", dependency_path);

for dep in dependencies {
let rlib_path = find_rlib(dependency_path, dep).expect("io error").expect("rlib not found");

flags.push_str(&format!("--extern {}={} ", dep, rlib_path.display()));
}

flags
}

#[cfg(not(miri))]
#[test]
fn compile_tests() {
use compiletest::common::ConfigWithTemp;
use compiletest::common::Mode;
use compiletest::Config;
use std::path::PathBuf;

let mut config: ConfigWithTemp = Config::default().tempdir();
let mut config: Config = Config::default();

config.mode = Mode::CompileFail;
config.src_base = PathBuf::from("tests/compile-fail");
config.target_rustcflags = Some("-L target/debug -L target/debug/deps".to_string());
config.clean_rmeta();

let dependencies = ["archery", "static_assertions"];

config.target_rustcflags = Some(rustc_flags("target/debug/deps/", &dependencies));

compiletest::run_tests(&config);
}

0 comments on commit da28e35

Please sign in to comment.