From f071ea7ee91efe3b6d07b82a8cee5e4a5dc69b38 Mon Sep 17 00:00:00 2001 From: Khyber Sen Date: Wed, 1 Nov 2023 02:53:41 -0700 Subject: [PATCH] `c2rust-analyze/tests`: Convert the `lighttpd_minimal` test to the use 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. --- .gitignore | 1 + analysis/tests/lighttpd-minimal/src/main.rs | 2 -- c2rust-analyze/tests/analyze.rs | 31 +++++++++++++++++++-- c2rust-analyze/tests/common/mod.rs | 4 +++ 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 26642bbd37..18c446d98c 100644 --- a/.gitignore +++ b/.gitignore @@ -49,3 +49,4 @@ marks.*.json # Outputs of `c2rust-analyze` inspect/ *.analysis.txt +analysis.txt diff --git a/analysis/tests/lighttpd-minimal/src/main.rs b/analysis/tests/lighttpd-minimal/src/main.rs index 74ed4d85d7..04d9d936ac 100644 --- a/analysis/tests/lighttpd-minimal/src/main.rs +++ b/analysis/tests/lighttpd-minimal/src/main.rs @@ -6,8 +6,6 @@ #![allow(unused_variables)] #![feature(extern_types)] -extern crate libc; - use libc::*; use std::mem; diff --git a/c2rust-analyze/tests/analyze.rs b/c2rust-analyze/tests/analyze.rs index 12d9bb4ca3..3cbb0a9566 100644 --- a/c2rust-analyze/tests/analyze.rs +++ b/c2rust-analyze/tests/analyze.rs @@ -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() { @@ -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] diff --git a/c2rust-analyze/tests/common/mod.rs b/c2rust-analyze/tests/common/mod.rs index 40ee08ba17..f63ea1d71c 100644 --- a/c2rust-analyze/tests/common/mod.rs +++ b/c2rust-analyze/tests/common/mod.rs @@ -139,6 +139,10 @@ impl Analyze { Self { path } } + pub fn path(&self) -> &Path { + &self.path + } + fn run_with_( &self, rs_path: &Path,