Skip to content

Commit

Permalink
test: Add crate-level integration tests
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ravenexp committed Oct 12, 2023
1 parent 296eaf6 commit 23e8c4d
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ jobs:
- uses: actions/checkout@v3
- name: Build
run: cargo build --verbose
- name: Install Conan
id: conan
uses: turtlebrowser/[email protected]
- name: Conan version
run: echo "${{ steps.conan.outputs.version }}"
- name: Run tests
run: cargo test --verbose
fmt:
Expand Down
3 changes: 3 additions & 0 deletions tests/conanfile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[requires]
libxml2/2.11.4
zlib/1.3
45 changes: 45 additions & 0 deletions tests/integration_test.rs
Original file line number Diff line number Diff line change
@@ -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: "));
}

0 comments on commit 23e8c4d

Please sign in to comment.