Run all tests without arguments

オープン
#2,028 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
cmake, cpp

調査の方向性

まず test/CMakeLists.txt、test/BUILD、test/spec_arg_test.cc、そして perf_counters_test の引数から始め、その後、現在引数を必要としているテストの main 関数を調べます。テストスイートをユーザーが引数を指定しなくても実行でき、ビルド定義全体でデフォルト引数が一貫して適用され、既存の引数依存テストが引き続き成功すれば完了です。

索引モデルが issue の本文から書いたものです。

説明

Hi! I find it confusing that the tests require arguments. I want to change it.

Here are my reasons:

  1. Not all tests check for required arguments
    https://github.com/google/benchmark/blob/7697796fe5a70edbc3394d0593ef82afeebb7ddf/test/spec_arg_test.cc#L63-L70 and so it's easy to run a test incorrectly.
  2. There are GitHub issues mentioning that a test fails when the actual problem was that the correct arguments were not passed.
  3. Arguments need to be duplicated between test/CMakeLists.txt and test/BUILD and they are actually not in sync now (perf_counters_test is run with different arguments).

My solution:

  1. Create test/default_arguments.h:
// ...

void AddTestArguments(int &argc, char **&argv, std::initializer_list<char const*> args={}) {
  if (argc > 1) {
    std::cout << "Warning: User is not expected to pass any command line arguments\n";
  }
  static std::vector<char const*> new_argv;
  new_argv.insert(new_argv.end(), argv, argv + argc);
  new_argv.insert(new_argv.end(), args.begin(), args.end());
  new_argv.push_back("--benchmark_min_time=0.01s");
  argv = const_cast<char**>(new_argv.data());
  argc = static_cast<int>(new_argv.size());
}
  1. Call it after each main function like this
int main(int argc, char* argv[]) {
  AddTestArguments(argc, argv, {"--benchmark_counters_tabular=true"});
  benchmark::MaybeReenterWithoutASLR(argc, argv);
  RunOutputTests(argc, argv);
}
  1. Cleanup the code

Sounds good?

主要言語
C++
スター
10.5k
フォーク
1.8k
平均マージ
1日 15時間
マージ済み PR(30日)
28

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

google/benchmark のほかの issue

google/benchmark の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。