Skip to content

Commit

Permalink
Allow compile tests to run under both debug and release profiles.
Browse files Browse the repository at this point in the history
Fixes #28.
  • Loading branch information
orium committed Oct 27, 2023
1 parent b8418a8 commit 3be44a4
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

extern crate compiletest_rs as compiletest;

use std::path::PathBuf;
use std::path::{Path, PathBuf};

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

for entry in read_dir(dependency_path)? {
Expand All @@ -23,8 +23,8 @@ fn find_rlib(dependency_path: &str, dependency_name: &str) -> std::io::Result<Op
Ok(None)
}

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

for dep in dependencies {
let rlib_path = find_rlib(dependency_path, dep).expect("io error").expect("rlib not found");
Expand All @@ -35,6 +35,18 @@ fn rustc_flags(dependency_path: &str, dependencies: &[&str]) -> String {
flags
}

fn dependency_path() -> PathBuf {
std::env::var("LD_LIBRARY_PATH")
.ok()
.or_else(|| std::env::var("DYLD_FALLBACK_LIBRARY_PATH").ok())
.or_else(|| std::env::var("PATH").ok())
.expect("unable to find the dependency path")
.split(':')
.map(PathBuf::from)
.find(|path| path.ends_with("deps"))
.expect("could not find dependency path")
}

#[test]
fn compile_tests() {
use compiletest::common::Mode;
Expand All @@ -48,7 +60,7 @@ fn compile_tests() {

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

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

compiletest::run_tests(&config);
}

0 comments on commit 3be44a4

Please sign in to comment.