tests.toml 4.8 KB

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