OLD | NEW |
---|---|
1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 # This file is meant to be included into an target to create a unittest that | 5 # This file is meant to be included into an target to create a unittest that |
6 # invokes a set of no-compile tests. A no-compile test is a test that asserts | 6 # invokes a set of no-compile tests. A no-compile test is a test that asserts |
7 # a particular construct will not compile. | 7 # a particular construct will not compile. |
8 # | 8 # |
9 # Also see: | 9 # Also see: |
10 # http://dev.chromium.org/developers/testing/no-compile-tests | 10 # http://dev.chromium.org/developers/testing/no-compile-tests |
11 # | 11 # |
12 # To use this, create a gyp target with the following form: | 12 # To use this, create a gyp target with the following form: |
13 # { | 13 # |
14 # 'target_name': 'my_module_nc_unittests', | 14 # import("//build/nocompile.gni") |
15 # 'type': 'executable', | 15 # nocompile_test("my_module_nc_unittests") { |
16 # 'sources': [ | 16 # sources = [ |
17 # 'nc_testset_1.nc', | 17 # 'nc_testset_1.nc', |
18 # 'nc_testset_2.nc', | 18 # 'nc_testset_2.nc', |
19 # ], | 19 # ] |
20 # 'includes': ['path/to/this/gypi/file'], | |
21 # } | 20 # } |
22 # | 21 # |
23 # The .nc files are C++ files that contain code we wish to assert will not | 22 # The .nc files are C++ files that contain code we wish to assert will not |
24 # compile. Each individual test case in the file should be put in its own | 23 # compile. Each individual test case in the file should be put in its own |
25 # #ifdef section. The expected output should be appended with a C++-style | 24 # #ifdef section. The expected output should be appended with a C++-style |
26 # comment that has a python list of regular expressions. This will likely | 25 # comment that has a python list of regular expressions. This will likely |
27 # be greater than 80-characters. Giving a solid expected output test is | 26 # be greater than 80-characters. Giving a solid expected output test is |
28 # important so that random compile failures do not cause the test to pass. | 27 # important so that random compile failures do not cause the test to pass. |
29 # | 28 # |
30 # Example .nc file: | 29 # Example .nc file: |
(...skipping 18 matching lines...) Expand all Loading... | |
49 # formatting or ifdef logic; it will likely just not work. | 48 # formatting or ifdef logic; it will likely just not work. |
50 # | 49 # |
51 # Implementation notes: | 50 # Implementation notes: |
52 # The .nc files are actually processed by a python script which executes the | 51 # The .nc files are actually processed by a python script which executes the |
53 # compiler and generates a .cc file that is empty on success, or will have a | 52 # compiler and generates a .cc file that is empty on success, or will have a |
54 # series of #error lines on failure, and a set of trivially passing gunit | 53 # series of #error lines on failure, and a set of trivially passing gunit |
55 # TEST() functions on success. This allows us to fail at the compile step when | 54 # TEST() functions on success. This allows us to fail at the compile step when |
56 # something goes wrong, and know during the unittest run that the test was at | 55 # something goes wrong, and know during the unittest run that the test was at |
57 # least processed when things go right. | 56 # least processed when things go right. |
58 | 57 |
59 { | 58 import("//testing/test.gni") |
60 # TODO(awong): Disabled until http://crbug.com/105388 is resolved. | 59 |
61 'sources/': [['exclude', '\\.nc$']], | 60 declare_args() { |
62 'conditions': [ | 61 enable_nocompile_tests = false |
63 [ 'OS!="win" and clang==1', { | |
64 'rules': [ | |
65 { | |
66 'variables': { | |
67 'nocompile_driver': '<(DEPTH)/tools/nocompile_driver.py', | |
68 'nc_result_path': ('<(INTERMEDIATE_DIR)/<(module_dir)/' | |
69 '<(RULE_INPUT_ROOT)_nc.cc'), | |
70 }, | |
71 'rule_name': 'run_nocompile', | |
72 'extension': 'nc', | |
73 'inputs': [ | |
74 '<(nocompile_driver)', | |
75 ], | |
76 'outputs': [ | |
77 '<(nc_result_path)' | |
78 ], | |
79 'action': [ | |
80 'python', | |
81 '<(nocompile_driver)', | |
82 '4', # number of compilers to invoke in parallel. | |
83 '<(RULE_INPUT_PATH)', | |
84 '-Wall -Werror -Wfatal-errors -I<(DEPTH)', | |
85 '<(nc_result_path)', | |
86 ], | |
87 'message': 'Generating no compile results for <(RULE_INPUT_PATH)', | |
88 'process_outputs_as_sources': 1, | |
89 }, | |
90 ], | |
91 }, { | |
92 'sources/': [['exclude', '\\.nc$']] | |
93 }], # 'OS!="win" and clang=="1"' | |
94 ], | |
95 } | 62 } |
96 | 63 |
64 if (enable_nocompile_tests) { | |
65 template("nocompile_test") { | |
66 nocompile_target = target_name + "_run_nocompile" | |
67 | |
68 action_foreach(nocompile_target) { | |
69 script = "//tools/nocompile_driver.py" | |
70 sources = invoker.sources | |
71 outputs = [ | |
72 "$target_gen_dir/{{source_name_part}}_nc.cc", | |
73 ] | |
74 args = [ | |
75 "4", | |
dcheng
2015/12/15 18:14:47
I'm not very familiar with GN: what does the 4 her
Nico
2015/12/15 19:10:04
See this on the lhs:
'4', # number of compilers t
tzik
2015/12/16 07:45:27
Added the comment too.
Yes, it's from the .gypi.
| |
76 "{{source}}", | |
77 "-Wall -Werror -Wfatal-errors " + "-I" + | |
78 rebase_path("//", root_build_dir), | |
79 "{{output}}", | |
80 ] | |
81 } | |
82 | |
83 test(target_name) { | |
84 deps = invoker.deps + [ ":$nocompile_target" ] | |
85 sources = get_target_outputs(":$nocompile_target") | |
86 } | |
87 } | |
88 } | |
OLD | NEW |