Skip to content

Commit

Permalink
c2rust-analyze/tests: Convert the lighttpd_minimal test to the us…
Browse files Browse the repository at this point in the history
…e the `cargo` wrapper.

This is done mostly as a proof of concept for now.
Ideally we'd want to add it as a method on `Analyze`/`FileCheck` and handle error reporting better.

Now that `lighttpd-minimal` is run with `cargo`, we don't need the `extern crate libc;` anymore.
  • Loading branch information
kkysen committed Nov 3, 2023
1 parent d6209fd commit f071ea7
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ marks.*.json
# Outputs of `c2rust-analyze`
inspect/
*.analysis.txt
analysis.txt
2 changes: 0 additions & 2 deletions analysis/tests/lighttpd-minimal/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
#![allow(unused_variables)]
#![feature(extern_types)]

extern crate libc;

use libc::*;
use std::mem;

Expand Down
31 changes: 29 additions & 2 deletions c2rust-analyze/tests/analyze.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
pub mod common;

use crate::common::{check_for_missing_tests_for, test_dir_for, Analyze, CrateOptions, CrateType};
use crate::common::check_for_missing_tests_for;
use crate::common::test_dir_for;
use crate::common::Analyze;
use crate::common::CrateOptions;
use crate::common::CrateType;
use fs_err::File;
use std::path::Path;
use std::process::Command;

#[test]
fn check_for_missing_tests() {
Expand Down Expand Up @@ -38,7 +45,27 @@ define_tests! {

#[test]
fn lighttpd_minimal() {
Analyze::resolve().run("../analysis/tests/lighttpd-minimal/src/main.rs");
let analyze = Analyze::resolve();
let mut cmd = Command::new(analyze.path());

cmd.arg("--");

cmd.arg("check");

let dir = Path::new("../analysis/tests/lighttpd-minimal");
let manifest_path = dir.join("Cargo.toml");
cmd.arg("--manifest-path").arg(manifest_path);

let output_path = dir.join("analysis.txt");
let output_stdout = File::create(&output_path).unwrap();
let output_stderr = File::try_clone(&output_stdout).unwrap();
cmd.stdout(output_stdout.into_parts().0)
.stderr(output_stderr.into_parts().0);

let status = cmd.status().unwrap();
assert!(status.success());

// TODO(kkysen) Handle error reporting better like [`Analyze::run`].
}

#[test]
Expand Down
4 changes: 4 additions & 0 deletions c2rust-analyze/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ impl Analyze {
Self { path }
}

pub fn path(&self) -> &Path {
&self.path
}

fn run_with_(
&self,
rs_path: &Path,
Expand Down

0 comments on commit f071ea7

Please sign in to comment.