PageRenderTime 42ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/integration/cmd_list_test.sh

https://code.google.com/
Shell | 535 lines | 426 code | 82 blank | 27 comment | 1 complexity | 280831fd1e19bdf750e8da49be20ef1e MD5 | raw file
Possible License(s): BSD-3-Clause
  1. # Copyright 2011 Google Inc.
  2. # All rights reserved.
  3. #
  4. # Redistribution and use in source and binary forms, with or without
  5. # modification, are permitted provided that the following conditions are
  6. # met:
  7. #
  8. # * Redistributions of source code must retain the above copyright
  9. # notice, this list of conditions and the following disclaimer.
  10. # * Redistributions in binary form must reproduce the above copyright
  11. # notice, this list of conditions and the following disclaimer in the
  12. # documentation and/or other materials provided with the distribution.
  13. # * Neither the name of Google Inc. nor the names of its contributors
  14. # may be used to endorse or promote products derived from this software
  15. # without specific prior written permission.
  16. #
  17. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  18. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  19. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  20. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  21. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  22. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  23. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  24. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  25. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  27. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. utils_test_case no_args
  29. no_args_body() {
  30. cat >Kyuafile <<EOF
  31. syntax("kyuafile", 1)
  32. test_suite("integration")
  33. atf_test_program{name="metadata"}
  34. atf_test_program{name="simple_all_pass"}
  35. include("subdir/Kyuafile")
  36. EOF
  37. utils_cp_helper metadata .
  38. utils_cp_helper simple_all_pass .
  39. mkdir subdir
  40. cat >subdir/Kyuafile <<EOF
  41. syntax("kyuafile", 1)
  42. test_suite("integration2")
  43. atf_test_program{name="simple_some_fail"}
  44. EOF
  45. utils_cp_helper simple_some_fail subdir
  46. cat >expout <<EOF
  47. metadata:no_properties
  48. metadata:one_property
  49. metadata:many_properties
  50. metadata:with_cleanup
  51. simple_all_pass:pass
  52. simple_all_pass:skip
  53. subdir/simple_some_fail:fail
  54. subdir/simple_some_fail:pass
  55. EOF
  56. atf_check -s exit:0 -o file:expout -e empty kyua list
  57. }
  58. utils_test_case one_arg__subdir
  59. one_arg__subdir_body() {
  60. cat >Kyuafile <<EOF
  61. syntax("kyuafile", 1)
  62. test_suite("top-level")
  63. include("subdir/Kyuafile")
  64. EOF
  65. mkdir subdir
  66. cat >subdir/Kyuafile <<EOF
  67. syntax("kyuafile", 1)
  68. test_suite("in-subdir")
  69. atf_test_program{name="simple_all_pass"}
  70. EOF
  71. utils_cp_helper simple_all_pass subdir
  72. cat >expout <<EOF
  73. subdir/simple_all_pass:pass
  74. subdir/simple_all_pass:skip
  75. EOF
  76. atf_check -s exit:0 -o file:expout -e empty kyua list subdir
  77. }
  78. utils_test_case one_arg__test_case
  79. one_arg__test_case_body() {
  80. cat >Kyuafile <<EOF
  81. syntax("kyuafile", 1)
  82. test_suite("top-level")
  83. atf_test_program{name="first"}
  84. atf_test_program{name="second"}
  85. EOF
  86. utils_cp_helper simple_all_pass first
  87. utils_cp_helper simple_all_pass second
  88. cat >expout <<EOF
  89. first:skip
  90. EOF
  91. atf_check -s exit:0 -o file:expout -e empty kyua list first:skip
  92. }
  93. utils_test_case one_arg__test_program
  94. one_arg__test_program_body() {
  95. cat >Kyuafile <<EOF
  96. syntax("kyuafile", 1)
  97. test_suite("top-level")
  98. atf_test_program{name="first"}
  99. atf_test_program{name="second"}
  100. EOF
  101. utils_cp_helper simple_all_pass first
  102. utils_cp_helper simple_some_fail second
  103. cat >expout <<EOF
  104. second:fail
  105. second:pass
  106. EOF
  107. atf_check -s exit:0 -o file:expout -e empty kyua list second
  108. }
  109. utils_test_case one_arg__invalid
  110. one_arg__invalid_body() {
  111. cat >experr <<EOF
  112. kyua: E: Test case component in 'foo:' is empty.
  113. EOF
  114. atf_check -s exit:1 -o empty -e file:experr kyua list foo:
  115. cat >experr <<EOF
  116. kyua: E: Program name '/a/b' must be relative to the test suite, not absolute.
  117. EOF
  118. atf_check -s exit:1 -o empty -e file:experr kyua list /a/b
  119. }
  120. utils_test_case many_args__ok
  121. many_args__ok_body() {
  122. cat >Kyuafile <<EOF
  123. syntax("kyuafile", 1)
  124. test_suite("top-level")
  125. include("subdir/Kyuafile")
  126. atf_test_program{name="first"}
  127. EOF
  128. utils_cp_helper simple_all_pass first
  129. mkdir subdir
  130. cat >subdir/Kyuafile <<EOF
  131. syntax("kyuafile", 1)
  132. test_suite("in-subdir")
  133. atf_test_program{name="second"}
  134. EOF
  135. utils_cp_helper simple_some_fail subdir/second
  136. cat >expout <<EOF
  137. subdir/second:fail (in-subdir)
  138. subdir/second:pass (in-subdir)
  139. first:pass (top-level)
  140. EOF
  141. atf_check -s exit:0 -o file:expout -e empty kyua list -v subdir first:pass
  142. }
  143. utils_test_case many_args__invalid
  144. many_args__invalid_body() {
  145. cat >experr <<EOF
  146. kyua: E: Program name component in ':badbad' is empty.
  147. EOF
  148. atf_check -s exit:1 -o empty -e file:experr kyua list this-is-ok :badbad
  149. cat >experr <<EOF
  150. kyua: E: Program name '/foo' must be relative to the test suite, not absolute.
  151. EOF
  152. atf_check -s exit:1 -o empty -e file:experr kyua list this-is-ok /foo
  153. }
  154. utils_test_case many_args__no_match__all
  155. many_args__no_match__all_body() {
  156. cat >Kyuafile <<EOF
  157. syntax("kyuafile", 1)
  158. test_suite("top-level")
  159. atf_test_program{name="first"}
  160. atf_test_program{name="second"}
  161. EOF
  162. utils_cp_helper simple_all_pass first
  163. utils_cp_helper simple_all_pass second
  164. cat >experr <<EOF
  165. kyua: W: No test cases matched by the filter 'first1'.
  166. EOF
  167. atf_check -s exit:1 -o empty -e file:experr kyua list first1
  168. }
  169. utils_test_case many_args__no_match__some
  170. many_args__no_match__some_body() {
  171. cat >Kyuafile <<EOF
  172. syntax("kyuafile", 1)
  173. test_suite("top-level")
  174. atf_test_program{name="first"}
  175. atf_test_program{name="second"}
  176. atf_test_program{name="third"}
  177. EOF
  178. utils_cp_helper simple_all_pass first
  179. utils_cp_helper simple_all_pass second
  180. utils_cp_helper simple_some_fail third
  181. cat >expout <<EOF
  182. first:pass
  183. first:skip
  184. third:fail
  185. third:pass
  186. EOF
  187. cat >experr <<EOF
  188. kyua: W: No test cases matched by the filter 'fifth'.
  189. kyua: W: No test cases matched by the filter 'fourth'.
  190. EOF
  191. atf_check -s exit:1 -o file:expout -e file:experr kyua list first fourth \
  192. third fifth
  193. }
  194. utils_test_case args_are_relative
  195. args_are_relative_body() {
  196. mkdir root
  197. cat >root/Kyuafile <<EOF
  198. syntax("kyuafile", 1)
  199. test_suite("integration-1")
  200. atf_test_program{name="first"}
  201. atf_test_program{name="second"}
  202. include("subdir/Kyuafile")
  203. EOF
  204. utils_cp_helper simple_all_pass root/first
  205. utils_cp_helper simple_some_fail root/second
  206. mkdir root/subdir
  207. cat >root/subdir/Kyuafile <<EOF
  208. syntax("kyuafile", 1)
  209. test_suite("integration-2")
  210. atf_test_program{name="third"}
  211. atf_test_program{name="fourth"}
  212. EOF
  213. utils_cp_helper simple_all_pass root/subdir/third
  214. utils_cp_helper simple_some_fail root/subdir/fourth
  215. cat >expout <<EOF
  216. first:pass (integration-1)
  217. first:skip (integration-1)
  218. subdir/fourth:fail (integration-2)
  219. EOF
  220. atf_check -s exit:0 -o file:expout -e empty kyua list \
  221. -v -k "$(pwd)/root/Kyuafile" first subdir/fourth:fail
  222. }
  223. utils_test_case only_load_used_test_programs
  224. only_load_used_test_programs_body() {
  225. cat >Kyuafile <<EOF
  226. syntax("kyuafile", 1)
  227. test_suite("integration")
  228. atf_test_program{name="first"}
  229. atf_test_program{name="second"}
  230. EOF
  231. utils_cp_helper simple_all_pass first
  232. utils_cp_helper bad_test_program second
  233. cat >expout <<EOF
  234. first:pass
  235. first:skip
  236. EOF
  237. CREATE_COOKIE="$(pwd)/cookie"; export CREATE_COOKIE
  238. atf_check -s exit:0 -o file:expout -e empty kyua list first
  239. if test -f "${CREATE_COOKIE}"; then
  240. atf_fail "An unmatched test case has been executed, which harms" \
  241. "performance"
  242. fi
  243. }
  244. utils_test_case kyuafile_flag__no_args
  245. kyuafile_flag__no_args_body() {
  246. cat >Kyuafile <<EOF
  247. This file is bogus but it is not loaded.
  248. EOF
  249. cat >myfile <<EOF
  250. syntax("kyuafile", 1)
  251. test_suite("integration")
  252. atf_test_program{name="sometest"}
  253. EOF
  254. utils_cp_helper simple_all_pass sometest
  255. cat >expout <<EOF
  256. sometest:pass
  257. sometest:skip
  258. EOF
  259. atf_check -s exit:0 -o file:expout -e empty kyua list -k myfile
  260. atf_check -s exit:0 -o file:expout -e empty kyua list --kyuafile=myfile
  261. }
  262. utils_test_case kyuafile_flag__some_args
  263. kyuafile_flag__some_args_body() {
  264. cat >Kyuafile <<EOF
  265. This file is bogus but it is not loaded.
  266. EOF
  267. cat >myfile <<EOF
  268. syntax("kyuafile", 1)
  269. test_suite("hello-world")
  270. atf_test_program{name="sometest"}
  271. EOF
  272. utils_cp_helper simple_all_pass sometest
  273. cat >expout <<EOF
  274. sometest:pass (hello-world)
  275. sometest:skip (hello-world)
  276. EOF
  277. atf_check -s exit:0 -o file:expout -e empty kyua list -v -k myfile sometest
  278. atf_check -s exit:0 -o file:expout -e empty kyua list -v --kyuafile=myfile \
  279. sometest
  280. }
  281. utils_test_case verbose_flag
  282. verbose_flag_body() {
  283. cat >Kyuafile <<EOF
  284. syntax("kyuafile", 1)
  285. test_suite("integration-suite-1")
  286. atf_test_program{name="simple_all_pass"}
  287. plain_test_program{name="i_am_plain", timeout=654}
  288. include("subdir/Kyuafile")
  289. EOF
  290. utils_cp_helper simple_all_pass .
  291. touch i_am_plain
  292. mkdir subdir
  293. cat >subdir/Kyuafile <<EOF
  294. syntax("kyuafile", 1)
  295. test_suite("integration-suite-2")
  296. atf_test_program{name="metadata"}
  297. EOF
  298. utils_cp_helper metadata subdir
  299. cat >expout <<EOF
  300. simple_all_pass:pass (integration-suite-1)
  301. simple_all_pass:skip (integration-suite-1)
  302. i_am_plain:main (integration-suite-1)
  303. timeout = 654
  304. subdir/metadata:no_properties (integration-suite-2)
  305. subdir/metadata:one_property (integration-suite-2)
  306. descr = Does nothing but has one metadata property
  307. subdir/metadata:many_properties (integration-suite-2)
  308. X-no-meaning = I am a custom variable
  309. descr = A description with some padding
  310. require.arch = some-architecture
  311. require.config = var1 var2 var3
  312. require.files = /my/file1 /some/other/file
  313. require.machine = some-platform
  314. require.progs = /nonexistent/bin3 bin1 bin2
  315. require.user = root
  316. subdir/metadata:with_cleanup (integration-suite-2)
  317. has.cleanup = true
  318. timeout = 250
  319. EOF
  320. atf_check -s exit:0 -o file:expout -e empty kyua list -v
  321. atf_check -s exit:0 -o file:expout -e empty kyua list --verbose
  322. }
  323. utils_test_case no_test_program_match
  324. no_test_program_match_body() {
  325. cat >Kyuafile <<EOF
  326. syntax("kyuafile", 1)
  327. test_suite("integration")
  328. atf_test_program{name="first"}
  329. EOF
  330. utils_cp_helper simple_all_pass first
  331. utils_cp_helper simple_all_pass second
  332. cat >experr <<EOF
  333. kyua: W: No test cases matched by the filter 'second'.
  334. EOF
  335. atf_check -s exit:1 -o empty -e file:experr kyua list second
  336. }
  337. utils_test_case no_test_case_match
  338. no_test_case_match_body() {
  339. cat >Kyuafile <<EOF
  340. syntax("kyuafile", 1)
  341. test_suite("integration")
  342. atf_test_program{name="first"}
  343. EOF
  344. utils_cp_helper simple_all_pass first
  345. cat >experr <<EOF
  346. kyua: W: No test cases matched by the filter 'first:foobar'.
  347. EOF
  348. atf_check -s exit:1 -o empty -e file:experr kyua list first:foobar
  349. }
  350. utils_test_case missing_kyuafile__no_args
  351. missing_kyuafile__no_args_body() {
  352. cat >experr <<EOF
  353. kyua: E: Load of 'Kyuafile' failed: File 'Kyuafile' not found.
  354. EOF
  355. atf_check -s exit:1 -o empty -e file:experr kyua list
  356. }
  357. utils_test_case missing_kyuafile__test_program
  358. missing_kyuafile__test_program_body() {
  359. mkdir subdir
  360. cat >subdir/Kyuafile <<EOF
  361. syntax("kyuafile", 1)
  362. test_suite("integration")
  363. atf_test_program{name="unused"}
  364. EOF
  365. utils_cp_helper simple_all_pass subdir/unused
  366. cat >experr <<EOF
  367. kyua: E: Load of 'Kyuafile' failed: File 'Kyuafile' not found.
  368. EOF
  369. atf_check -s exit:1 -o empty -e file:experr kyua list subdir/unused
  370. }
  371. utils_test_case missing_kyuafile__subdir
  372. missing_kyuafile__subdir_body() {
  373. mkdir subdir
  374. cat >subdir/Kyuafile <<EOF
  375. syntax("kyuafile", 1)
  376. test_suite("integration")
  377. atf_test_program{name="unused"}
  378. EOF
  379. utils_cp_helper simple_all_pass subdir/unused
  380. cat >experr <<EOF
  381. kyua: E: Load of 'Kyuafile' failed: File 'Kyuafile' not found.
  382. EOF
  383. atf_check -s exit:1 -o empty -e file:experr kyua list subdir
  384. }
  385. utils_test_case bogus_kyuafile
  386. bogus_kyuafile_body() {
  387. cat >Kyuafile <<EOF
  388. Hello, world.
  389. EOF
  390. cat >experr <<EOF
  391. kyua: E: Load of 'Kyuafile' failed: Failed to load Lua file 'Kyuafile': Kyuafile:2: '<name>' expected near '<eof>'.
  392. EOF
  393. atf_check -s exit:1 -o empty -e file:experr kyua list
  394. }
  395. utils_test_case bogus_test_program
  396. bogus_test_program_body() {
  397. cat >Kyuafile <<EOF
  398. syntax("kyuafile", 1)
  399. test_suite("integration")
  400. atf_test_program{name="crash_on_list"}
  401. atf_test_program{name="non_executable"}
  402. EOF
  403. utils_cp_helper bad_test_program crash_on_list
  404. echo 'I am not executable' >non_executable
  405. cat >expout <<EOF
  406. crash_on_list:__test_cases_list__
  407. non_executable:__test_cases_list__
  408. EOF
  409. atf_check -s exit:0 -o file:expout -e empty kyua list
  410. }
  411. utils_test_case missing_test_program
  412. missing_test_program_body() {
  413. cat >Kyuafile <<EOF
  414. syntax("kyuafile", 1)
  415. include("subdir/Kyuafile")
  416. EOF
  417. mkdir subdir
  418. cat >subdir/Kyuafile <<EOF
  419. syntax("kyuafile", 1)
  420. test_suite("integration")
  421. atf_test_program{name="ok"}
  422. atf_test_program{name="i-am-missing"}
  423. EOF
  424. echo 'I should not be touched because the Kyuafile is bogus' >subdir/ok
  425. cat >experr <<EOF
  426. kyua: E: Load of 'Kyuafile' failed: Non-existent test program 'subdir/i-am-missing'.
  427. EOF
  428. atf_check -s exit:1 -o empty -e file:experr kyua list
  429. }
  430. atf_init_test_cases() {
  431. atf_add_test_case no_args
  432. atf_add_test_case one_arg__subdir
  433. atf_add_test_case one_arg__test_case
  434. atf_add_test_case one_arg__test_program
  435. atf_add_test_case one_arg__invalid
  436. atf_add_test_case many_args__ok
  437. atf_add_test_case many_args__invalid
  438. atf_add_test_case many_args__no_match__all
  439. atf_add_test_case many_args__no_match__some
  440. atf_add_test_case args_are_relative
  441. atf_add_test_case only_load_used_test_programs
  442. atf_add_test_case kyuafile_flag__no_args
  443. atf_add_test_case kyuafile_flag__some_args
  444. atf_add_test_case verbose_flag
  445. atf_add_test_case no_test_program_match
  446. atf_add_test_case no_test_case_match
  447. atf_add_test_case missing_kyuafile__no_args
  448. atf_add_test_case missing_kyuafile__test_program
  449. atf_add_test_case missing_kyuafile__subdir
  450. atf_add_test_case bogus_kyuafile
  451. atf_add_test_case bogus_test_program
  452. atf_add_test_case missing_test_program
  453. }