xref: /aosp_15_r20/external/bazelbuild-rules_go/tests/core/go_test/README.rst (revision 9bb1b549b6a84214c53be0924760be030e66b93a)
1Basic go_test functionality
2===========================
3
4.. _go_test: /docs/go/core/rules.md#_go_test
5.. _#1877: https://github.com/bazelbuild/rules_go/issues/1877
6.. _#34129: https:////github.com/golang/go/issues/34129
7.. _#2749: https://github.com/bazelbuild/rules_go/issues/2749
8
9Tests to ensure that basic features of `go_test`_ are working as expected.
10
11.. contents::
12
13internal_test
14-------------
15
16Test that a `go_test`_ rule that adds white box tests to an embedded package works.
17This builds a library with `lib.go <lib.go>`_ and then a package with an
18`internal test <internal_test.go>`_ that contains the test case.
19It uses x_def stamped values to verify the library names are correct.
20
21external_test
22-------------
23
24Test that a `go_test`_ rule that adds black box tests for a dependant package works.
25This builds a library with `lib.go <lib.go>`_ and then a package with an
26`external test <external_test.go>`_ that contains the test case.
27It uses x_def stamped values to verify the library names are correct.
28
29combined_test
30-------------
31Test that a `go_test`_ rule that adds both white and black box tests for a
32package works.
33This builds a library with `lib.go <lib.go>`_ and then a one merged with the
34`internal test <internal_test.go>`_, and then another one that depends on it
35with the `external test <external_test.go>`_.
36It uses x_def stamped values to verify that all library names are correct.
37Verifies #413
38
39flag_test
40---------
41Test that a `go_test`_ rule that adds flags, even in the main package, can read
42the flag.
43This does not even build a library, it's a test in the main package with no
44dependancies that checks it can declare and then read a flag.
45Verifies #838
46
47only_testmain_test
48------------------
49Test that an `go_test`_ that contains a ``TestMain`` function but no tests
50still builds and passes.
51
52external_importmap_test
53----------------------
54
55Test that an external test package in `go_test`_ is compiled with the correct
56``importmap`` for the library under test. This is verified by defining an
57interface in the library under test and implementing it in a separate
58dependency.
59
60Verifies #1538.
61
62pwd_test
63--------
64
65Checks that the ``PWD`` environment variable is set to the current directory
66in the generated test main before running a test. This matches functionality
67in ``go test``.
68
69Verifies #1561.
70
71data_test
72---------
73
74Checks that data dependencies, including those inherited from ``deps`` and
75``embed``, are visible to tests at run-time. Source files should not be
76visible at run-time.
77
78test_fail_fast_test
79----------------
80
81Checks that ``--test_runner_fail_fast`` actually enables stopping test execution after
82the first failure.
83
84Verifies #3055.
85
86test_filter_test
87----------------
88
89Checks that ``--test_filter`` actually filters out test cases.
90
91testmain_import_test
92----------------
93
94Check if all packages in all source files are imported to test main, to ensure
95a consistent test behaviour. This ensures a consistent behaviour when thinking
96about global indirect depencencies.
97
98tags_test
99---------
100
101Checks that setting ``gotags`` affects source filtering. The test will fail
102unless a specific tag is set.
103
104indirect_import_test
105--------------------
106
107Checks that an external test can import another package that imports the library
108under test. The other package should be compiled against the internal test
109package, not the library under test. Verifies `#1877`_.
110
111testmain_without_exit
112---------------------
113
114Checks that TestMain without calling os.Exit directly works.
115Verifies `#34129`_ from Go 1.15.
116
117wrapper_test
118------------
119
120Checks that a ``go_test`` can be executed by another test in a subdirectory.
121Verifies `#2749`_.
122
123fuzz_test
124---------
125
126Checks that a ``go_test`` with a fuzz target builds correctly.
127