Skip to content

Commit 514f858

Browse files
committed
Add multiple_programs test
1 parent c1f3afe commit 514f858

File tree

1 file changed

+51
-2
lines changed

1 file changed

+51
-2
lines changed

src/tests.rs

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@ use crate::util::files_with_extension;
22
use anyhow::{ensure, Result};
33
use assert_cmd::cargo::CommandCargoExt;
44
use std::{
5-
collections::HashSet, env::current_dir, fs::read_to_string, path::Path, process::Command,
5+
collections::HashSet,
6+
env::current_dir,
7+
fs::read_to_string,
8+
path::{Path, PathBuf},
9+
process::Command,
610
sync::Mutex,
711
};
812

913
const BASIC_DIR: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/fixtures/basic");
10-
1114
const CALL_EXTERNAL_DIR: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/fixtures/call_external");
15+
const MULTIPLE_PROGRAMS_DIR: &str =
16+
concat!(env!("CARGO_MANIFEST_DIR"), "/fixtures/multiple_programs");
1217

1318
// smoelius: Only one Anchor test can be run at a time.
1419
static MUTEX: Mutex<()> = Mutex::new(());
@@ -81,6 +86,50 @@ fn include_cargo_does_not_change_line_hits() {
8186
}
8287
}
8388

89+
#[test]
90+
fn multiple_programs() {
91+
let _lock = MUTEX.lock().unwrap();
92+
93+
yarn(MULTIPLE_PROGRAMS_DIR).unwrap();
94+
95+
let mut command = anchor_coverage_command(MULTIPLE_PROGRAMS_DIR);
96+
let status = command.status().unwrap();
97+
assert!(status.success(), "command failed: {command:?}");
98+
99+
let lcovs = files_with_extension(
100+
Path::new(MULTIPLE_PROGRAMS_DIR).join("sbf_trace_dir"),
101+
"lcov",
102+
)
103+
.unwrap();
104+
let source_files = lcovs
105+
.iter()
106+
.map(|lcov| {
107+
let contents = read_to_string(lcov).unwrap();
108+
let source_file = contents
109+
.lines()
110+
.next()
111+
.and_then(|line| line.strip_prefix("SF:"))
112+
.unwrap();
113+
PathBuf::from(source_file)
114+
})
115+
.collect::<HashSet<_>>();
116+
117+
for program in ["foo", "bar"] {
118+
// smoelius: Verify IDL was generated.
119+
let idl_json_path = Path::new(MULTIPLE_PROGRAMS_DIR)
120+
.join("target/idl")
121+
.join(program)
122+
.with_extension("json");
123+
assert!(idl_json_path.try_exists().unwrap());
124+
// smoelius: Verify lcov was generated.
125+
let lib_rs_path = Path::new(MULTIPLE_PROGRAMS_DIR)
126+
.join("programs")
127+
.join(program)
128+
.join("src/lib.rs");
129+
assert!(source_files.contains(&lib_rs_path));
130+
}
131+
}
132+
84133
fn yarn(dir: &str) -> Result<()> {
85134
let mut command = Command::new("yarn");
86135
command.current_dir(dir);

0 commit comments

Comments
 (0)