BUILD.bazel 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. # Copyright 2017 Google Inc.
  2. # All Rights Reserved.
  3. #
  4. #
  5. # Redistribution and use in source and binary forms, with or without
  6. # modification, are permitted provided that the following conditions are
  7. # met:
  8. #
  9. # * Redistributions of source code must retain the above copyright
  10. # notice, this list of conditions and the following disclaimer.
  11. # * Redistributions in binary form must reproduce the above
  12. # copyright notice, this list of conditions and the following disclaimer
  13. # in the documentation and/or other materials provided with the
  14. # distribution.
  15. # * Neither the name of Google Inc. nor the names of its
  16. # contributors may be used to endorse or promote products derived from
  17. # this software without specific prior written permission.
  18. #
  19. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  22. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  23. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  24. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  25. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  26. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  27. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. #
  31. # Bazel BUILD for The Google C++ Testing Framework (Google Test)
  32. load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_test")
  33. load("@rules_python//python:defs.bzl", "py_library", "py_test")
  34. licenses(["notice"])
  35. package(default_visibility = ["//:__subpackages__"])
  36. #on windows exclude gtest-tuple.h
  37. cc_test(
  38. name = "gtest_all_test",
  39. size = "small",
  40. srcs = glob(
  41. include = [
  42. "gtest-*.cc",
  43. "googletest-*.cc",
  44. "*.h",
  45. "googletest/include/gtest/**/*.h",
  46. ],
  47. exclude = [
  48. "gtest-unittest-api_test.cc",
  49. "googletest/src/gtest-all.cc",
  50. "gtest_all_test.cc",
  51. "gtest-death-test_ex_test.cc",
  52. "gtest-listener_test.cc",
  53. "gtest-unittest-api_test.cc",
  54. "googletest-param-test-test.cc",
  55. "googletest-param-test2-test.cc",
  56. "googletest-catch-exceptions-test_.cc",
  57. "googletest-color-test_.cc",
  58. "googletest-env-var-test_.cc",
  59. "googletest-failfast-unittest_.cc",
  60. "googletest-filter-unittest_.cc",
  61. "googletest-global-environment-unittest_.cc",
  62. "googletest-break-on-failure-unittest_.cc",
  63. "googletest-listener-test.cc",
  64. "googletest-output-test_.cc",
  65. "googletest-list-tests-unittest_.cc",
  66. "googletest-shuffle-test_.cc",
  67. "googletest-setuptestsuite-test_.cc",
  68. "googletest-uninitialized-test_.cc",
  69. "googletest-death-test_ex_test.cc",
  70. "googletest-param-test-test",
  71. "googletest-throw-on-failure-test_.cc",
  72. "googletest-param-test-invalid-name1-test_.cc",
  73. "googletest-param-test-invalid-name2-test_.cc",
  74. ],
  75. ) + select({
  76. "//:windows": [],
  77. "//conditions:default": [],
  78. }),
  79. copts = select({
  80. "//:windows": ["-DGTEST_USE_OWN_TR1_TUPLE=0"],
  81. "//conditions:default": ["-DGTEST_USE_OWN_TR1_TUPLE=1"],
  82. }) + select({
  83. # Ensure MSVC treats source files as UTF-8 encoded.
  84. "//:msvc_compiler": ["-utf-8"],
  85. "//conditions:default": [],
  86. }),
  87. includes = [
  88. "googletest",
  89. "googletest/include",
  90. "googletest/include/internal",
  91. "googletest/test",
  92. ],
  93. linkopts = select({
  94. "//:windows": [],
  95. "//conditions:default": ["-pthread"],
  96. }),
  97. deps = ["//:gtest_main"],
  98. )
  99. # Tests death tests.
  100. cc_test(
  101. name = "googletest-death-test-test",
  102. size = "medium",
  103. srcs = ["googletest-death-test-test.cc"],
  104. deps = ["//:gtest_main"],
  105. )
  106. cc_test(
  107. name = "gtest_test_macro_stack_footprint_test",
  108. size = "small",
  109. srcs = ["gtest_test_macro_stack_footprint_test.cc"],
  110. deps = ["//:gtest"],
  111. )
  112. #These googletest tests have their own main()
  113. cc_test(
  114. name = "googletest-listener-test",
  115. size = "small",
  116. srcs = ["googletest-listener-test.cc"],
  117. deps = ["//:gtest_main"],
  118. )
  119. cc_test(
  120. name = "gtest-unittest-api_test",
  121. size = "small",
  122. srcs = [
  123. "gtest-unittest-api_test.cc",
  124. ],
  125. deps = [
  126. "//:gtest",
  127. ],
  128. )
  129. cc_test(
  130. name = "googletest-param-test-test",
  131. size = "small",
  132. srcs = [
  133. "googletest-param-test-test.cc",
  134. "googletest-param-test-test.h",
  135. "googletest-param-test2-test.cc",
  136. ],
  137. deps = ["//:gtest"],
  138. )
  139. cc_test(
  140. name = "gtest_unittest",
  141. size = "small",
  142. srcs = ["gtest_unittest.cc"],
  143. shard_count = 2,
  144. deps = ["//:gtest_main"],
  145. )
  146. # Py tests
  147. py_library(
  148. name = "gtest_test_utils",
  149. testonly = 1,
  150. srcs = ["gtest_test_utils.py"],
  151. imports = ["."],
  152. )
  153. cc_binary(
  154. name = "gtest_help_test_",
  155. testonly = 1,
  156. srcs = ["gtest_help_test_.cc"],
  157. deps = ["//:gtest_main"],
  158. )
  159. py_test(
  160. name = "gtest_help_test",
  161. size = "small",
  162. srcs = ["gtest_help_test.py"],
  163. data = [":gtest_help_test_"],
  164. deps = [":gtest_test_utils"],
  165. )
  166. cc_binary(
  167. name = "googletest-output-test_",
  168. testonly = 1,
  169. srcs = ["googletest-output-test_.cc"],
  170. deps = ["//:gtest"],
  171. )
  172. py_test(
  173. name = "googletest-output-test",
  174. size = "small",
  175. srcs = ["googletest-output-test.py"],
  176. args = select({
  177. "//:has_absl": [],
  178. "//conditions:default": ["--no_stacktrace_support"],
  179. }),
  180. data = [
  181. "googletest-output-test-golden-lin.txt",
  182. ":googletest-output-test_",
  183. ],
  184. deps = [":gtest_test_utils"],
  185. )
  186. cc_binary(
  187. name = "googletest-color-test_",
  188. testonly = 1,
  189. srcs = ["googletest-color-test_.cc"],
  190. deps = ["//:gtest"],
  191. )
  192. py_test(
  193. name = "googletest-color-test",
  194. size = "small",
  195. srcs = ["googletest-color-test.py"],
  196. data = [":googletest-color-test_"],
  197. deps = [":gtest_test_utils"],
  198. )
  199. cc_binary(
  200. name = "googletest-env-var-test_",
  201. testonly = 1,
  202. srcs = ["googletest-env-var-test_.cc"],
  203. deps = ["//:gtest"],
  204. )
  205. py_test(
  206. name = "googletest-env-var-test",
  207. size = "medium",
  208. srcs = ["googletest-env-var-test.py"],
  209. data = [":googletest-env-var-test_"],
  210. deps = [":gtest_test_utils"],
  211. )
  212. cc_binary(
  213. name = "googletest-failfast-unittest_",
  214. testonly = 1,
  215. srcs = ["googletest-failfast-unittest_.cc"],
  216. deps = ["//:gtest"],
  217. )
  218. py_test(
  219. name = "googletest-failfast-unittest",
  220. size = "medium",
  221. srcs = ["googletest-failfast-unittest.py"],
  222. data = [":googletest-failfast-unittest_"],
  223. deps = [":gtest_test_utils"],
  224. )
  225. cc_binary(
  226. name = "googletest-filter-unittest_",
  227. testonly = 1,
  228. srcs = ["googletest-filter-unittest_.cc"],
  229. deps = ["//:gtest"],
  230. )
  231. py_test(
  232. name = "googletest-filter-unittest",
  233. size = "medium",
  234. srcs = ["googletest-filter-unittest.py"],
  235. data = [":googletest-filter-unittest_"],
  236. deps = [":gtest_test_utils"],
  237. )
  238. cc_binary(
  239. name = "googletest-global-environment-unittest_",
  240. testonly = 1,
  241. srcs = ["googletest-global-environment-unittest_.cc"],
  242. deps = ["//:gtest"],
  243. )
  244. py_test(
  245. name = "googletest-global-environment-unittest",
  246. size = "medium",
  247. srcs = ["googletest-global-environment-unittest.py"],
  248. data = [":googletest-global-environment-unittest_"],
  249. deps = [":gtest_test_utils"],
  250. )
  251. cc_binary(
  252. name = "googletest-break-on-failure-unittest_",
  253. testonly = 1,
  254. srcs = ["googletest-break-on-failure-unittest_.cc"],
  255. deps = ["//:gtest"],
  256. )
  257. py_test(
  258. name = "googletest-break-on-failure-unittest",
  259. size = "small",
  260. srcs = ["googletest-break-on-failure-unittest.py"],
  261. data = [":googletest-break-on-failure-unittest_"],
  262. deps = [":gtest_test_utils"],
  263. )
  264. cc_test(
  265. name = "gtest_assert_by_exception_test",
  266. size = "small",
  267. srcs = ["gtest_assert_by_exception_test.cc"],
  268. deps = ["//:gtest"],
  269. )
  270. cc_binary(
  271. name = "googletest-throw-on-failure-test_",
  272. testonly = 1,
  273. srcs = ["googletest-throw-on-failure-test_.cc"],
  274. deps = ["//:gtest"],
  275. )
  276. py_test(
  277. name = "googletest-throw-on-failure-test",
  278. size = "small",
  279. srcs = ["googletest-throw-on-failure-test.py"],
  280. data = [":googletest-throw-on-failure-test_"],
  281. deps = [":gtest_test_utils"],
  282. )
  283. cc_binary(
  284. name = "googletest-list-tests-unittest_",
  285. testonly = 1,
  286. srcs = ["googletest-list-tests-unittest_.cc"],
  287. deps = ["//:gtest"],
  288. )
  289. cc_test(
  290. name = "gtest_skip_test",
  291. size = "small",
  292. srcs = ["gtest_skip_test.cc"],
  293. deps = ["//:gtest_main"],
  294. )
  295. cc_test(
  296. name = "gtest_skip_in_environment_setup_test",
  297. size = "small",
  298. srcs = ["gtest_skip_in_environment_setup_test.cc"],
  299. deps = ["//:gtest_main"],
  300. )
  301. py_test(
  302. name = "gtest_skip_check_output_test",
  303. size = "small",
  304. srcs = ["gtest_skip_check_output_test.py"],
  305. data = [":gtest_skip_test"],
  306. deps = [":gtest_test_utils"],
  307. )
  308. py_test(
  309. name = "gtest_skip_environment_check_output_test",
  310. size = "small",
  311. srcs = ["gtest_skip_environment_check_output_test.py"],
  312. data = [
  313. ":gtest_skip_in_environment_setup_test",
  314. ],
  315. deps = [":gtest_test_utils"],
  316. )
  317. py_test(
  318. name = "googletest-list-tests-unittest",
  319. size = "small",
  320. srcs = ["googletest-list-tests-unittest.py"],
  321. data = [":googletest-list-tests-unittest_"],
  322. deps = [":gtest_test_utils"],
  323. )
  324. cc_binary(
  325. name = "googletest-shuffle-test_",
  326. srcs = ["googletest-shuffle-test_.cc"],
  327. deps = ["//:gtest"],
  328. )
  329. py_test(
  330. name = "googletest-shuffle-test",
  331. size = "small",
  332. srcs = ["googletest-shuffle-test.py"],
  333. data = [":googletest-shuffle-test_"],
  334. deps = [":gtest_test_utils"],
  335. )
  336. cc_binary(
  337. name = "googletest-catch-exceptions-no-ex-test_",
  338. testonly = 1,
  339. srcs = ["googletest-catch-exceptions-test_.cc"],
  340. deps = ["//:gtest_main"],
  341. )
  342. cc_binary(
  343. name = "googletest-catch-exceptions-ex-test_",
  344. testonly = 1,
  345. srcs = ["googletest-catch-exceptions-test_.cc"],
  346. copts = ["-fexceptions"],
  347. deps = ["//:gtest_main"],
  348. )
  349. py_test(
  350. name = "googletest-catch-exceptions-test",
  351. size = "small",
  352. srcs = ["googletest-catch-exceptions-test.py"],
  353. data = [
  354. ":googletest-catch-exceptions-ex-test_",
  355. ":googletest-catch-exceptions-no-ex-test_",
  356. ],
  357. deps = [":gtest_test_utils"],
  358. )
  359. cc_binary(
  360. name = "gtest_xml_output_unittest_",
  361. testonly = 1,
  362. srcs = ["gtest_xml_output_unittest_.cc"],
  363. deps = ["//:gtest"],
  364. )
  365. cc_test(
  366. name = "gtest_no_test_unittest",
  367. size = "small",
  368. srcs = ["gtest_no_test_unittest.cc"],
  369. deps = ["//:gtest"],
  370. )
  371. py_test(
  372. name = "gtest_xml_output_unittest",
  373. size = "small",
  374. srcs = [
  375. "gtest_xml_output_unittest.py",
  376. "gtest_xml_test_utils.py",
  377. ],
  378. args = select({
  379. "//:has_absl": [],
  380. "//conditions:default": ["--no_stacktrace_support"],
  381. }),
  382. data = [
  383. # We invoke gtest_no_test_unittest to verify the XML output
  384. # when the test program contains no test definition.
  385. ":gtest_no_test_unittest",
  386. ":gtest_xml_output_unittest_",
  387. ],
  388. deps = [":gtest_test_utils"],
  389. )
  390. cc_binary(
  391. name = "gtest_xml_outfile1_test_",
  392. testonly = 1,
  393. srcs = ["gtest_xml_outfile1_test_.cc"],
  394. deps = ["//:gtest_main"],
  395. )
  396. cc_binary(
  397. name = "gtest_xml_outfile2_test_",
  398. testonly = 1,
  399. srcs = ["gtest_xml_outfile2_test_.cc"],
  400. deps = ["//:gtest_main"],
  401. )
  402. py_test(
  403. name = "gtest_xml_outfiles_test",
  404. size = "small",
  405. srcs = [
  406. "gtest_xml_outfiles_test.py",
  407. "gtest_xml_test_utils.py",
  408. ],
  409. data = [
  410. ":gtest_xml_outfile1_test_",
  411. ":gtest_xml_outfile2_test_",
  412. ],
  413. deps = [":gtest_test_utils"],
  414. )
  415. cc_binary(
  416. name = "googletest-setuptestsuite-test_",
  417. testonly = 1,
  418. srcs = ["googletest-setuptestsuite-test_.cc"],
  419. deps = ["//:gtest_main"],
  420. )
  421. py_test(
  422. name = "googletest-setuptestsuite-test",
  423. size = "medium",
  424. srcs = ["googletest-setuptestsuite-test.py"],
  425. data = [":googletest-setuptestsuite-test_"],
  426. deps = [":gtest_test_utils"],
  427. )
  428. cc_binary(
  429. name = "googletest-uninitialized-test_",
  430. testonly = 1,
  431. srcs = ["googletest-uninitialized-test_.cc"],
  432. deps = ["//:gtest"],
  433. )
  434. py_test(
  435. name = "googletest-uninitialized-test",
  436. size = "medium",
  437. srcs = ["googletest-uninitialized-test.py"],
  438. data = ["googletest-uninitialized-test_"],
  439. deps = [":gtest_test_utils"],
  440. )
  441. cc_binary(
  442. name = "gtest_testbridge_test_",
  443. testonly = 1,
  444. srcs = ["gtest_testbridge_test_.cc"],
  445. deps = ["//:gtest_main"],
  446. )
  447. # Tests that filtering via testbridge works
  448. py_test(
  449. name = "gtest_testbridge_test",
  450. size = "small",
  451. srcs = ["gtest_testbridge_test.py"],
  452. data = [":gtest_testbridge_test_"],
  453. deps = [":gtest_test_utils"],
  454. )
  455. py_test(
  456. name = "googletest-json-outfiles-test",
  457. size = "small",
  458. srcs = [
  459. "googletest-json-outfiles-test.py",
  460. "gtest_json_test_utils.py",
  461. ],
  462. data = [
  463. ":gtest_xml_outfile1_test_",
  464. ":gtest_xml_outfile2_test_",
  465. ],
  466. deps = [":gtest_test_utils"],
  467. )
  468. py_test(
  469. name = "googletest-json-output-unittest",
  470. size = "medium",
  471. srcs = [
  472. "googletest-json-output-unittest.py",
  473. "gtest_json_test_utils.py",
  474. ],
  475. args = select({
  476. "//:has_absl": [],
  477. "//conditions:default": ["--no_stacktrace_support"],
  478. }),
  479. data = [
  480. # We invoke gtest_no_test_unittest to verify the JSON output
  481. # when the test program contains no test definition.
  482. ":gtest_no_test_unittest",
  483. ":gtest_xml_output_unittest_",
  484. ],
  485. deps = [":gtest_test_utils"],
  486. )
  487. # Verifies interaction of death tests and exceptions.
  488. cc_test(
  489. name = "googletest-death-test_ex_catch_test",
  490. size = "medium",
  491. srcs = ["googletest-death-test_ex_test.cc"],
  492. copts = ["-fexceptions"],
  493. defines = ["GTEST_ENABLE_CATCH_EXCEPTIONS_=1"],
  494. deps = ["//:gtest"],
  495. )
  496. cc_binary(
  497. name = "googletest-param-test-invalid-name1-test_",
  498. testonly = 1,
  499. srcs = ["googletest-param-test-invalid-name1-test_.cc"],
  500. deps = ["//:gtest"],
  501. )
  502. cc_binary(
  503. name = "googletest-param-test-invalid-name2-test_",
  504. testonly = 1,
  505. srcs = ["googletest-param-test-invalid-name2-test_.cc"],
  506. deps = ["//:gtest"],
  507. )
  508. py_test(
  509. name = "googletest-param-test-invalid-name1-test",
  510. size = "small",
  511. srcs = ["googletest-param-test-invalid-name1-test.py"],
  512. data = [":googletest-param-test-invalid-name1-test_"],
  513. tags = [
  514. "no_test_msvc2015",
  515. "no_test_msvc2017",
  516. ],
  517. deps = [":gtest_test_utils"],
  518. )
  519. py_test(
  520. name = "googletest-param-test-invalid-name2-test",
  521. size = "small",
  522. srcs = ["googletest-param-test-invalid-name2-test.py"],
  523. data = [":googletest-param-test-invalid-name2-test_"],
  524. tags = [
  525. "no_test_msvc2015",
  526. "no_test_msvc2017",
  527. ],
  528. deps = [":gtest_test_utils"],
  529. )