Skip to content
This repository was archived by the owner on Sep 9, 2025. It is now read-only.

Commit 3bc764c

Browse files
author
Hendrik van Antwerpen
committed
Add test demonstrating non-termination on certain paths
1 parent 71bf812 commit 3bc764c

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

stack-graphs/tests/it/cycles.rs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ use std::time::Duration;
1616

1717
use crate::util::*;
1818

19+
const TEST_TIMEOUT: Duration = Duration::from_secs(3);
20+
1921
// ----------------------------------------------------------------------------
2022
// productive paths
2123

@@ -167,7 +169,7 @@ fn finding_simple_identity_cycle_is_detected() {
167169
// test termination of path finding
168170
{
169171
let mut path_count = 0usize;
170-
let cancellation_flag = CancelAfterDuration::new(Duration::from_secs(10));
172+
let cancellation_flag = CancelAfterDuration::new(TEST_TIMEOUT);
171173
let result = partials.find_minimal_partial_path_set_in_file(
172174
&graph,
173175
file,
@@ -269,7 +271,7 @@ fn finding_composite_identity_cycle_is_detected() {
269271
// test termination of path finding
270272
{
271273
let mut path_count = 0usize;
272-
let cancellation_flag = CancelAfterDuration::new(Duration::from_secs(10));
274+
let cancellation_flag = CancelAfterDuration::new(TEST_TIMEOUT);
273275
let result = partials.find_minimal_partial_path_set_in_file(
274276
&graph,
275277
file,
@@ -311,3 +313,29 @@ fn stitching_composite_identity_cycle_is_detected() {
311313
.is_err());
312314
}
313315
}
316+
317+
#[test]
318+
fn appending_eliminating_cycle_terminates() {
319+
let mut graph = StackGraph::new();
320+
let file = graph.add_file("test").unwrap();
321+
let r = StackGraph::root_node();
322+
let s = create_scope_node(&mut graph, file, false);
323+
let foo_def = create_pop_symbol_node(&mut graph, file, "foo", false);
324+
325+
let mut partials = PartialPaths::new();
326+
create_partial_path_and_edges(&mut graph, &mut partials, &[r, s, foo_def, s, r]).unwrap();
327+
328+
// test termination of path finding
329+
{
330+
let mut path_count = 0usize;
331+
let cancellation_flag = CancelAfterDuration::new(TEST_TIMEOUT);
332+
let result = partials.find_minimal_partial_path_set_in_file(
333+
&graph,
334+
file,
335+
&cancellation_flag,
336+
|_, _, _| path_count += 1,
337+
);
338+
assert!(result.is_ok());
339+
assert_eq!(0, path_count);
340+
}
341+
}

0 commit comments

Comments
 (0)