tests.toml 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. # If you want to test a single file with single case, you can try this command:
  2. # RUST_LOG="debug" flutter test -j, --concurrency=1 'path to the file' --name 'test case name'
  3. [tasks.flutter_test]
  4. description = "Run flutter test with single case in single file. Input: cargo make flutter_test 'path to the file' --name 'test case name'"
  5. script = '''
  6. cd appflowy_flutter
  7. RUST_LOG="debug" flutter test -j, --concurrency=1 "${@}"
  8. '''
  9. script_runner = "@shell"
  10. [tasks.dart_unit_test]
  11. script = '''
  12. cargo make --profile test-macos-$(uname -m) run_dart_unit_test
  13. '''
  14. script_runner = "@shell"
  15. [tasks.dart_unit_test.windows]
  16. script = '''
  17. cargo make --profile test-windows run_dart_unit_test
  18. '''
  19. script_runner = "@shell"
  20. [tasks.dart_unit_test.linux]
  21. script = '''
  22. cargo make --profile test-linux run_dart_unit_test
  23. '''
  24. script_runner = "@shell"
  25. [tasks.run_dart_unit_test]
  26. env = { RUST_LOG = "info" }
  27. dependencies = ["inner_build_test_backend"]
  28. description = "Run flutter unit tests"
  29. script = '''
  30. cd appflowy_flutter
  31. flutter test --dart-define=RUST_LOG=${RUST_LOG} -j, --concurrency=1 --coverage --verbose
  32. '''
  33. [tasks.rust_unit_test]
  34. run_task = { name = ["rust_lib_unit_test", "shared_lib_unit_test"] }
  35. [tasks.rust_lib_unit_test]
  36. env = { RUST_LOG = "info" }
  37. description = "Run rust-lib unit tests"
  38. script = '''
  39. cd rust-lib
  40. RUST_LOG=info RUST_BACKTRACE=1 cargo test --no-default-features --features="rev-sqlite"
  41. '''
  42. [tasks.shared_lib_unit_test]
  43. env = { RUST_LOG = "info" }
  44. description = "Run shared-lib unit test"
  45. script = '''
  46. cd ../shared-lib
  47. cargo test --no-default-features
  48. '''
  49. [tasks.check_grcov]
  50. description = "Check if `grcov` is installled"
  51. script_runner = "@shell"
  52. script = '''
  53. export PATH=$PATH:"$HOME/.cargo/bin/"
  54. if command -v grcov > /dev/null; then
  55. echo "Found 'grcov' executable."
  56. else
  57. echo "[!] Could not find 'grcov' executable."
  58. echo "[!] Please install 'grcov' by running 'cargo install grcov'."
  59. echo "[!] You may also need to install 'llvm-tools-preview' using 'rustup component add llvm-tools-preview'."
  60. echo "[!] If installed, check if 'grcov' is in PATH."
  61. echo "[!] Exiting..."
  62. exit -1
  63. fi
  64. '''
  65. [tasks.clean_profraw_files]
  66. description = "Cleans profraw files that are created by `cargo test`"
  67. script_runner = "@duckscript"
  68. script = ["""
  69. rust_lib_profs = glob_array ./rust-lib/**/*.profraw
  70. for prof in ${rust_lib_profs}
  71. full_path = canonicalize ${prof}
  72. rm ${full_path}
  73. end
  74. shared_lib_profs = glob_array ../shared-lib/**/*.profraw
  75. for prof in ${shared_lib_profs}
  76. full_path = canonicalize ${prof}
  77. rm ${full_path}
  78. end
  79. """]
  80. [tasks.run_rustlib_coverage_tests]
  81. description = "Run tests with coverage instrumentation"
  82. script_runner = "@shell"
  83. script = ["""
  84. echo --- Running coverage tests ---
  85. cd rust-lib/
  86. CARGO_INCREMENTAL=0 \
  87. RUSTFLAGS='-C instrument-coverage' \
  88. LLVM_PROFILE_FILE='prof-%p-%m.profraw' \
  89. cargo test --no-default-features --features="rev-sqlite"
  90. """]
  91. [tasks.run_sharedlib_coverage_tests]
  92. description = "Run tests with coverage instrumentation"
  93. script_runner = "@shell"
  94. script = ["""
  95. echo --- Running coverage tests ---
  96. cd ../shared-lib
  97. CARGO_INCREMENTAL=0 \
  98. RUSTFLAGS='-C instrument-coverage' \
  99. LLVM_PROFILE_FILE='prof-%p-%m.profraw' \
  100. cargo test --no-default-features
  101. """]
  102. [tasks.get_rustlib_grcov_report]
  103. description = "Get `grcov` HTML report for test coverage for rust-lib"
  104. script_runner = "@shell"
  105. script = [
  106. """
  107. echo --- Getting 'grcov' results for 'rust-lib' ---
  108. cd rust-lib/
  109. grcov . \
  110. --binary-path target/debug/deps \
  111. --source-dir . \
  112. --output-type html \
  113. --branch \
  114. --ignore-not-existing \
  115. --log-level WARN \
  116. --output-path target/coverage-html
  117. echo "--- Done! Generated HTML report under 'target/coverage-html' for rustlib."
  118. """,
  119. ]
  120. [tasks.get_sharedlib_grcov_report]
  121. description = "Get `grcov` HTML report for test coverage shared-lib"
  122. script_runner = "@shell"
  123. script = [
  124. """
  125. echo --- Getting 'grcov' results 'shared-lib' ---
  126. cd ../shared-lib
  127. grcov . \
  128. --binary-path target/debug/deps \
  129. --source-dir . \
  130. --output-type html \
  131. --branch \
  132. --ignore-not-existing \
  133. --log-level WARN \
  134. --output-path target/coverage-html
  135. echo "--- Done! Generated HTML report under 'target/coverage-html' for sharedlib."
  136. """,
  137. ]
  138. [tasks.get_grcov_report]
  139. description = "Get `grcov` HTML report for test coverage"
  140. run_task = { name = [
  141. "get_rustlib_grcov_report",
  142. "get_sharedlib_grcov_report",
  143. ], parallel = true }
  144. [tasks.get_sharedlib_lcov_report]
  145. description = "Generates `lcov` report for `shared-lib`"
  146. script_runner = "@shell"
  147. script = ["""
  148. echo Getting 'lcov' results for 'shared-lib'
  149. cd ../shared-lib
  150. grcov . \
  151. --binary-path target/debug/deps \
  152. --source-dir . \
  153. --output-type lcov \
  154. --branch \
  155. --ignore-not-existing \
  156. --log-level WARN \
  157. --output-path target/coverage.lcov
  158. echo "--- Done! Generated 'target/coverage.lcov' sharedlib."
  159. """]
  160. [tasks.get_rustlib_lcov_report]
  161. description = "Generates `lcov` report for `rust-lib`"
  162. script_runner = "@shell"
  163. script = ["""
  164. echo Getting 'lcov' results for 'rust-lib'
  165. cd rust-lib/
  166. grcov . \
  167. --binary-path target/debug/deps \
  168. --source-dir . \
  169. --output-type lcov \
  170. --branch \
  171. --ignore-not-existing \
  172. --log-level WARN \
  173. --output-path target/coverage.lcov
  174. echo "--- Done! Generated 'target/coverage.lcov' for rustlib."
  175. """]
  176. [tasks.get_lcov_report]
  177. description = "Get `lcov` reports for test coverage"
  178. run_task = { name = [
  179. "get_sharedlib_lcov_report",
  180. "get_rustlib_lcov_report",
  181. ], parallel = true }
  182. [tasks.rust_unit_test_with_coverage]
  183. description = "Run rust unit test with code coverage"
  184. run_task = { name = [
  185. "check_grcov",
  186. 'appflowy-flutter-deps-tools',
  187. "run_rustlib_coverage_tests",
  188. "run_sharedlib_coverage_tests",
  189. "get_lcov_report",
  190. "clean_profraw_files",
  191. ] }
  192. [tasks.build_test_backend]
  193. script = '''
  194. cargo make --profile test-macos-$(uname -m) inner_build_test_backend
  195. '''
  196. script_runner = "@shell"
  197. [tasks.build_test_backend.windows]
  198. script = '''
  199. cargo make --profile test-windows inner_build_test_backend
  200. '''
  201. script_runner = "@shell"
  202. [tasks.build_test_backend.linux]
  203. script = '''
  204. cargo make --profile test-linux inner_build_test_backend
  205. '''
  206. script_runner = "@shell"
  207. [tasks.inner_build_test_backend]
  208. category = "Build"
  209. dependencies = ["env_check"]
  210. run_task = { name = [
  211. "setup-test-crate-type",
  212. "compile_test_backend",
  213. "copy-to-sandbox-folder",
  214. "restore-test-crate-type",
  215. ] }
  216. [tasks.compile_test_backend]
  217. mac_alias = "compile_test_backend_default"
  218. windows_alias = "compile_test_backend_windows"
  219. linux_alias = "compile_test_backend_default"
  220. [tasks.compile_test_backend_default]
  221. private = true
  222. script = [
  223. """
  224. cd rust-lib/
  225. rustup show
  226. echo RUST_LOG=${RUST_LOG} cargo build --package=dart-ffi --target ${TEST_COMPILE_TARGET} --features "${FLUTTER_DESKTOP_FEATURES}"
  227. RUST_LOG=${RUST_LOG} cargo build --package=dart-ffi --target ${TEST_COMPILE_TARGET} --features "${FLUTTER_DESKTOP_FEATURES}"
  228. cd ../
  229. """,
  230. ]
  231. script_runner = "@shell"
  232. [tasks.compile_test_backend_windows]
  233. private = true
  234. script = [
  235. """
  236. cd rust-lib/
  237. rustup show
  238. echo cargo build --package=dart-ffi --target ${TEST_COMPILE_TARGET} --features "${FLUTTER_DESKTOP_FEATURES}"
  239. RUST_LOG=${RUST_LOG} cargo build --package=dart-ffi --target ${TEST_COMPILE_TARGET} --features "${FLUTTER_DESKTOP_FEATURES}"
  240. cd ../
  241. """,
  242. ]
  243. script_runner = "@shell"
  244. [tasks.copy-to-sandbox-folder]
  245. mac_alias = "copy-to-sandbox-folder-default"
  246. windows_alias = "copy-to-sandbox-folder-windows"
  247. linux_alias = "copy-to-sandbox-folder-default"
  248. [tasks.copy-to-sandbox-folder-windows]
  249. private = true
  250. script = [
  251. """
  252. # Copy the appflowy_backend lib to system temp directory for flutter unit test.
  253. lib = set ${LIB_NAME}.${TEST_LIB_EXT}
  254. dest = set ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/appflowy_flutter/.sandbox/${lib}
  255. rm ${dest}
  256. cp ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/target/${TEST_COMPILE_TARGET}/${TEST_BUILD_FLAG}/${lib} \
  257. ${dest}
  258. """,
  259. ]
  260. script_runner = "@duckscript"
  261. [tasks.copy-to-sandbox-folder-default]
  262. private = true
  263. script = [
  264. """
  265. # Copy the appflowy_backend lib to system temp directory for flutter unit test.
  266. lib = set lib${LIB_NAME}.${TEST_LIB_EXT}
  267. dest = set ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/appflowy_flutter/.sandbox/${lib}
  268. rm ${dest}
  269. cp ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/rust-lib/target/${TEST_COMPILE_TARGET}/${TEST_BUILD_FLAG}/${lib} \
  270. ${dest}
  271. """,
  272. ]
  273. script_runner = "@duckscript"