Skip to content

Commit

Permalink
parse and execute new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv committed Dec 14, 2023
1 parent 878449f commit 7b1db2f
Show file tree
Hide file tree
Showing 27 changed files with 977 additions and 551 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:
with:
toolchain: 1.73.0
targets: ${{ matrix.target }}

- name: Install musl-gcc
if: matrix.target == 'x86_64-unknown-linux-musl'
run: sudo apt install musl-tools
Expand Down
14 changes: 8 additions & 6 deletions examples/rich/recipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ requirements:
- python 3.10
- typing_extensions >=4.0.0,<5.0.0

test:
imports:
- rich
commands:
tests:
- python:
imports:
- rich
- script:
- pip check
requires:
- pip
requirements:
run:
- pip

about:
homepage: https://github.com/Textualize/rich
Expand Down
26 changes: 13 additions & 13 deletions examples/xtensor/recipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ requirements:
run_constrained:
- xsimd >=8.0.3,<10

test:
commands:
- if: unix or emscripten
then:
- test -d ${PREFIX}/include/xtensor
- test -f ${PREFIX}/include/xtensor/xarray.hpp
- test -f ${PREFIX}/share/cmake/xtensor/xtensorConfig.cmake
- test -f ${PREFIX}/share/cmake/xtensor/xtensorConfigVersion.cmake
- if: win
then:
- if not exist %LIBRARY_PREFIX%\include\xtensor\xarray.hpp (exit 1)
- if not exist %LIBRARY_PREFIX%\share\cmake\xtensor\xtensorConfig.cmake (exit 1)
- if not exist %LIBRARY_PREFIX%\share\cmake\xtensor\xtensorConfigVersion.cmake (exit 1)
tests:
- script:
- if: unix or emscripten
then:
- test -d ${PREFIX}/include/xtensor
- test -f ${PREFIX}/include/xtensor/xarray.hpp
- test -f ${PREFIX}/share/cmake/xtensor/xtensorConfig.cmake
- test -f ${PREFIX}/share/cmake/xtensor/xtensorConfigVersion.cmake
- if: win
then:
- if not exist %LIBRARY_PREFIX%\include\xtensor\xarray.hpp (exit 1)
- if not exist %LIBRARY_PREFIX%\share\cmake\xtensor\xtensorConfig.cmake (exit 1)
- if not exist %LIBRARY_PREFIX%\share\cmake\xtensor\xtensorConfigVersion.cmake (exit 1)

about:
homepage: https://github.com/xtensor-stack/xtensor
Expand Down
14 changes: 10 additions & 4 deletions rust-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ mod tests {
}
unreachable!("above is an infinite loop")
}

fn rattler() -> RattlerBuild {
if let Ok(path) = std::env::var("RATTLER_BUILD_PATH") {
if let Some(ret) = RattlerBuild::with_binary(path) {
Expand All @@ -155,9 +156,11 @@ mod tests {
}
RattlerBuild::with_cargo(".").unwrap()
}

fn recipes() -> PathBuf {
test_data_dir().join("recipes")
}

fn test_data_dir() -> PathBuf {
PathBuf::from(shx("cargo locate-project --workspace -q --message-format=plain").unwrap())
.parent()
Expand Down Expand Up @@ -426,10 +429,13 @@ mod tests {
let license = pkg.join("info/licenses/LICENSE.rst");
assert!(license.exists());

assert!(pkg.join("info/test/run_test.sh").exists());
assert!(pkg.join("info/test/run_test.bat").exists());
assert!(pkg.join("info/test/run_test.py").exists());
assert!(pkg.join("info/test/test_time_dependencies.json").exists());
assert!(pkg.join("info/tests/1/run_test.sh").exists());
assert!(pkg.join("info/tests/1/run_test.bat").exists());
assert!(pkg
.join("info/tests/1/test_time_dependencies.json")
.exists());

assert!(pkg.join("info/tests/0/run_test.py").exists());
// make sure that the entry point does not exist
assert!(!pkg.join("python-scripts/flask").exists());

Expand Down
29 changes: 17 additions & 12 deletions src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ use rattler_shell::shell;

use crate::env_vars::write_env_script;
use crate::metadata::{Directories, Output};
use crate::package_test::TestConfiguration;
use crate::packaging::{package_conda, record_files};
use crate::recipe::parser::ScriptContent;
use crate::recipe::parser::{ScriptContent, TestType};
use crate::render::resolved_dependencies::{install_environments, resolve_dependencies};
use crate::source::fetch_sources;
use crate::test::TestConfiguration;
use crate::{index, test, tool_configuration};
use crate::{index, package_test, tool_configuration};

const BASH_PREAMBLE: &str = r#"
## Start of bash preamble
Expand Down Expand Up @@ -303,14 +303,18 @@ pub async fn run_build(
)
.into_diagnostic()?;

if let Some(package_content) = output.recipe.test().package_content() {
test::run_package_content_tests(
package_content,
paths_json,
&output.build_configuration.target_platform,
)
.await
.into_diagnostic()?;
// We run all the package content tests
for test in output.recipe.tests() {
// TODO we could also run each of the (potentially multiple) test scripts and collect the errors
if let TestType::PackageContents(package_contents) = test {
package_test::run_package_content_tests(
package_contents,
&paths_json,
&output.build_configuration.target_platform,
)
.await
.into_diagnostic()?;
}
}

if !tool_configuration.no_clean {
Expand All @@ -333,13 +337,14 @@ pub async fn run_build(
} else {
tracing::info!("Running tests");

test::run_test(
package_test::run_test(
&result,
&TestConfiguration {
test_prefix: test_dir.clone(),
target_platform: Some(output.build_configuration.target_platform),
keep_test_prefix: tool_configuration.no_clean,
channels,
tool_configuration: tool_configuration.clone(),
},
)
.await
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#![deny(missing_docs)]
// #![deny(missing_docs)]

//! The library pieces of rattler-build

pub mod build;
pub mod metadata;
pub mod package_test;
pub mod recipe;
pub mod render;
pub mod selectors;
pub mod source;
pub mod test;
pub mod tool_configuration;
pub mod used_variables;
pub mod variant_config;
Expand Down
19 changes: 16 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ use rattler_build::{
build::run_build,
hash::HashInfo,
metadata::{BuildConfiguration, Directories, PackageIdentifier},
package_test::{self, TestConfiguration},
recipe::{parser::Recipe, ParsingError},
selectors::SelectorConfig,
test::{self, TestConfiguration},
tool_configuration,
variant_config::{ParseErrors, VariantConfig},
};
Expand Down Expand Up @@ -136,6 +136,10 @@ struct BuildOpts {

#[derive(Parser)]
struct TestOpts {
/// Channels to use when testing
#[arg(short = 'c', long)]
channel: Option<Vec<String>>,

/// The package file to test
#[arg(short, long)]
package_file: PathBuf,
Expand Down Expand Up @@ -187,10 +191,19 @@ async fn run_test_from_args(args: TestOpts) -> miette::Result<()> {
test_prefix,
target_platform: Some(Platform::current()),
keep_test_prefix: false,
channels: vec!["conda-forge".to_string(), "./output".to_string()],
channels: args
.channel
.unwrap_or_else(|| vec!["conda-forge".to_string()]),
tool_configuration: tool_configuration::Configuration {
client: AuthenticatedClient::default(),
multi_progress_indicator: MultiProgress::new(),
// duplicate from `keep_test_prefix`?
no_clean: false,
..Default::default()
},
};

test::run_test(&package_file, &test_options)
package_test::run_test(&package_file, &test_options)
.await
.into_diagnostic()?;

Expand Down
Loading

0 comments on commit 7b1db2f

Please sign in to comment.