tests.toml 5.6 KB

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