Equim-chan / Mortal

🚀🀄️ A fast and strong AI for riichi mahjong, powered by Rust and deep reinforcement learning.
https://mortal.ekyu.moe
GNU Affero General Public License v3.0
929 stars 118 forks source link

Fail to run doc test under `libriichi` #2

Closed JaySon-Huang closed 2 years ago

JaySon-Huang commented 2 years ago

First I try to run tests under libriichi directly and get errors like

> cd Mortal/libriichi
>  cargo test
    Finished test [unoptimized + debuginfo] target(s) in 0.09s
     Running unittests src/lib.rs (/path/to/Mortal/target/debug/deps/riichi-47b47cdd3de647c5)
dyld[69996]: symbol not found in flat namespace '_PyBaseObject_Type'
error: test failed, to rerun pass '--lib'

Caused by:
  process didn't exit successfully: `/path/to/Mortal/target/debug/deps/riichi-47b47cdd3de647c5` (signal: 6, SIGABRT: process abort signal)

Then I follow the FAQ of pyo3 i-cant-run-cargo-test and get errors like

>  cargo test --no-default-features
   Compiling pyo3 v0.15.2
   Compiling numpy v0.15.1
   Compiling libriichi v0.1.0 (/path/to/Mortal/libriichi)
    Finished test [unoptimized + debuginfo] target(s) in 4.85s
     Running unittests src/lib.rs (/path/to/Mortal/target/debug/deps/riichi-069c85f8695c006a)

running 21 tests
test hand::test::parse ... ok
test arena::result::test::rankings ... ok
test macros::test::completeness ... ok
test hand::test::string ... ok
test macros::test::syntax ... ok
test state::test::can_chi ... ok
test algo::agari::test::agari_calc ... ok
test algo::shanten::test::calc_3n_plus_3 ... ok
test algo::shanten::test::calc_3n_plus_1 ... ok
test algo::shanten::test::calc_3n_plus_2 ... ok
test state::test::dora_count_after_kan ... ok
test state::test::get_rank ... ok
test state::test::furiten ... ok
test algo::agari::test::ankan_after_riichi ... ok
test state::test::waits ... ok
test tile::test::next_prev ... ok
test state::test::rule_based_agari_all_last_minogashi ... ok
test state::test::kakan_from_hand ... ok
test state::test::double_chankan_ron ... ok
test state::test::discard_candidates_with_unconditional_tenpai ... ok
test arena::game::test::tsumogiri ... ok

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

     Running unittests src/bin/stat.rs (/path/to/Mortal/target/debug/deps/stat-fba45acd61b1da13)

running 0 tests

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

     Running unittests src/bin/validate_logs.rs (/path/to/Mortal/target/debug/deps/validate_logs-6345802e6d8664c1)

running 0 tests

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

   Doc-tests riichi

running 1 test
test src/agent/batchify.rs - agent::batchify::BatchifiedAgent<A>::new (line 23) ... FAILED

failures:

---- src/agent/batchify.rs - agent::batchify::BatchifiedAgent<A>::new (line 23) stdout ----
error[E0432]: unresolved import `riichi::agent::Tsumogiri`
 --> src/agent/batchify.rs:24:50
  |
4 | use riichi::agent::{BatchAgent, BatchifiedAgent, Tsumogiri};
  |                                                  ^^^^^^^^^ no `Tsumogiri` in `agent`

error[E0603]: module `agent` is private
  --> src/agent/batchify.rs:24:13
   |
4  | use riichi::agent::{BatchAgent, BatchifiedAgent, Tsumogiri};
   |             ^^^^^ private module
   |
note: the module `agent` is defined here
  --> /path/to/Mortal/libriichi/src/lib.rs:11:1
   |
11 | mod agent;
   | ^^^^^^^^^^

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0432, E0603.
For more information about an error, try `rustc --explain E0432`.
Couldn't compile the test.

failures:
    src/agent/batchify.rs - agent::batchify::BatchifiedAgent<A>::new (line 23)

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

error: test failed, to rerun pass '--doc'
Equim-chan commented 2 years ago

You should run this

$ cargo test --lib --no-default-features --features flate2/zlib

bin and lib are exclusive targets, and they should be built/tested separately. I'm not sure if it is one of pyo3's limitations.

flate2/zlib is optional but recommended, because flate2 uses Rust implementation by default, which is slow in debug profile.

This is also the way tests are configuered to run in CI:

https://github.com/Equim-chan/Mortal/blob/fdaef5339cf1a6722c9167e41a526b831893c053/.github/workflows/libriichi.yml#L55-L56

I should have included this info in the doc, will add it later.