tests.toml 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. [tasks.dart_unit_test]
  2. dependencies = ["build-test-lib"]
  3. description = "Run flutter unit tests"
  4. script = '''
  5. cd app_flowy
  6. flutter test --dart-define=RUST_LOG=${TEST_RUST_LOG} --concurrency=1
  7. '''
  8. [tasks.rust_unit_test]
  9. run_task = { name = ["rust_lib_unit_test", "shared_lib_unit_test"] }
  10. [tasks.rust_lib_unit_test]
  11. description = "Run rust-lib unit tests"
  12. script = '''
  13. cd rust-lib
  14. RUST_LOG=info cargo test --no-default-features --features="sync"
  15. '''
  16. [tasks.shared_lib_unit_test]
  17. description = "Run shared-lib unit test"
  18. script = '''
  19. cd ../shared-lib
  20. RUST_LOG=info cargo test --no-default-features
  21. '''
  22. [tasks.check_grcov]
  23. description = "Check if `grcov` is installled"
  24. script_runner = "@shell"
  25. script = '''
  26. export PATH=$PATH:"$HOME/.cargo/bin/"
  27. if command -v grcov > /dev/null; then
  28. echo "Found 'grcov' executable."
  29. else
  30. echo "[!] Could not find 'grcov' executable."
  31. echo "[!] Please install 'grcov' by running 'cargo install grcov'."
  32. echo "[!] You may also need to install 'llvm-tools-preview' using 'rustup component add llvm-tools-preview'."
  33. echo "[!] If installed, check if 'grcov' is in PATH."
  34. echo "[!] Exiting..."
  35. exit -1
  36. fi
  37. '''
  38. [tasks.clean_profraw_files]
  39. description = "Cleans profraw files that are created by `cargo test`"
  40. script_runner = "@duckscript"
  41. script = [
  42. """
  43. rust_lib_profs = glob_array ./rust-lib/**/*.profraw
  44. for prof in ${rust_lib_profs}
  45. full_path = canonicalize ${prof}
  46. rm ${full_path}
  47. end
  48. shared_lib_profs = glob_array ../shared-lib/**/*.profraw
  49. for prof in ${shared_lib_profs}
  50. full_path = canonicalize ${prof}
  51. rm ${full_path}
  52. end
  53. """
  54. ]
  55. [tasks.run_rustlib_coverage_tests]
  56. description = "Run tests with coverage instrumentation"
  57. script_runner = "@shell"
  58. script = [
  59. """
  60. echo --- Running coverage tests ---
  61. # Install Protobuf compiler
  62. cargo make install_protobuf_compiler
  63. export PATH="$PATH":"$HOME/.pub-cache/bin"
  64. export PATH="$PATH":"$HOME/.cargo/bin/"
  65. cd rust-lib/
  66. CARGO_INCREMENTAL=0 \
  67. RUSTFLAGS='-C instrument-coverage' \
  68. LLVM_PROFILE_FILE='prof-%p-%m.profraw' \
  69. cargo test --no-default-features --features="sync"
  70. """
  71. ]
  72. [tasks.run_sharedlib_coverage_tests]
  73. description = "Run tests with coverage instrumentation"
  74. script_runner = "@shell"
  75. script = [
  76. """
  77. echo --- Running coverage tests ---
  78. # Install Protobuf compiler
  79. cargo make install_protobuf_compiler
  80. export PATH="$PATH":"$HOME/.pub-cache/bin"
  81. export PATH="$PATH":"$HOME/.cargo/bin/"
  82. cd ../shared-lib
  83. CARGO_INCREMENTAL=0 \
  84. RUSTFLAGS='-C instrument-coverage' \
  85. LLVM_PROFILE_FILE='prof-%p-%m.profraw' \
  86. cargo test --no-default-features
  87. """
  88. ]
  89. [tasks.get_rustlib_grcov_report]
  90. description = "Get `grcov` HTML report for test coverage for rust-lib"
  91. script_runner = "@shell"
  92. script = [
  93. """
  94. echo --- Getting 'grcov' results for 'rust-lib' ---
  95. cd rust-lib/
  96. grcov . \
  97. --binary-path target/debug/deps \
  98. --source-dir . \
  99. --output-type html \
  100. --branch \
  101. --ignore-not-existing \
  102. --log-level WARN \
  103. --output-path target/coverage-html
  104. echo "--- Done! Generated HTML report under 'target/coverage-html' for rustlib."
  105. """
  106. ]
  107. [tasks.get_sharedlib_grcov_report]
  108. description = "Get `grcov` HTML report for test coverage shared-lib"
  109. script_runner = "@shell"
  110. script = [
  111. """
  112. echo --- Getting 'grcov' results 'shared-lib' ---
  113. cd ../shared-lib
  114. grcov . \
  115. --binary-path target/debug/deps \
  116. --source-dir . \
  117. --output-type html \
  118. --branch \
  119. --ignore-not-existing \
  120. --log-level WARN \
  121. --output-path target/coverage-html
  122. echo "--- Done! Generated HTML report under 'target/coverage-html' for sharedlib."
  123. """
  124. ]
  125. [tasks.get_grcov_report]
  126. description = "Get `grcov` HTML report for test coverage"
  127. run_task = { name = [
  128. "get_rustlib_grcov_report",
  129. "get_sharedlib_grcov_report"
  130. ], parallel = true }
  131. [tasks.get_sharedlib_lcov_report]
  132. description = "Generates `lcov` report for `shared-lib`"
  133. script_runner = "@shell"
  134. script = [
  135. """
  136. echo Getting 'lcov' results for 'shared-lib'
  137. cd ../shared-lib
  138. grcov . \
  139. --binary-path target/debug/deps \
  140. --source-dir . \
  141. --output-type lcov \
  142. --branch \
  143. --ignore-not-existing \
  144. --log-level WARN \
  145. --output-path target/coverage.lcov
  146. echo "--- Done! Generated 'target/coverage.lcov' sharedlib."
  147. """
  148. ]
  149. [tasks.get_rustlib_lcov_report]
  150. description = "Generates `lcov` report for `rust-lib`"
  151. script_runner = "@shell"
  152. script = [
  153. """
  154. echo Getting 'lcov' results for 'rust-lib'
  155. cd rust-lib/
  156. grcov . \
  157. --binary-path target/debug/deps \
  158. --source-dir . \
  159. --output-type lcov \
  160. --branch \
  161. --ignore-not-existing \
  162. --log-level WARN \
  163. --output-path target/coverage.lcov
  164. echo "--- Done! Generated 'target/coverage.lcov' for rustlib."
  165. """
  166. ]
  167. [tasks.get_lcov_report]
  168. description = "Get `lcov` reports for test coverage"
  169. run_task = { name = [
  170. "get_sharedlib_lcov_report",
  171. "get_rustlib_lcov_report"
  172. ], parallel = true }
  173. [tasks.get_ci_test_coverage]
  174. description = "Get LCOV coverage reports for CI"
  175. run_task = { name = [
  176. "check_grcov",
  177. "run_rustlib_coverage_tests",
  178. "run_sharedlib_coverage_tests",
  179. "get_lcov_report",
  180. "clean_profraw_files"
  181. ]}
  182. [tasks.get_test_coverage]
  183. description = "Get human readable test coverage reports"
  184. run_task = { name = [
  185. "check_grcov",
  186. "run_rustlib_coverage_tests",
  187. "run_sharedlib_coverage_tests",
  188. "get_grcov_report",
  189. "clean_profraw_files"
  190. ]}