github.phpd.cn/thought-machine/please@v12.2.0+incompatible/test/BUILD (about) 1 # A series of end-to-end tests on the Please binary. 2 # 3 # These are a little fragile since they assume things about specific output messages, which 4 # of course we might rather not. However it's something of a pain to get good test coverage 5 # since by its nature the tool has heaps of side effects, so this is at least one way of 6 # reassuring ourselves that it does behave as expected. 7 # 8 # Note that we have to be kinda careful with this; since it invokes plz to run tests while 9 # an instance of it is already going, there are potential concurrency issues. These are 10 # mitigated by having these tests only run tests in this package which are tagged as manual 11 # so the bootstrap script won't try to run them twice simultaneously. 12 13 subinclude('//build_defs:plz_e2e_test') 14 15 # Tests the expected output of 'query somepath'. 16 # Note that you have to be careful with the choice of targets, since the path 17 # found is not necessarily unique or stable. 18 plz_e2e_test( 19 name = 'query_somepath_test', 20 cmd = 'plz query somepath //tools/junit_runner //third_party/java:_junit#bin', 21 expected_output = 'query_somepath_test.txt', 22 ) 23 24 plz_e2e_test( 25 name = 'query_somepath_reverse_test', 26 cmd = 'plz query somepath //third_party/java:_junit#bin //tools/junit_runner', 27 expected_output = 'query_somepath_test.txt', # Output should be the same as above 28 ) 29 30 plz_e2e_test( 31 name = 'query_somepath_nopath_test', 32 cmd = 'plz query somepath //src:please //third_party/java:junit', 33 expected_output = 'query_somepath_nopath_test.txt', 34 ) 35 36 # Tests that targets can only use other targets that they depend on. 37 plz_e2e_test( 38 name = 'dep_required_test', 39 cmd = 'plz build //test:failed_dep', 40 expect_output_contains = "//test:failed_dep can't use //src/core; doesn't depend on target //src/core", 41 expected_failure = True, 42 ) 43 44 build_rule( 45 name = 'failed_dep', 46 cmd = 'echo $(location //src/core)', 47 labels = ['manual'], 48 ) 49 50 # Test that we count test output correctly. Also indirectly tests access to test data files. 51 # Note that we're stripping coloured output for now. Later we should probably have a flag or something. 52 plz_e2e_test( 53 name = 'test_output_test', 54 cmd = 'plz test //test:test_output_test_1 //test:test_output_test_2 | sed "s/\033\\[[0-9;]*[a-zA-Z]//g"', 55 expect_output_contains = '6 tests run; 6 passed.', 56 # Invokes a containerised test although it's not itself. 57 labels = ['container'], 58 ) 59 60 gentest( 61 name = 'test_output_test_1', 62 data = ['test_output_test_1.txt'], 63 labels = ['manual'], 64 test_cmd = 'cp $(location test_output_test_1.txt) test.results', 65 ) 66 67 gentest( 68 name = 'test_output_test_2', 69 container = True, 70 data = ['test_output_test_2.xml'], 71 labels = ['manual'], 72 test_cmd = 'cp $(location test_output_test_2.xml) test.results', 73 ) 74 75 # Test that on re-running a test it is cached. 76 plz_e2e_test( 77 name = 'test_caching_test', 78 cmd = 'plz test //test:caching_test && plz test -v 4 //test:caching_test', 79 expect_output_contains = 'Not re-running test //test:caching_test', 80 ) 81 82 gentest( 83 name = 'caching_test', 84 labels = ['manual'], 85 no_test_output = True, 86 test_cmd = 'true', 87 deps = ['//src:please'], 88 ) 89 90 # Test that we don't generate coverage on running a test normally (because it's slower). 91 python_test( 92 name = '_no_coverage_output_test', 93 srcs = ['coverage_output_test.py'], 94 labels = ['manual'], 95 ) 96 97 plz_e2e_test( 98 name = 'no_coverage_output_test', 99 cmd = 'plz test //test:_no_coverage_output_test', 100 expect_file_doesnt_exist = '../../../bin/test/.test_coverage__no_coverage_output_test*', 101 labels = ['python3'], 102 ) 103 104 # Test that we do generate it when using plz cover. 105 python_test( 106 name = '_coverage_output_test', 107 srcs = ['coverage_output_test.py'], 108 labels = ['manual'], 109 ) 110 111 plz_e2e_test( 112 name = 'coverage_output_test', 113 cmd = 'plz cover //test:_coverage_output_test', 114 expect_file_exists = '../../../bin/test/.test_coverage__coverage_output_test*', 115 # Temporarily disabled until #25 is resolved. Until then it recompiles various go_library 116 # rules which makes it (and possibly others) flaky. 117 labels = ['manual'], 118 ) 119 120 # Quick test for plz run 121 plz_e2e_test( 122 name = 'plz_run_test', 123 cmd = 'plz run //src:please -- --version', 124 expect_output_contains = 'Please version', 125 ) 126 127 # Test for query alltargets 128 plz_e2e_test( 129 name = 'query_alltargets_test', 130 cmd = 'plz query alltargets', 131 expect_output_contains = '//src:please', 132 ) 133 134 # Test for query output 135 plz_e2e_test( 136 name = 'query_output_test', 137 cmd = 'plz query output //test:query_output_filegroup', 138 expected_output = 'query_output_test.txt', 139 ) 140 141 filegroup( 142 name = 'query_output_filegroup', 143 srcs = ['//src:please'], 144 ) 145 146 # Test running a test with no-cache 147 plz_e2e_test( 148 name = 'test_nocache_test', 149 cmd = 'plz test --nocache //test:nocache_test', 150 ) 151 152 gentest( 153 name = 'nocache_test', 154 labels = ['manual'], 155 no_test_output = True, 156 test_cmd = 'true', 157 deps = ['//src:please'], 158 ) 159 160 # Simulates a code generating rule to test the require / provide mechanism. 161 plz_e2e_test( 162 name = 'require_provide_test', 163 cmd = 'plz build //test/moar:require_provide_check -v 2 -p', 164 expect_output_doesnt_contain = '//test/moar:test_require', 165 ) 166 167 # Test for running individual tests 168 python_test( 169 name = 'individual_test_run_py', 170 srcs = ['individual_test_run.py'], 171 labels = ['manual'], 172 ) 173 174 plz_e2e_test( 175 name = 'individual_python_test', 176 cmd = 'plz test //test:individual_test_run_py TestRunningIndividualTests.test_first_thing', 177 expect_output_contains = '1 test target and 1 test run', 178 labels = ['python3'], 179 ) 180 181 java_test( 182 name = 'individual_test_run_java', 183 srcs = ['IndividualTest.java'], 184 labels = ['manual'], 185 deps = [ 186 '//third_party/java:junit', 187 ], 188 ) 189 190 plz_e2e_test( 191 name = 'individual_java_test', 192 cmd = 'plz test //test:individual_test_run_java testFirstThing', 193 expect_output_contains = '1 test target and 1 test run', 194 labels = ['java'], 195 ) 196 197 java_test( 198 name = 'no_test_run_java', 199 srcs = ['NoTestRun.java'], 200 labels = ['manual'], 201 deps = [ 202 '//third_party/java:junit', 203 ], 204 ) 205 206 plz_e2e_test( 207 name = 'no_java_test', 208 cmd = 'plz test -p //test:no_test_run_java wibblewobble', 209 expect_output_contains = '1 failed', 210 expected_failure = True, 211 ) 212 213 # Test re-runs. 214 go_test( 215 name = 'num_runs_go_test', 216 srcs = ['num_runs_test.go'], 217 labels = ['manual'], 218 ) 219 220 plz_e2e_test( 221 name = 'num_runs_test', 222 cmd = 'plz test -p --num_runs=5 //test:num_runs_go_test', 223 expect_output_contains = '5 passed', 224 ) 225 226 # Tests for query affectedtests. 227 plz_e2e_test( 228 name = 'query_affectedtests_test', 229 cmd = 'plz query affectedtargets --tests -p test/affectedtests_test.go', 230 expected_output = 'query_affectedtests_test.txt', 231 ) 232 233 plz_e2e_test( 234 name = 'query_affectedtests_stdin_test', 235 cmd = 'echo test/affectedtests_test.go | plz query affectedtargets --tests -p -', 236 expected_output = 'query_affectedtests_test.txt', 237 ) 238 239 go_test( 240 name = 'affectedtests_test', 241 srcs = ['affectedtests_test.go'], 242 ) 243 244 go_test( 245 name = 'affectedtests_manual_test', 246 srcs = ['affectedtests_test.go'], 247 labels = ['manual'], 248 ) 249 250 # Tests for query completions 251 plz_e2e_test( 252 name = 'basic_completion_test', 253 cmd = 'plz query completions //test/completions: | sort', 254 expected_output = 'basic_completions.txt', 255 ) 256 257 plz_e2e_test( 258 name = 'build_completion_test', 259 cmd = 'plz query completions //test/completions: --cmd build | sort', 260 expected_output = 'basic_completions.txt', 261 ) 262 263 plz_e2e_test( 264 name = 'test_completion_test', 265 cmd = 'plz query completions //test/completions: --cmd test | sort', 266 expected_output = 'test_completions.txt', 267 ) 268 269 plz_e2e_test( 270 name = 'run_completion_test', 271 cmd = 'plz query completions //test/completions: --cmd run | sort', 272 expected_output = 'run_completions.txt', 273 ) 274 275 # Flag tests 276 plz_e2e_test( 277 name = 'extra_flag_test', 278 cmd = 'plz cache clean', 279 expected_failure = True, 280 ) 281 282 # Test the add_out functionality which has a subtle dependency on the order 283 # we do things relating to the cache. 284 genrule( 285 name = '_add_out_gen', 286 cmd = 'echo hello > _add_out_gen.txt', 287 post_build = lambda name, _: add_out(name, '_add_out_gen.txt'), 288 ) 289 290 gentest( 291 name = '_add_out_test', 292 data = [':_add_out_gen'], 293 labels = ['manual'], 294 no_test_output = True, 295 test_cmd = 'ls test/_add_out_gen.txt', 296 ) 297 298 plz_e2e_test( 299 name = 'add_out_test', 300 cmd = 'plz build //test:_add_out_test && plz clean //test:_add_out_gen && plz test //test:_add_out_test', 301 ) 302 303 # Test the extra output functionality. 304 go_test( 305 name = 'extra_test_output_go_test', 306 srcs = ['extra_test_output_test.go'], 307 container = True, 308 labels = ['manual'], 309 test_outputs = ['truth.txt'], 310 ) 311 312 plz_e2e_test( 313 name = 'extra_test_output_test', 314 cmd = 'plz test //test:extra_test_output_go_test', 315 expect_file_exists = '../../../bin/test/truth.txt', 316 labels = ['container'], 317 ) 318 319 # Test 'query alltargets' 320 plz_e2e_test( 321 name = 'query_alltargets_1_test', 322 cmd = 'plz query alltargets //test/moar/...', 323 expected_output = 'query_alltargets_1.txt', 324 ) 325 326 plz_e2e_test( 327 name = 'query_alltargets_2_test', 328 cmd = 'plz query alltargets //test/moar/... --include test', 329 expected_output = 'query_alltargets_2.txt', 330 ) 331 332 plz_e2e_test( 333 name = 'cyclic_dependency_test', 334 cmd = 'plz test //plz-out/tmp/test/cyclic_dependency_test#.test/test/cycle:all', 335 data = ['cycle/TEST_BUILD'], 336 expect_output_contains = 'Dependency cycle found', 337 expected_failure = True, 338 pre_cmd = 'mv test/cycle/TEST_BUILD test/cycle/BUILD', 339 ) 340 341 # Used manually for testing the test flakiness stuff. 342 python_test( 343 name = 'flaky_test', 344 srcs = ['flaky_test.py'], 345 flaky = True, 346 labels = ['manual'], 347 ) 348 349 # Tests on commands / flags etc. 350 plz_e2e_test( 351 name = 'unknown_command_test', 352 cmd = 'plz fix', 353 expect_output_contains = 'Unknown command', 354 expected_failure = True, 355 ) 356 357 plz_e2e_test( 358 name = 'unknown_flag_test', 359 cmd = 'plz build --wibble', 360 expect_output_contains = 'Unknown flag', 361 expected_failure = True, 362 ) 363 364 # Tests on the stamp attribute. 365 # These essentially pass as long as they can build. 366 # (Note that we can't use -v because OSX is unlikely to have a new enough version of bash). 367 build_rule( 368 name = 'stamp_negative_test', 369 cmd = '[ -z ${STAMP+x} ]', 370 no_test_output = True, 371 test = True, 372 test_cmd = 'true', 373 ) 374 375 build_rule( 376 name = 'stamp_positive_test', 377 cmd = '[ ! -z ${STAMP+x} ]', 378 no_test_output = True, 379 stamp = True, 380 test = True, 381 test_cmd = 'true', 382 ) 383 384 # Test on a build rule that writes a symlink. 385 genrule( 386 name = 'symlink_gen', 387 srcs = ['symlink_test.txt'], 388 outs = ['symlink_test.txt'], 389 cmd = 'ln -s $SRCS $OUTS', 390 ) 391 392 gentest( 393 name = 'symlink_test', 394 data = [':symlink_gen'], 395 no_test_output = True, 396 test_cmd = 'test -L test/symlink_test.txt', 397 ) 398 399 # This rule tests the no_test_output flag. If that isn't honoured 400 # plz would report a test failure because results were missing. 401 gentest( 402 name = 'no_test_output_test', 403 no_test_output = True, 404 test_cmd = 'echo SUCCESS', 405 ) 406 407 # This tests that data files exist in the correct location, and 408 # indirectly performs a basic test of sh_test which we don't use elsewhere. 409 sh_test( 410 name = 'data_files_test', 411 src = 'data_files_test.sh', 412 data = ['container_data.txt'], 413 ) 414 415 # This test is here as a convenience to test the flakiness functionality. 416 # It's just using random internally so won't pass consistently. 417 python_test( 418 name = 'flakiness_test', 419 srcs = ['flakiness_test.py'], 420 flaky = 5, 421 labels = ['manual'], 422 ) 423 424 # Test that it's not possible to glob the BUILD file at parse time. 425 if 'BUILD' in glob(['*']): 426 raise ParseError('should not be able to glob the BUILD file')