From 2b557fd347f92c89d5fe7716eb4a2908f6f77a56 Mon Sep 17 00:00:00 2001 From: Sergey Kvachonok Date: Thu, 12 Oct 2023 12:22:17 +0300 Subject: [PATCH] test: Add crate-level integration tests Add a sample `Conanfile.txt` and run the `conan install` command using the public crate API. Check that the JSON-formatted Conan output is parsed successfully. Test the Conan command failure handling code in two separate test cases. --- .github/workflows/rust.yml | 7 +++++ tests/conanfile.txt | 3 +++ tests/integration_test.rs | 54 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 tests/conanfile.txt create mode 100644 tests/integration_test.rs diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index f318a9f..3e07724 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -17,6 +17,13 @@ jobs: - uses: actions/checkout@v3 - name: Build run: cargo build --verbose + - name: Install Conan + id: conan + uses: turtlebrowser/get-conan@v1.2 + - name: Conan version + run: echo "${{ steps.conan.outputs.version }}" + - name: Conan profile init + run: conan profile detect - name: Run tests run: cargo test --verbose fmt: diff --git a/tests/conanfile.txt b/tests/conanfile.txt new file mode 100644 index 0000000..0740b42 --- /dev/null +++ b/tests/conanfile.txt @@ -0,0 +1,3 @@ +[requires] +libxml2/2.11.4 +zlib/1.3 diff --git a/tests/integration_test.rs b/tests/integration_test.rs new file mode 100644 index 0000000..f98d33a --- /dev/null +++ b/tests/integration_test.rs @@ -0,0 +1,54 @@ +//! conan2-rs integration tests + +use std::{io::Write, path::Path}; + +use conan2::ConanInstall; + +#[test] +fn run_conan_install() { + let output = ConanInstall::with_recipe(Path::new("tests/conanfile.txt")) + .output_folder(Path::new(env!("CARGO_TARGET_TMPDIR"))) + .build("missing") + .run(); + + // Fallback for test debugging + if !output.is_success() { + std::io::stderr().write_all(output.stderr()).unwrap(); + } + + assert!(output.is_success()); + assert_eq!(output.status_code(), 0); + + output.parse().emit(); +} + +#[test] +fn fail_no_conanfile() { + let output = ConanInstall::new() + .output_folder(Path::new(env!("CARGO_TARGET_TMPDIR"))) + .run(); + + std::io::stderr().write_all(output.stderr()).unwrap(); + + assert!(!output.is_success()); + assert!(output.status_code() > 0); + assert_eq!(output.stdout().len(), 0); + assert!(output + .stderr() + .starts_with(b"ERROR: Conanfile not found at")); +} + +#[test] +fn fail_no_profile() { + let output = ConanInstall::with_recipe(Path::new("tests/conanfile.txt")) + .output_folder(Path::new(env!("CARGO_TARGET_TMPDIR"))) + .profile("no-such-profile") + .run(); + + std::io::stderr().write_all(output.stderr()).unwrap(); + + assert!(!output.is_success()); + assert!(output.status_code() > 0); + assert_eq!(output.stdout().len(), 0); + assert!(output.stderr().starts_with(b"ERROR: Profile not found: ")); +}