aboutsummaryrefslogtreecommitdiff
path: root/tests/core/go_test/README.rst
blob: 176cf1969a1b8f519b284bbac78d34128a76d114 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
Basic go_test functionality
===========================

.. _go_test: /docs/go/core/rules.md#_go_test
.. _#1877: https://github.com/bazelbuild/rules_go/issues/1877
.. _#34129: https:////github.com/golang/go/issues/34129
.. _#2749: https://github.com/bazelbuild/rules_go/issues/2749

Tests to ensure that basic features of `go_test`_ are working as expected.

.. contents::

internal_test
-------------

Test that a `go_test`_ rule that adds white box tests to an embedded package works.
This builds a library with `lib.go <lib.go>`_ and then a package with an
`internal test <internal_test.go>`_ that contains the test case.
It uses x_def stamped values to verify the library names are correct.

external_test
-------------

Test that a `go_test`_ rule that adds black box tests for a dependant package works.
This builds a library with `lib.go <lib.go>`_ and then a package with an
`external test <external_test.go>`_ that contains the test case.
It uses x_def stamped values to verify the library names are correct.

combined_test
-------------
Test that a `go_test`_ rule that adds both white and black box tests for a
package works.
This builds a library with `lib.go <lib.go>`_ and then a one merged with the
`internal test <internal_test.go>`_, and then another one that depends on it
with the `external test <external_test.go>`_.
It uses x_def stamped values to verify that all library names are correct.
Verifies #413

flag_test
---------
Test that a `go_test`_ rule that adds flags, even in the main package, can read
the flag.
This does not even build a library, it's a test in the main package with no
dependancies that checks it can declare and then read a flag.
Verifies #838

only_testmain_test
------------------
Test that an `go_test`_ that contains a ``TestMain`` function but no tests
still builds and passes.

external_importmap_test
----------------------

Test that an external test package in `go_test`_ is compiled with the correct
``importmap`` for the library under test. This is verified by defining an
interface in the library under test and implementing it in a separate
dependency.

Verifies #1538.

pwd_test
--------

Checks that the ``PWD`` environment variable is set to the current directory
in the generated test main before running a test. This matches functionality
in ``go test``.

Verifies #1561.

data_test
---------

Checks that data dependencies, including those inherited from ``deps`` and
``embed``, are visible to tests at run-time. Source files should not be
visible at run-time.

test_fail_fast_test
----------------

Checks that ``--test_runner_fail_fast`` actually enables stopping test execution after
the first failure.

Verifies #3055.

test_filter_test
----------------

Checks that ``--test_filter`` actually filters out test cases.

testmain_import_test
----------------

Check if all packages in all source files are imported to test main, to ensure
a consistent test behaviour. This ensures a consistent behaviour when thinking
about global indirect depencencies.

tags_test
---------

Checks that setting ``gotags`` affects source filtering. The test will fail
unless a specific tag is set.

indirect_import_test
--------------------

Checks that an external test can import another package that imports the library
under test. The other package should be compiled against the internal test
package, not the library under test. Verifies `#1877`_.

testmain_without_exit
---------------------

Checks that TestMain without calling os.Exit directly works.
Verifies `#34129`_ from Go 1.15.

wrapper_test
------------

Checks that a ``go_test`` can be executed by another test in a subdirectory.
Verifies `#2749`_.

fuzz_test
---------

Checks that a ``go_test`` with a fuzz target builds correctly.