Skip to content

Add a tool to run the tests of dependencies #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

qryxip
Copy link
Member

@qryxip qryxip commented Nov 25, 2019

#1 のためのツールを作りました。 「テストを一々書かなくてもdependencyの元々のテストを使えばいいのでは?」という考えです。

cargo (binの方)には元々dependencyに含まれているtargetを直接実行する機能があります。

$ cargo test -p maplit -p num

しかしこれには致命的な制限があり、dev-dependencyが1つでもあると駄目です。 現在のdependency graph上で解決可能であってもです。 というよりCargo.lockにはdev-dependenciesのすべてが含まれているはずですが。

$ cargo test -p regex
error: package `regex` cannot be tested because it requires dev-dependencies and is not a member of the workspace

今回作ったツール、dep-testsは以下の動作をします。

  1. 現在のdependency graphからplatformに合致したnormal-dependencyの関係のみからなる部分グラフ上のpackageを求める。 (ただしatcoder-rust-base自身を除く) -d 1を指定するとatcoder-rust-base[dependencies]だけになる。
  2. $TMPDIR/atcoder-rust-base-dep-tests/かどこかにそのpackageの為のworkspaceをN個作成する。 具体的には$CARGO_HOME/registryからコピーしたものにatcoder-rust-baseCargo.lockを突っ込む。Cargo.lockはrootがどことかは書かれていないのでそのままのバージョンで動く。 (sourceが異なってくるはずだが何故かCargo.lockはupdateされない。) N個のworkspaceに分離する理由はfeaturesの状態を極力保存するため。
  3. N個のworkspaceでcargo testする。この際current workspace member (= 元のdependencyの一つ)のみ元のfeaturesを再現する。

現状問題のある点としてN個のビルドキャッシュを作るので時間とディスク容量によろしくないことと、いくつかのpackageがよくわからない理由でテスト(のビルド)に失敗してそれにjemallocatorpetgraphが含まれていることですね。 (./dep-tests.toml参照。)

$ cargo dep-tests --help
    Finished dev [unoptimized + debuginfo] target(s) in 0.06s
     Running `dep-tests/target/debug/dep-tests --help`
dep-tests 0.0.0
Run all of the tests in the dependency graph.

USAGE:
    dep-tests [FLAGS] [OPTIONS] <dir>

FLAGS:
        --all-features           Activate all available features
        --no-default-features    Do not activate the `default` feature
        --frozen                 Require Cargo.lock and cache are up to date
        --locked                 Require Cargo.lock is up to date
        --offline                Run without accessing the network
    -h, --help                   Prints help information
    -V, --version                Prints version information

OPTIONS:
    -p, --package <SPEC>...         **Dependency** to run test for
        --features <FEATURES>...    Space-separated list of features to activate
        --color <WHEN>              Coloring: auto, always, never
    -d, --depth <N>                 How deep in the dependency chain to search
        --skip <N>                  Skips the first N packages

ARGS:
    <dir>    Directory to run tests [default: /tmp/atcoder-rust-base-dep-tests]

またdep-testscargo で npm-scripts 的なことをするで紹介された方法で起動します。 依存関係を独立させる方の方法なのでcwdがatcoder-lang-jaである必要があります。

[alias]
dep-tests = ["run", "--manifest-path", "./dep-tests/Cargo.toml", "--"]

@statiolake
Copy link
Contributor

なるほど、ありがとうございます。これは便利そうですね。こちらでも選択したバージョンのライブラリに問題がないかどうかを最終確認できてよいと思います。

ただ、とりあえず元々の #1 の目的としては、現在コンパイルに Cargo を利用しないで rustc を直接利用する方針で進めているので、用意したツールの生成するコンパイルオプションできちんとバイナリが作成・リンクされるかを確かめるためのテストが必要だろうということだったと思います。ですので必要最低限、依存クレートを利用してもコンパイル・リンクできますよということだけでも確かめるテストについては、追加する必要は依然としてあるかと思います。 (つまり、あのテストプロジェクトをツールに与えて生成されたコンパイルオプションで rustc を叩いて、それで正常にバイナリが生成されることを確認したいので、そのためのテストコードが必要ということでした。)

いっそそれも Github Actions か何かに登録するとよいかもしれませんね。

@statiolake statiolake merged commit edddabb into rust-lang-ja:ja-all-enabled Nov 26, 2019
@qryxip qryxip deleted the ja-all-enabled-dep-tests branch November 26, 2019 07:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants