-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
74fafba
commit 61b973e
Showing
7 changed files
with
221 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#![feature(rustc_private)] | ||
#[macro_use] | ||
extern crate lazy_static; | ||
|
||
use paralegal_flow::test_utils::*; | ||
use paralegal_spdg::Identifier; | ||
|
||
const CRATE_DIR: &str = "tests/cross-crate"; | ||
|
||
lazy_static! { | ||
static ref TEST_CRATE_ANALYZED: bool = { | ||
paralegal_flow_command(CRATE_DIR) | ||
.status() | ||
.unwrap() | ||
.success() | ||
}; | ||
} | ||
|
||
macro_rules! define_test { | ||
($name:ident: $ctrl:ident -> $block:block) => { | ||
define_test!($name: $ctrl, $name -> $block); | ||
}; | ||
($name:ident: $ctrl:ident, $ctrl_name:ident -> $block:block) => { | ||
paralegal_flow::define_flow_test_template!(TEST_CRATE_ANALYZED, CRATE_DIR, $name: $ctrl, $ctrl_name -> $block); | ||
}; | ||
} | ||
|
||
define_test!(basic : graph -> { | ||
let src_fn = graph.function("src"); | ||
let src = graph.call_site(&src_fn); | ||
let not_src_fn = graph.function("not_src"); | ||
let not_src = graph.call_site(¬_src_fn); | ||
let target_fn = graph.function("target"); | ||
let target = graph.call_site(&target_fn); | ||
assert!(src.output().flows_to_data(&target.input())); | ||
assert!(!not_src.output().flows_to_data(&target.input())); | ||
}); | ||
|
||
define_test!(basic_marker: graph -> { | ||
|
||
let marker = Identifier::new_intern("mark"); | ||
assert!(dbg!(&graph.spdg().markers).iter().any(|(_, markers)| markers.contains(&marker))) | ||
}); | ||
|
||
define_test!(assigns_marker: graph -> { | ||
let sources = graph.marked(Identifier::new_intern("source")); | ||
let mark = graph.marked(Identifier::new_intern("mark")); | ||
let target = graph.marked(Identifier::new_intern("target")); | ||
assert!(!sources.is_empty()); | ||
assert!(!mark.is_empty()); | ||
assert!(!target.is_empty()); | ||
assert!(sources.flows_to_data(&mark)); | ||
assert!(mark.flows_to_data(&target)); | ||
}); | ||
|
||
define_test!(basic_generic : graph -> { | ||
let src_fn = graph.function("src"); | ||
let src = graph.call_site(&src_fn); | ||
let not_src_fn = graph.function("not_src"); | ||
let not_src = graph.call_site(¬_src_fn); | ||
let target_fn = graph.function("target"); | ||
let target = graph.call_site(&target_fn); | ||
assert!(src.output().flows_to_data(&target.input())); | ||
assert!(!not_src.output().flows_to_data(&target.input())); | ||
}); | ||
|
||
define_test!(assigns_marker_generic: graph -> { | ||
let sources = graph.marked(Identifier::new_intern("source")); | ||
let mark = graph.marked(Identifier::new_intern("mark")); | ||
let target = graph.marked(Identifier::new_intern("target")); | ||
assert!(!sources.is_empty()); | ||
assert!(!mark.is_empty()); | ||
assert!(!target.is_empty()); | ||
assert!(sources.flows_to_data(&mark)); | ||
assert!(mark.flows_to_data(&target)); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[workspace] | ||
members = ["dependency", "entry"] |
6 changes: 6 additions & 0 deletions
6
crates/paralegal-flow/tests/cross-crate/dependency/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[package] | ||
name = "dependency" | ||
version = "0.0.1" | ||
|
||
[dependencies] | ||
paralegal = { path = "../../../../paralegal" } |
30 changes: 30 additions & 0 deletions
30
crates/paralegal-flow/tests/cross-crate/dependency/src/lib.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
pub fn find_me(a: usize, _b: usize) -> usize { | ||
a | ||
} | ||
|
||
#[paralegal::marker(mark, return)] | ||
pub fn source() -> usize { | ||
0 | ||
} | ||
|
||
#[paralegal::marker(mark, return)] | ||
fn taint_it<A>(_: A) -> A { | ||
unimplemented!() | ||
} | ||
|
||
pub fn assign_marker(a: usize) -> usize { | ||
taint_it(a) | ||
} | ||
|
||
pub fn find_me_generic<A>(a: A, _b: A) -> A { | ||
a | ||
} | ||
|
||
#[paralegal::marker(mark, return)] | ||
pub fn generic_source<A>() -> A { | ||
unimplemented!() | ||
} | ||
|
||
pub fn assign_marker_generic<A>(a: A) -> A { | ||
taint_it(a) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[package] | ||
name = "entry" | ||
version = "0.0.1" | ||
|
||
[dependencies] | ||
dependency = { path = "../dependency" } | ||
paralegal = { path = "../../../../paralegal" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
extern crate dependency; | ||
|
||
use dependency::{assign_marker, assign_marker_generic, find_me, find_me_generic, source}; | ||
|
||
#[paralegal::marker(source, return)] | ||
fn src() -> usize { | ||
0 | ||
} | ||
|
||
#[paralegal::marker(not_source)] | ||
fn not_src() -> usize { | ||
1 | ||
} | ||
|
||
#[paralegal::marker(target, arguments = [0])] | ||
fn target(u: usize) {} | ||
|
||
#[paralegal::analyze] | ||
fn basic() { | ||
target(find_me(src(), not_src())) | ||
} | ||
|
||
#[paralegal::analyze] | ||
fn basic_marker() { | ||
target(source()); | ||
} | ||
|
||
#[paralegal::analyze] | ||
fn assigns_marker() { | ||
target(assign_marker(src())); | ||
} | ||
|
||
#[paralegal::analyze] | ||
fn basic_generic() { | ||
target(find_me_generic(src(), not_src())) | ||
} | ||
|
||
#[paralegal::analyze] | ||
fn assigns_marker_generic() { | ||
target(assign_marker_generic(src())); | ||
} | ||
|
||
fn main() {} |