tests.toml 5.2 KB

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