tests.toml 5.1 KB

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