dir-path-2-tree · Rust

One task in several forms: recursive, iterative, with an explicit stack and with a depth limit - measured, tested, and shown where recursion overflows the stack.

Stack overflow demonstration, this run

A path of depth 5 000 on a thread with 64 KiB of stack; each crashing case runs in a child process (tests/stack_overflow.rs).

    Finished `test` profile [unoptimized + debuginfo] target(s) in 0.06s
     Running tests/stack_overflow.rs (target/debug/deps/stack_overflow-c60b7379aeda36a7)

running 5 tests
test iterative_insert_write_and_drop_need_no_call_stack ... ok
test recursive_drop_overflows_the_stack ... recursive_drop_overflows_the_stack: the child ended with signal: 6 (SIGABRT) (core dumped)
    thread '<unknown>' (4274) has overflowed its stack
    fatal runtime error: stack overflow, aborting
ok
test recursive_insert_overflows_the_stack ... recursive_insert_overflows_the_stack: the child ended with signal: 6 (SIGABRT) (core dumped)
    thread '<unknown>' (4282) has overflowed its stack
    fatal runtime error: stack overflow, aborting
ok
test recursive_write_overflows_the_stack ... recursive_write_overflows_the_stack: the child ended with signal: 6 (SIGABRT) (core dumped)
    thread '<unknown>' (4296) has overflowed its stack
    fatal runtime error: stack overflow, aborting
ok
test the_depth_limit_turns_the_crash_into_an_error ... the_depth_limit_turns_the_crash_into_an_error: Maximum tree depth 30 exceeded (current depth: 31)
ok

test result: ok. 5 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.54s

All tests, this run

    Updating crates.io index
 Downloading crates ...
  Downloaded autocfg v1.5.1
  Downloaded anstyle-query v1.1.5
  Downloaded clap_lex v1.0.0
  Downloaded typed-builder v0.15.2
  Downloaded colorchoice v1.0.4
  Downloaded async-trait v0.1.89
  Downloaded ciborium-ll v0.2.2
  Downloaded lazy-regex-proc_macros v3.6.0
  Downloaded ciborium-io v0.2.2
  Downloaded unicode-linebreak v0.1.5
  Downloaded bitflags v1.3.2
  Downloaded anstyle v1.0.13
  Downloaded itoa v1.0.17
  Downloaded cast v0.3.0
  Downloaded drain_filter_polyfill v0.1.3
  Downloaded pin-utils v0.1.0
  Downloaded errno v0.3.14
  Downloaded heck v0.5.0
  Downloaded futures-sink v0.3.31
  Downloaded peg v0.6.3
  Downloaded scopeguard v1.2.0
  Downloaded futures-io v0.3.31
  Downloaded smart-default v0.7.1
  Downloaded strsim v0.11.1
  Downloaded terminal_size v0.4.3
  Downloaded synthez v0.3.1
  Downloaded synthez-codegen v0.3.1
  Downloaded typed-builder-macro v0.15.2
  Downloaded cfg-if v1.0.4
  Downloaded linked-hash-map v0.5.6
  Downloaded plotters-backend v0.3.7
  Downloaded plotters-svg v0.3.7
  Downloaded is_terminal_polyfill v1.70.2
  Downloaded sealed v0.5.0
  Downloaded futures-macro v0.3.31
  Downloaded is-terminal v0.4.17
  Downloaded lazy-regex v3.6.0
  Downloaded same-file v1.0.6
  Downloaded peg-runtime v0.6.3
  Downloaded heck v0.4.1
  Downloaded anstyle-parse v0.2.7
  Downloaded bytecount v0.6.9
  Downloaded utf8parse v0.2.2
  Downloaded anes v0.1.6
  Downloaded crossbeam-deque v0.8.6
  Downloaded futures-channel v0.3.31
  Downloaded globwalk v0.8.1
  Downloaded anstream v0.6.21
  Downloaded cucumber-expressions v0.3.0
  Downloaded bitflags v2.10.0
  Downloaded smawk v0.3.2
  Downloaded tokio-macros v2.6.0
  Downloaded futures-executor v0.3.31
  Downloaded oorandom v11.1.5
  Downloaded pin-project-lite v0.2.16
  Downloaded slab v0.4.12
  Downloaded synthez-core v0.3.1
  Downloaded thiserror v1.0.69
  Downloaded tinytemplate v1.2.1
  Downloaded walkdir v2.5.0
  Downloaded zmij v1.0.21
  Downloaded criterion-plot v0.5.0
  Downloaded cucumber-codegen v0.20.2
  Downloaded futures-core v0.3.31
  Downloaded globset v0.4.18
  Downloaded futures-task v0.3.31
  Downloaded inventory v0.3.21
  Downloaded either v1.15.0
  Downloaded inflections v1.1.1
  Downloaded humantime v2.3.0
  Downloaded lock_api v0.4.14
  Downloaded quote v1.0.44
  Downloaded gherkin v0.14.0
  Downloaded nom_locate v4.2.0
  Downloaded peg-macros v0.6.3
  Downloaded clap_derive v4.5.55
  Downloaded console v0.15.11
  Downloaded anyhow v1.0.101
  Downloaded signal-hook-registry v1.4.8
  Downloaded thiserror-impl v1.0.69
  Downloaded crossbeam-utils v0.8.21
  Downloaded parking_lot_core v0.9.12
  Downloaded pin-project-internal v1.1.10
  Downloaded parking_lot v0.12.5
  Downloaded once_cell v1.21.3
  Downloaded derive_more v0.99.20
  Downloaded crossbeam-epoch v0.9.18
  Downloaded ignore v0.4.25
  Downloaded smallvec v1.15.1
  Downloaded unicode-ident v1.0.23
  Downloaded half v2.7.1
  Downloaded ciborium v0.2.2
  Downloaded futures v0.3.31
  Downloaded proc-macro2 v1.0.106
  Downloaded pin-project v1.1.10
  Downloaded serde_core v1.0.228
  Downloaded bytes v1.11.1
  Downloaded clap v4.5.58
  Downloaded num-traits v0.2.19
  Downloaded socket2 v0.6.2
  Downloaded rayon-core v1.13.0
  Downloaded log v0.4.29
  Downloaded serde_derive v1.0.228
  Downloaded textwrap v0.16.2
  Downloaded zerocopy-derive v0.8.61
  Downloaded memchr v2.8.0
  Downloaded aho-corasick v1.1.4
  Downloaded mio v1.1.1
  Downloaded itertools v0.10.5
  Downloaded minimal-lexical v0.2.1
  Downloaded nom v7.1.3
  Downloaded cucumber v0.20.2
  Downloaded criterion v0.5.1
  Downloaded serde v1.0.228
  Downloaded plotters v0.3.7
  Downloaded futures-util v0.3.31
  Downloaded itertools v0.12.1
  Downloaded regex v1.12.3
  Downloaded clap_builder v4.5.58
  Downloaded serde_json v1.0.149
  Downloaded rayon v1.12.0
  Downloaded bstr v1.12.1
  Downloaded regex-syntax v0.7.5
  Downloaded regex-syntax v0.8.9
  Downloaded rustix v1.1.3
  Downloaded regex-automata v0.4.14
  Downloaded unicode-width v0.2.2
  Downloaded syn v2.0.115
  Downloaded zerocopy v0.8.61
  Downloaded libc v0.2.182
  Downloaded linux-raw-sys v0.11.0
  Downloaded tokio v1.49.0
   Compiling proc-macro2 v1.0.106
   Compiling unicode-ident v1.0.23
   Compiling quote v1.0.44
   Compiling memchr v2.8.0
   Compiling regex-syntax v0.8.9
   Compiling libc v0.2.182
   Compiling zmij v1.0.21
   Compiling syn v2.0.115
   Compiling crossbeam-utils v0.8.21
   Compiling aho-corasick v1.1.4
   Compiling either v1.15.0
   Compiling serde_json v1.0.149
   Compiling heck v0.4.1
   Compiling regex-automata v0.4.14
   Compiling itoa v1.0.17
   Compiling serde_core v1.0.228
   Compiling minimal-lexical v0.2.1
   Compiling crossbeam-epoch v0.9.18
   Compiling rustix v1.1.3
   Compiling cfg-if v1.0.4
   Compiling crossbeam-deque v0.8.6
   Compiling serde_derive v1.0.228
   Compiling linux-raw-sys v0.11.0
   Compiling zerocopy v0.8.61
   Compiling utf8parse v0.2.2
   Compiling bitflags v2.10.0
   Compiling bytecount v0.6.9
   Compiling serde v1.0.228
   Compiling anstyle-parse v0.2.7
   Compiling zerocopy-derive v0.8.61
   Compiling regex v1.12.3
   Compiling sealed v0.5.0
   Compiling autocfg v1.5.1
   Compiling futures-sink v0.3.31
   Compiling pin-project-lite v0.2.16
   Compiling is_terminal_polyfill v1.70.2
   Compiling anstyle v1.0.13
   Compiling same-file v1.0.6
   Compiling colorchoice v1.0.4
   Compiling anstyle-query v1.1.5
   Compiling futures-core v0.3.31
   Compiling anstream v0.6.21
   Compiling walkdir v2.5.0
   Compiling futures-channel v0.3.31
   Compiling num-traits v0.2.19
   Compiling synthez-core v0.3.1
   Compiling terminal_size v0.4.3
   Compiling futures-macro v0.3.31
   Compiling derive_more v0.99.20
   Compiling nom v7.1.3
   Compiling bstr v1.12.1
   Compiling pin-utils v0.1.0
   Compiling log v0.4.29
   Compiling strsim v0.11.1
   Compiling slab v0.4.12
   Compiling clap_lex v1.0.0
   Compiling regex-syntax v0.7.5
   Compiling unicode-width v0.2.2
   Compiling futures-task v0.3.31
   Compiling parking_lot_core v0.9.12
   Compiling once_cell v1.21.3
   Compiling futures-io v0.3.31
   Compiling heck v0.5.0
   Compiling peg-runtime v0.6.3
   Compiling rayon-core v1.13.0
   Compiling thiserror v1.0.69
   Compiling peg-macros v0.6.3
   Compiling clap_derive v4.5.55
   Compiling half v2.7.1
   Compiling futures-util v0.3.31
   Compiling nom_locate v4.2.0
   Compiling clap_builder v4.5.58
   Compiling globset v0.4.18
   Compiling gherkin v0.14.0
   Compiling synthez-codegen v0.3.1
   Compiling thiserror-impl v1.0.69
   Compiling typed-builder-macro v0.15.2
   Compiling plotters-backend v0.3.7
   Compiling ciborium-io v0.2.2
   Compiling unicode-linebreak v0.1.5
   Compiling smawk v0.3.2
   Compiling scopeguard v1.2.0
   Compiling smallvec v1.15.1
   Compiling anyhow v1.0.101
   Compiling textwrap v0.16.2
   Compiling lock_api v0.4.14
   Compiling ciborium-ll v0.2.2
   Compiling plotters-svg v0.3.7
   Compiling typed-builder v0.15.2
   Compiling futures-executor v0.3.31
   Compiling clap v4.5.58
   Compiling synthez v0.3.1
   Compiling ignore v0.4.25
   Compiling cucumber-expressions v0.3.0
   Compiling peg v0.6.3
   Compiling lazy-regex-proc_macros v3.6.0
   Compiling pin-project-internal v1.1.10
   Compiling itertools v0.10.5
   Compiling itertools v0.12.1
   Compiling errno v0.3.14
   Compiling cast v0.3.0
   Compiling bitflags v1.3.2
   Compiling inflections v1.1.1
   Compiling pin-project v1.1.10
   Compiling globwalk v0.8.1
   Compiling signal-hook-registry v1.4.8
   Compiling tinytemplate v1.2.1
   Compiling criterion-plot v0.5.0
   Compiling lazy-regex v3.6.0
   Compiling rayon v1.12.0
   Compiling plotters v0.3.7
   Compiling cucumber-codegen v0.20.2
   Compiling futures v0.3.31
   Compiling ciborium v0.2.2
   Compiling parking_lot v0.12.5
   Compiling console v0.15.11
   Compiling smart-default v0.7.1
   Compiling tokio-macros v2.6.0
   Compiling async-trait v0.1.89
   Compiling is-terminal v0.4.17
   Compiling mio v1.1.1
   Compiling socket2 v0.6.2
   Compiling oorandom v11.1.5
   Compiling bytes v1.11.1
   Compiling drain_filter_polyfill v0.1.3
   Compiling anes v0.1.6
   Compiling inventory v0.3.21
   Compiling humantime v2.3.0
   Compiling linked-hash-map v0.5.6
   Compiling criterion v0.5.1
   Compiling cucumber v0.20.2
   Compiling dir-path-2-tree v0.1.0 (/home/runner/work/dir-path-2-tree/dir-path-2-tree)
   Compiling tokio v1.49.0
    Finished `test` profile [unoptimized + debuginfo] target(s) in 23.68s
     Running unittests src/lib.rs (target/debug/deps/dir_path_2_tree-af6684410be6bb49)

running 7 tests
test tests::test_complex_tree_structure ... ok
test tests::test_insert_empty_parts ... ok
test tests::test_insert_multiple_paths ... ok
test tests::test_insert_overlapping_paths ... ok
test tests::test_insert_single_path ... ok
test tests::test_insert_single_element ... ok
test tests::test_tree_structure_is_sorted ... ok

test result: ok. 7 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running unittests src/main.rs (target/debug/deps/dir_path_2_tree-0d5856a549145298)

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running tests/equivalence.rs (target/debug/deps/equivalence-608bb36d0c62d253)

running 4 tests
test the_iterative_variant_keeps_the_pre_order ... ok
test the_safe_variant_stops_at_its_limit ... ok
test every_write_variant_writes_the_same_lines ... ok
test every_insert_variant_builds_the_same_tree ... ok

test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running tests/features.rs (target/debug/deps/features-509b30730d0feede)

running 1 test
Feature: Build and display tree structure from dot-separated paths
  Scenario: Build tree from file.txt input
   ✔  Given I have a file with dot-separated paths:
       | var.text.bla.bla  |
       | usr.bin.bash      |
       | usr.bin.c         |
       | home.me.and.you   |
       | var.you.dont.know |
       | home.me.can.dont  |
   ✔  When I build the tree
   ✔  Then the output should match:
  Scenario: Build tree from single nested path
   ✔  Given I have a file with dot-separated paths:
       | a.b.c |
   ✔  When I build the tree
   ✔  Then the output should match:
  Scenario: Build tree from paths with multiple branches
   ✔  Given I have a file with dot-separated paths:
       | a.b.c |
       | a.b.d |
       | a.e   |
   ✔  When I build the tree
   ✔  Then the output should match:
[Summary]
1 feature
3 scenarios (3 passed)
9 steps (9 passed)
test tests::cucumber_tests ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running tests/integration_test.rs (target/debug/deps/integration_test-b61d5233108f7b13)

running 2 tests
test test_multiple_paths ... ok
test test_single_path ... ok

test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running tests/stack_overflow.rs (target/debug/deps/stack_overflow-c60b7379aeda36a7)

running 5 tests
test iterative_insert_write_and_drop_need_no_call_stack ... ok
test the_depth_limit_turns_the_crash_into_an_error ... ok
test recursive_insert_overflows_the_stack ... ok
test recursive_drop_overflows_the_stack ... ok
test recursive_write_overflows_the_stack ... ok

test result: ok. 5 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.24s

   Doc-tests dir_path_2_tree

running 3 tests
test src/lib.rs - insert_path_iterative (line 56) ... ok
test src/lib.rs - insert_path (line 30) ... ok
test src/lib.rs - print_tree_safe (line 220) ... ok

test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.14s