tests.toml 8.5 KB

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