File: unittest.gni

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (58 lines) | stat: -rw-r--r-- 2,333 bytes parent folder | download | duplicates (14)
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
# This file defines a template for adding a unittest binary.
#
# It's a thin wrapper around GN's built-in executable() target type and
# accepts the same parameters, and in addition this paramater:
#
#   has_custom_main (optional)
#       [bool] If set, link against gtest instead of UnitTestMain; for tests
#              that define their own main() function.
#
# Example use:
#
#   unittest("FormatTest") {
#     sources = [ ... ]
#     ...
#   }

template("unittest") {
  executable(target_name) {
    has_custom_main = false  # Default value.

    # Foward everything (has_custom_main if set; configs, sources, deps, ...).
    forward_variables_from(invoker, "*")
    assert(!defined(invoker.output_dir), "cannot set unittest output_dir")
    assert(!defined(invoker.testonly), "cannot set unittest testonly")

    # Common settings for all unit tests.
    # Unit test binaries shouldn't go right in out/gn/bin, for two reasons:
    # 1. That's where production binaries go.
    # 2. The CMake build doesn't put the unit tests of all projects (clang,
    #    lld,...) in one directory, so it's not guaranteed that there won't
    #    be name collisions between test binaries from separate projects.
    # Each lit suite takes an foo_obj_root parameter and puts temporary files
    # for lit tests at foo_obj_root/test and looks for unit test binaries
    # below foo_obj_root/unittests. As long as the BUILD.gn files processing
    # the lit.site.cfg.py.in files match the output dir here, it doesn't
    # matter all that much where the unit test binaries go, with the weak
    # constraints that test binaries of different projects should go in
    # different folders, and that it's not too difficult to manually
    # run the unit test binary if necessary. Using target_out_dir here
    # means that //clang/unittests/Format gets its binary in
    # out/gn/obj/clang/unittests/Format/FormatTests, which seems fine.
    #
    # If you change output_dir here, look through
    # `git grep target_out_dir '*/unittests/*'` and update those too.
    output_dir = target_out_dir

    if (has_custom_main) {
      deps += [ "//third-party/unittest:gtest" ]
    } else {
      deps += [ "//third-party/unittest/UnitTestMain" ]
    }
    testonly = true
  }
}

set_defaults("unittest") {
  configs = shared_binary_target_configs
}