From 23e8c4d7648561ab825c52012a4303b386f0e70a 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 | 5 +++++ tests/conanfile.txt | 3 +++ tests/integration_test.rs | 45 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 53 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..896925d 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -17,6 +17,11 @@ 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: 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..c123351 --- /dev/null +++ b/tests/integration_test.rs @@ -0,0 +1,45 @@ +//! conan2-rs integration tests + +use std::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(); + + 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(); + + assert!(!output.is_success()); + assert_eq!(output.status_code(), 1); + 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(); + + assert!(!output.is_success()); + assert_eq!(output.status_code(), 1); + assert_eq!(output.stdout().len(), 0); + assert!(output.stderr().starts_with(b"ERROR: Profile not found: ")); +}