main.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #pragma once
  2. #include <iosfwd>
  3. #include <string>
  4. #include <string_view>
  5. #include <unordered_map>
  6. #include <vector>
  7. /**
  8. * You need to use these functions if you're customizing tests initialization
  9. * or writing a custom `main`.
  10. */
  11. namespace NGTest {
  12. /**
  13. * Default `main` implementation.
  14. */
  15. int Main(int argc, char** argv);
  16. /**
  17. * CLI parsing result.
  18. */
  19. struct TFlags {
  20. /**
  21. * Argument for `ListTests` function.
  22. */
  23. int ListLevel = 0;
  24. /**
  25. * Where to print listed tests. Empty string means print to `stdout`.
  26. */
  27. std::string ListPath = "";
  28. /**
  29. * Path to trace file. If empty, tracing is not enabled.
  30. */
  31. std::string TracePath = "";
  32. /**
  33. * Should trace file be opened for append rather than just write.
  34. */
  35. bool AppendTrace = false;
  36. /**
  37. * Test filters.
  38. */
  39. std::string Filter = "*";
  40. /**
  41. * Number of CLI arguments for GTest init function (not counting the last null one).
  42. */
  43. int GtestArgc = 0;
  44. /**
  45. * CLI arguments for GTest init function.
  46. * The last one is nullptr.
  47. */
  48. std::vector<char*> GtestArgv = {};
  49. };
  50. /**
  51. * Parse unittest-related flags. Test binaries support flags from `library/cpp/testing/unittest` and flags from gtest.
  52. * This means that there are usually two parsing passes. The first one parses arguments as recognized
  53. * by the `library/cpp/testing/unittest`, so things like `--trace-path` and filters. The second one parses flags
  54. * as recognized by gtest.
  55. */
  56. TFlags ParseFlags(int argc, char** argv);
  57. /**
  58. * List tests using the unittest style and exit.
  59. *
  60. * This function should be called after initializing google tests because test parameters are instantiated
  61. * during initialization.
  62. *
  63. * @param listLevel verbosity of test list. `0` means don't print anything and don't exit, `1` means print
  64. * test suites, `2` means print individual tests.
  65. */
  66. void ListTests(int listLevel, const std::string& listPath);
  67. /**
  68. * Remove default result reporter, the one that prints to stdout.
  69. */
  70. void UnsetDefaultReporter();
  71. /**
  72. * Set trace reporter.
  73. *
  74. * Trace files are used by arcadia CI to interact with test runner. They consist of JSON objects, one per line.
  75. * Each object represents an event, such as 'test started' or 'test finished'.
  76. *
  77. * @param traceFile where to write trace file. This stream should exist for the entire duration of test run.
  78. */
  79. void SetTraceReporter(std::ostream* traceFile);
  80. }