Eran Shalom | f1db75c | 2018-08-27 07:09:19 -0700 | [diff] [blame] | 1 | // Copyright 2015 The Bazel Authors. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package com.google.devtools.build.lib.runtime; |
| 16 | |
Googler | ba6fdb9 | 2018-12-08 06:29:58 -0800 | [diff] [blame] | 17 | import static com.google.common.truth.Truth.assertThat; |
Googler | a670577 | 2019-05-28 09:39:18 -0700 | [diff] [blame] | 18 | import static org.mockito.ArgumentMatchers.any; |
Googler | ba6fdb9 | 2018-12-08 06:29:58 -0800 | [diff] [blame] | 19 | import static org.mockito.Mockito.mock; |
Eran Shalom | f1db75c | 2018-08-27 07:09:19 -0700 | [diff] [blame] | 20 | import static org.mockito.Mockito.never; |
ichern | 8ec182a | 2020-01-08 05:29:11 -0800 | [diff] [blame] | 21 | import static org.mockito.Mockito.times; |
Eran Shalom | f1db75c | 2018-08-27 07:09:19 -0700 | [diff] [blame] | 22 | import static org.mockito.Mockito.verify; |
| 23 | import static org.mockito.Mockito.when; |
| 24 | |
ichern | 8ec182a | 2020-01-08 05:29:11 -0800 | [diff] [blame] | 25 | import com.google.common.collect.ImmutableList; |
Eran Shalom | f1db75c | 2018-08-27 07:09:19 -0700 | [diff] [blame] | 26 | import com.google.common.collect.ImmutableMap; |
Googler | ba6fdb9 | 2018-12-08 06:29:58 -0800 | [diff] [blame] | 27 | import com.google.common.collect.ImmutableSet; |
ichern | 8ec182a | 2020-01-08 05:29:11 -0800 | [diff] [blame] | 28 | import com.google.common.collect.ImmutableSortedSet; |
Eran Shalom | f1db75c | 2018-08-27 07:09:19 -0700 | [diff] [blame] | 29 | import com.google.devtools.build.lib.cmdline.Label; |
Googler | ba6fdb9 | 2018-12-08 06:29:58 -0800 | [diff] [blame] | 30 | import com.google.devtools.build.lib.cmdline.LabelSyntaxException; |
Eran Shalom | f1db75c | 2018-08-27 07:09:19 -0700 | [diff] [blame] | 31 | import com.google.devtools.build.lib.exec.ExecutionOptions; |
jcater | d990df5 | 2020-04-07 04:38:15 -0700 | [diff] [blame] | 32 | import com.google.devtools.build.lib.exec.ExecutionOptions.TestSummaryFormat; |
Eran Shalom | f1db75c | 2018-08-27 07:09:19 -0700 | [diff] [blame] | 33 | import com.google.devtools.build.lib.runtime.TerminalTestResultNotifier.TestSummaryOptions; |
| 34 | import com.google.devtools.build.lib.util.io.AnsiTerminalPrinter; |
nharmata | ccc4295 | 2018-10-25 15:39:26 -0700 | [diff] [blame] | 35 | import com.google.devtools.build.lib.vfs.Path; |
Eran Shalom | f1db75c | 2018-08-27 07:09:19 -0700 | [diff] [blame] | 36 | import com.google.devtools.build.lib.view.test.TestStatus.BlazeTestStatus; |
| 37 | import com.google.devtools.build.lib.view.test.TestStatus.TestCase; |
| 38 | import com.google.devtools.build.lib.view.test.TestStatus.TestCase.Status; |
| 39 | import com.google.devtools.common.options.OptionsParsingResult; |
Eran Shalom | f1db75c | 2018-08-27 07:09:19 -0700 | [diff] [blame] | 40 | import java.util.Collections; |
ichern | 8ec182a | 2020-01-08 05:29:11 -0800 | [diff] [blame] | 41 | import java.util.Comparator; |
Googler | ba6fdb9 | 2018-12-08 06:29:58 -0800 | [diff] [blame] | 42 | import java.util.List; |
Eran Shalom | f1db75c | 2018-08-27 07:09:19 -0700 | [diff] [blame] | 43 | import org.junit.Test; |
| 44 | import org.junit.runner.RunWith; |
| 45 | import org.junit.runners.JUnit4; |
Googler | ba6fdb9 | 2018-12-08 06:29:58 -0800 | [diff] [blame] | 46 | import org.mockito.ArgumentCaptor; |
Eran Shalom | f1db75c | 2018-08-27 07:09:19 -0700 | [diff] [blame] | 47 | |
Googler | ba6fdb9 | 2018-12-08 06:29:58 -0800 | [diff] [blame] | 48 | /** Tests for {@link TerminalTestResultNotifier}. */ |
Eran Shalom | f1db75c | 2018-08-27 07:09:19 -0700 | [diff] [blame] | 49 | @RunWith(JUnit4.class) |
Googler | ba6fdb9 | 2018-12-08 06:29:58 -0800 | [diff] [blame] | 50 | public final class TerminalTestResultNotifierTest { |
Eran Shalom | f1db75c | 2018-08-27 07:09:19 -0700 | [diff] [blame] | 51 | |
ulfjack | 7c20af3 | 2020-01-15 07:59:02 -0800 | [diff] [blame] | 52 | private static final String SOME_TARGETS_ARE_MISSING_TEST_CASES_DISCLAIMER = |
| 53 | "some targets did not have test case information"; |
Eran Shalom | f1db75c | 2018-08-27 07:09:19 -0700 | [diff] [blame] | 54 | |
Googler | ba6fdb9 | 2018-12-08 06:29:58 -0800 | [diff] [blame] | 55 | private final OptionsParsingResult optionsParsingResult = mock(OptionsParsingResult.class); |
| 56 | private final AnsiTerminalPrinter ansiTerminalPrinter = mock(AnsiTerminalPrinter.class); |
| 57 | |
| 58 | private BlazeTestStatus targetStatus; |
| 59 | private int numFailedTestCases; |
ulfjack | 7c20af3 | 2020-01-15 07:59:02 -0800 | [diff] [blame] | 60 | private int numUnknownTestCases; |
Googler | ba6fdb9 | 2018-12-08 06:29:58 -0800 | [diff] [blame] | 61 | private int numTotalTestCases; |
| 62 | private TestSummaryFormat testSummaryFormat; |
| 63 | |
| 64 | @Test |
| 65 | public void testCaseOption_allPass() throws Exception { |
jcater | d990df5 | 2020-04-07 04:38:15 -0700 | [diff] [blame] | 66 | testSummaryFormat = ExecutionOptions.TestSummaryFormat.TESTCASE; |
Googler | ba6fdb9 | 2018-12-08 06:29:58 -0800 | [diff] [blame] | 67 | numFailedTestCases = 0; |
| 68 | numTotalTestCases = 10; |
| 69 | targetStatus = BlazeTestStatus.PASSED; |
| 70 | |
| 71 | printTestCaseSummary(); |
| 72 | |
| 73 | String printed = getPrintedMessage(); |
| 74 | assertThat(printed).contains(info("10 passing")); |
| 75 | assertThat(printed).contains("0 failing"); |
| 76 | assertThat(printed).contains("out of 10 test cases"); |
ulfjack | 7c20af3 | 2020-01-15 07:59:02 -0800 | [diff] [blame] | 77 | assertThat(printed).doesNotContain(SOME_TARGETS_ARE_MISSING_TEST_CASES_DISCLAIMER); |
Googler | ba6fdb9 | 2018-12-08 06:29:58 -0800 | [diff] [blame] | 78 | assertThat(printed).doesNotContain(AnsiTerminalPrinter.Mode.ERROR.toString()); |
| 79 | } |
| 80 | |
| 81 | @Test |
| 82 | public void testCaseOption_allPassButTargetFails() throws Exception { |
jcater | d990df5 | 2020-04-07 04:38:15 -0700 | [diff] [blame] | 83 | testSummaryFormat = ExecutionOptions.TestSummaryFormat.TESTCASE; |
Googler | ba6fdb9 | 2018-12-08 06:29:58 -0800 | [diff] [blame] | 84 | numFailedTestCases = 0; |
ulfjack | 7c20af3 | 2020-01-15 07:59:02 -0800 | [diff] [blame] | 85 | numUnknownTestCases = 10; |
Googler | ba6fdb9 | 2018-12-08 06:29:58 -0800 | [diff] [blame] | 86 | numTotalTestCases = 10; |
| 87 | targetStatus = BlazeTestStatus.FAILED; |
| 88 | |
| 89 | printTestCaseSummary(); |
| 90 | |
| 91 | String printed = getPrintedMessage(); |
ulfjack | 7c20af3 | 2020-01-15 07:59:02 -0800 | [diff] [blame] | 92 | assertThat(printed).contains("0 passing"); |
Googler | ba6fdb9 | 2018-12-08 06:29:58 -0800 | [diff] [blame] | 93 | assertThat(printed).contains("0 failing"); |
| 94 | assertThat(printed).contains("out of 10 test cases"); |
ulfjack | 7c20af3 | 2020-01-15 07:59:02 -0800 | [diff] [blame] | 95 | assertThat(printed).contains(SOME_TARGETS_ARE_MISSING_TEST_CASES_DISCLAIMER); |
Googler | ba6fdb9 | 2018-12-08 06:29:58 -0800 | [diff] [blame] | 96 | assertThat(printed).doesNotContain(AnsiTerminalPrinter.Mode.ERROR.toString()); |
| 97 | } |
| 98 | |
| 99 | @Test |
| 100 | public void testCaseOption_someFail() throws Exception { |
jcater | d990df5 | 2020-04-07 04:38:15 -0700 | [diff] [blame] | 101 | testSummaryFormat = ExecutionOptions.TestSummaryFormat.TESTCASE; |
Googler | ba6fdb9 | 2018-12-08 06:29:58 -0800 | [diff] [blame] | 102 | numFailedTestCases = 2; |
ulfjack | 7c20af3 | 2020-01-15 07:59:02 -0800 | [diff] [blame] | 103 | numUnknownTestCases = 0; |
Googler | ba6fdb9 | 2018-12-08 06:29:58 -0800 | [diff] [blame] | 104 | numTotalTestCases = 10; |
| 105 | targetStatus = BlazeTestStatus.FAILED; |
| 106 | |
| 107 | printTestCaseSummary(); |
| 108 | |
| 109 | String printed = getPrintedMessage(); |
| 110 | assertThat(printed).contains(info("8 passing")); |
| 111 | assertThat(printed).contains(error("2 failing")); |
| 112 | assertThat(printed).contains("out of 10 test cases"); |
ulfjack | 7c20af3 | 2020-01-15 07:59:02 -0800 | [diff] [blame] | 113 | assertThat(printed).doesNotContain(SOME_TARGETS_ARE_MISSING_TEST_CASES_DISCLAIMER); |
Googler | ba6fdb9 | 2018-12-08 06:29:58 -0800 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | @Test |
ichern | 8ec182a | 2020-01-08 05:29:11 -0800 | [diff] [blame] | 117 | public void shortOption_someFailToBuild() throws Exception { |
jcater | d990df5 | 2020-04-07 04:38:15 -0700 | [diff] [blame] | 118 | testSummaryFormat = ExecutionOptions.TestSummaryFormat.SHORT; |
ichern | 8ec182a | 2020-01-08 05:29:11 -0800 | [diff] [blame] | 119 | numFailedTestCases = 0; |
| 120 | int numFailedToBuildTestCases = TerminalTestResultNotifier.NUM_FAILED_TO_BUILD + 1; |
ulfjack | 7c20af3 | 2020-01-15 07:59:02 -0800 | [diff] [blame] | 121 | numUnknownTestCases = 0; |
ichern | 8ec182a | 2020-01-08 05:29:11 -0800 | [diff] [blame] | 122 | numTotalTestCases = 10; |
| 123 | targetStatus = BlazeTestStatus.FAILED_TO_BUILD; |
| 124 | |
| 125 | printFailedToBuildSummaries(); |
| 126 | |
| 127 | String skippedMessage = getPrintedMessage(); |
| 128 | assertThat(skippedMessage).isEqualTo("(Skipping other failed to build tests)"); |
| 129 | |
| 130 | ArgumentCaptor<String> messageCaptor = ArgumentCaptor.forClass(String.class); |
| 131 | verify(ansiTerminalPrinter, times(numFailedToBuildTestCases)).print(messageCaptor.capture()); |
| 132 | List<String> values = messageCaptor.getAllValues(); |
| 133 | |
| 134 | for (int i = 0; i < numFailedToBuildTestCases - 1; i++) { |
| 135 | String message = values.get(i); |
| 136 | assertThat(message).contains("//foo/bar:baz"); |
| 137 | assertThat(message).contains(BlazeTestStatus.FAILED_TO_BUILD.toString().replace('_', ' ')); |
| 138 | } |
| 139 | |
| 140 | String last = values.get(numFailedToBuildTestCases - 1); |
| 141 | assertThat(last).contains("Executed 0 out of 6 tests"); |
| 142 | assertThat(last).contains(numFailedToBuildTestCases + " fail to build"); |
| 143 | } |
| 144 | |
| 145 | @Test |
Googler | ba6fdb9 | 2018-12-08 06:29:58 -0800 | [diff] [blame] | 146 | public void testCaseOption_allFail() throws Exception { |
jcater | d990df5 | 2020-04-07 04:38:15 -0700 | [diff] [blame] | 147 | testSummaryFormat = ExecutionOptions.TestSummaryFormat.TESTCASE; |
Googler | ba6fdb9 | 2018-12-08 06:29:58 -0800 | [diff] [blame] | 148 | numFailedTestCases = 10; |
ulfjack | 7c20af3 | 2020-01-15 07:59:02 -0800 | [diff] [blame] | 149 | numUnknownTestCases = 0; |
Googler | ba6fdb9 | 2018-12-08 06:29:58 -0800 | [diff] [blame] | 150 | numTotalTestCases = 10; |
| 151 | targetStatus = BlazeTestStatus.FAILED; |
| 152 | |
| 153 | printTestCaseSummary(); |
| 154 | |
| 155 | String printed = getPrintedMessage(); |
| 156 | assertThat(printed).contains("0 passing"); |
| 157 | assertThat(printed).contains(error("10 failing")); |
| 158 | assertThat(printed).contains("out of 10 test cases"); |
ulfjack | 7c20af3 | 2020-01-15 07:59:02 -0800 | [diff] [blame] | 159 | assertThat(printed).doesNotContain(SOME_TARGETS_ARE_MISSING_TEST_CASES_DISCLAIMER); |
Googler | ba6fdb9 | 2018-12-08 06:29:58 -0800 | [diff] [blame] | 160 | assertThat(printed).doesNotContain(AnsiTerminalPrinter.Mode.INFO.toString()); |
| 161 | } |
| 162 | |
| 163 | @Test |
| 164 | public void detailedOption_allPass() throws Exception { |
jcater | d990df5 | 2020-04-07 04:38:15 -0700 | [diff] [blame] | 165 | testSummaryFormat = ExecutionOptions.TestSummaryFormat.DETAILED; |
Googler | ba6fdb9 | 2018-12-08 06:29:58 -0800 | [diff] [blame] | 166 | numFailedTestCases = 0; |
ulfjack | 7c20af3 | 2020-01-15 07:59:02 -0800 | [diff] [blame] | 167 | numUnknownTestCases = 0; |
Googler | ba6fdb9 | 2018-12-08 06:29:58 -0800 | [diff] [blame] | 168 | numTotalTestCases = 10; |
| 169 | targetStatus = BlazeTestStatus.PASSED; |
| 170 | |
| 171 | printTestCaseSummary(); |
| 172 | |
| 173 | String printed = getPrintedMessage(); |
| 174 | assertThat(printed).contains(info("10 passing")); |
| 175 | assertThat(printed).contains("0 failing"); |
| 176 | assertThat(printed).contains("out of 10 test cases"); |
ulfjack | 7c20af3 | 2020-01-15 07:59:02 -0800 | [diff] [blame] | 177 | assertThat(printed).doesNotContain(SOME_TARGETS_ARE_MISSING_TEST_CASES_DISCLAIMER); |
Googler | ba6fdb9 | 2018-12-08 06:29:58 -0800 | [diff] [blame] | 178 | assertThat(printed).doesNotContain(AnsiTerminalPrinter.Mode.ERROR.toString()); |
| 179 | } |
| 180 | |
| 181 | @Test |
| 182 | public void detailedOption_allPassButTargetFails() throws Exception { |
jcater | d990df5 | 2020-04-07 04:38:15 -0700 | [diff] [blame] | 183 | testSummaryFormat = ExecutionOptions.TestSummaryFormat.DETAILED; |
Googler | ba6fdb9 | 2018-12-08 06:29:58 -0800 | [diff] [blame] | 184 | numFailedTestCases = 0; |
ulfjack | 7c20af3 | 2020-01-15 07:59:02 -0800 | [diff] [blame] | 185 | numUnknownTestCases = 10; |
Googler | ba6fdb9 | 2018-12-08 06:29:58 -0800 | [diff] [blame] | 186 | numTotalTestCases = 10; |
| 187 | targetStatus = BlazeTestStatus.FAILED; |
| 188 | |
| 189 | printTestCaseSummary(); |
| 190 | |
| 191 | String printed = getPrintedMessage(); |
ulfjack | 7c20af3 | 2020-01-15 07:59:02 -0800 | [diff] [blame] | 192 | assertThat(printed).contains("0 passing"); |
Googler | ba6fdb9 | 2018-12-08 06:29:58 -0800 | [diff] [blame] | 193 | assertThat(printed).contains("0 failing"); |
| 194 | assertThat(printed).contains("out of 10 test cases"); |
ulfjack | 7c20af3 | 2020-01-15 07:59:02 -0800 | [diff] [blame] | 195 | assertThat(printed).contains(SOME_TARGETS_ARE_MISSING_TEST_CASES_DISCLAIMER); |
Googler | ba6fdb9 | 2018-12-08 06:29:58 -0800 | [diff] [blame] | 196 | assertThat(printed).doesNotContain(AnsiTerminalPrinter.Mode.ERROR.toString()); |
| 197 | } |
| 198 | |
| 199 | @Test |
| 200 | public void detailedOption_someFail() throws Exception { |
jcater | d990df5 | 2020-04-07 04:38:15 -0700 | [diff] [blame] | 201 | testSummaryFormat = ExecutionOptions.TestSummaryFormat.DETAILED; |
Googler | ba6fdb9 | 2018-12-08 06:29:58 -0800 | [diff] [blame] | 202 | numFailedTestCases = 2; |
ulfjack | 7c20af3 | 2020-01-15 07:59:02 -0800 | [diff] [blame] | 203 | numUnknownTestCases = 0; |
Googler | ba6fdb9 | 2018-12-08 06:29:58 -0800 | [diff] [blame] | 204 | numTotalTestCases = 10; |
| 205 | targetStatus = BlazeTestStatus.FAILED; |
| 206 | |
| 207 | printTestCaseSummary(); |
| 208 | |
| 209 | String printed = getPrintedMessage(); |
| 210 | assertThat(printed).contains(info("8 passing")); |
| 211 | assertThat(printed).contains(error("2 failing")); |
| 212 | assertThat(printed).contains("out of 10 test cases"); |
ulfjack | 7c20af3 | 2020-01-15 07:59:02 -0800 | [diff] [blame] | 213 | assertThat(printed).doesNotContain(SOME_TARGETS_ARE_MISSING_TEST_CASES_DISCLAIMER); |
Googler | ba6fdb9 | 2018-12-08 06:29:58 -0800 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | @Test |
| 217 | public void detailedOption_allFail() throws Exception { |
jcater | d990df5 | 2020-04-07 04:38:15 -0700 | [diff] [blame] | 218 | testSummaryFormat = ExecutionOptions.TestSummaryFormat.DETAILED; |
Googler | ba6fdb9 | 2018-12-08 06:29:58 -0800 | [diff] [blame] | 219 | numFailedTestCases = 10; |
ulfjack | 7c20af3 | 2020-01-15 07:59:02 -0800 | [diff] [blame] | 220 | numUnknownTestCases = 0; |
Googler | ba6fdb9 | 2018-12-08 06:29:58 -0800 | [diff] [blame] | 221 | numTotalTestCases = 10; |
| 222 | targetStatus = BlazeTestStatus.FAILED; |
| 223 | |
| 224 | printTestCaseSummary(); |
| 225 | |
| 226 | String printed = getPrintedMessage(); |
| 227 | assertThat(printed).contains("0 passing"); |
| 228 | assertThat(printed).contains(error("10 failing")); |
| 229 | assertThat(printed).contains("out of 10 test cases"); |
ulfjack | 7c20af3 | 2020-01-15 07:59:02 -0800 | [diff] [blame] | 230 | assertThat(printed).doesNotContain(SOME_TARGETS_ARE_MISSING_TEST_CASES_DISCLAIMER); |
Googler | ba6fdb9 | 2018-12-08 06:29:58 -0800 | [diff] [blame] | 231 | assertThat(printed).doesNotContain(AnsiTerminalPrinter.Mode.INFO.toString()); |
| 232 | } |
| 233 | |
| 234 | @Test |
| 235 | public void shortOption_noSummaryPrinted() throws Exception { |
jcater | d990df5 | 2020-04-07 04:38:15 -0700 | [diff] [blame] | 236 | testSummaryFormat = ExecutionOptions.TestSummaryFormat.SHORT; |
Googler | ba6fdb9 | 2018-12-08 06:29:58 -0800 | [diff] [blame] | 237 | numFailedTestCases = 2; |
ulfjack | 7c20af3 | 2020-01-15 07:59:02 -0800 | [diff] [blame] | 238 | numUnknownTestCases = 0; |
Googler | ba6fdb9 | 2018-12-08 06:29:58 -0800 | [diff] [blame] | 239 | numTotalTestCases = 10; |
| 240 | targetStatus = BlazeTestStatus.FAILED; |
| 241 | |
| 242 | printTestCaseSummary(); |
| 243 | |
| 244 | verifyNoSummaryPrinted(); |
| 245 | } |
| 246 | |
| 247 | @Test |
| 248 | public void terseOption_noSummaryPrinted() throws Exception { |
jcater | d990df5 | 2020-04-07 04:38:15 -0700 | [diff] [blame] | 249 | testSummaryFormat = ExecutionOptions.TestSummaryFormat.TERSE; |
Googler | ba6fdb9 | 2018-12-08 06:29:58 -0800 | [diff] [blame] | 250 | numFailedTestCases = 2; |
ulfjack | 7c20af3 | 2020-01-15 07:59:02 -0800 | [diff] [blame] | 251 | numUnknownTestCases = 0; |
Googler | ba6fdb9 | 2018-12-08 06:29:58 -0800 | [diff] [blame] | 252 | numTotalTestCases = 10; |
| 253 | targetStatus = BlazeTestStatus.FAILED; |
| 254 | |
| 255 | printTestCaseSummary(); |
| 256 | |
| 257 | verifyNoSummaryPrinted(); |
| 258 | } |
| 259 | |
| 260 | @Test |
| 261 | public void noneOption_noSummaryPrinted() throws Exception { |
jcater | d990df5 | 2020-04-07 04:38:15 -0700 | [diff] [blame] | 262 | testSummaryFormat = ExecutionOptions.TestSummaryFormat.NONE; |
Googler | ba6fdb9 | 2018-12-08 06:29:58 -0800 | [diff] [blame] | 263 | numFailedTestCases = 2; |
ulfjack | 7c20af3 | 2020-01-15 07:59:02 -0800 | [diff] [blame] | 264 | numUnknownTestCases = 0; |
Googler | ba6fdb9 | 2018-12-08 06:29:58 -0800 | [diff] [blame] | 265 | numTotalTestCases = 10; |
| 266 | targetStatus = BlazeTestStatus.FAILED; |
| 267 | |
| 268 | printTestCaseSummary(); |
| 269 | |
| 270 | verifyNoSummaryPrinted(); |
| 271 | } |
| 272 | |
ichern | 8ec182a | 2020-01-08 05:29:11 -0800 | [diff] [blame] | 273 | private void printFailedToBuildSummaries() throws LabelSyntaxException { |
| 274 | ExecutionOptions executionOptions = ExecutionOptions.DEFAULTS; |
| 275 | executionOptions.testSummary = testSummaryFormat; |
| 276 | when(optionsParsingResult.getOptions(ExecutionOptions.class)).thenReturn(executionOptions); |
| 277 | TestSummaryOptions testSummaryOptions = new TestSummaryOptions(); |
| 278 | testSummaryOptions.verboseSummary = true; |
| 279 | when(optionsParsingResult.getOptions(TestSummaryOptions.class)).thenReturn(testSummaryOptions); |
| 280 | |
| 281 | ImmutableSortedSet.Builder<TestSummary> builder = |
| 282 | ImmutableSortedSet.orderedBy(Comparator.comparing(o -> o.getLabel().getName())); |
| 283 | for (int i = 0; i < TerminalTestResultNotifier.NUM_FAILED_TO_BUILD + 1; i++) { |
| 284 | TestSummary testSummary = mock(TestSummary.class); |
| 285 | when(testSummary.getTotalTestCases()).thenReturn(0); |
| 286 | |
| 287 | Label labelA = Label.parseAbsolute("//foo/bar:baz" + i, ImmutableMap.of()); |
| 288 | when(testSummary.getFailedTestCases()).thenReturn(ImmutableList.of()); |
| 289 | when(testSummary.getStatus()).thenReturn(BlazeTestStatus.FAILED_TO_BUILD); |
| 290 | when(testSummary.getLabel()).thenReturn(labelA); |
| 291 | |
| 292 | builder.add(testSummary); |
| 293 | } |
| 294 | |
| 295 | TerminalTestResultNotifier terminalTestResultNotifier = |
| 296 | new TerminalTestResultNotifier( |
| 297 | ansiTerminalPrinter, Path::getPathString, optionsParsingResult); |
| 298 | terminalTestResultNotifier.notify(builder.build(), 0); |
| 299 | } |
| 300 | |
Googler | ba6fdb9 | 2018-12-08 06:29:58 -0800 | [diff] [blame] | 301 | private void printTestCaseSummary() throws LabelSyntaxException { |
Eran Shalom | f1db75c | 2018-08-27 07:09:19 -0700 | [diff] [blame] | 302 | ExecutionOptions executionOptions = ExecutionOptions.DEFAULTS; |
Googler | ba6fdb9 | 2018-12-08 06:29:58 -0800 | [diff] [blame] | 303 | executionOptions.testSummary = testSummaryFormat; |
Eran Shalom | f1db75c | 2018-08-27 07:09:19 -0700 | [diff] [blame] | 304 | when(optionsParsingResult.getOptions(ExecutionOptions.class)).thenReturn(executionOptions); |
Eran Shalom | f1db75c | 2018-08-27 07:09:19 -0700 | [diff] [blame] | 305 | TestSummaryOptions testSummaryOptions = new TestSummaryOptions(); |
| 306 | testSummaryOptions.verboseSummary = true; |
| 307 | when(optionsParsingResult.getOptions(TestSummaryOptions.class)).thenReturn(testSummaryOptions); |
Eran Shalom | f1db75c | 2018-08-27 07:09:19 -0700 | [diff] [blame] | 308 | |
Googler | ba6fdb9 | 2018-12-08 06:29:58 -0800 | [diff] [blame] | 309 | TestSummary testSummary = mock(TestSummary.class); |
| 310 | when(testSummary.getTotalTestCases()).thenReturn(numTotalTestCases); |
ulfjack | 7c20af3 | 2020-01-15 07:59:02 -0800 | [diff] [blame] | 311 | when(testSummary.getUnkownTestCases()).thenReturn(numUnknownTestCases); |
Eran Shalom | f1db75c | 2018-08-27 07:09:19 -0700 | [diff] [blame] | 312 | TestCase failedTestCase = TestCase.newBuilder().setStatus(Status.FAILED).build(); |
Googler | ba6fdb9 | 2018-12-08 06:29:58 -0800 | [diff] [blame] | 313 | List<TestCase> failedTestCases = Collections.nCopies(numFailedTestCases, failedTestCase); |
Eran Shalom | f1db75c | 2018-08-27 07:09:19 -0700 | [diff] [blame] | 314 | |
| 315 | Label labelA = Label.parseAbsolute("//foo/bar:baz", ImmutableMap.of()); |
Googler | ba6fdb9 | 2018-12-08 06:29:58 -0800 | [diff] [blame] | 316 | when(testSummary.getFailedTestCases()).thenReturn(failedTestCases); |
| 317 | when(testSummary.getStatus()).thenReturn(targetStatus); |
Eran Shalom | f1db75c | 2018-08-27 07:09:19 -0700 | [diff] [blame] | 318 | when(testSummary.getLabel()).thenReturn(labelA); |
| 319 | |
Googler | ba6fdb9 | 2018-12-08 06:29:58 -0800 | [diff] [blame] | 320 | TerminalTestResultNotifier terminalTestResultNotifier = |
| 321 | new TerminalTestResultNotifier( |
| 322 | ansiTerminalPrinter, Path::getPathString, optionsParsingResult); |
| 323 | terminalTestResultNotifier.notify(ImmutableSet.of(testSummary), 1); |
Eran Shalom | f1db75c | 2018-08-27 07:09:19 -0700 | [diff] [blame] | 324 | } |
| 325 | |
Googler | ba6fdb9 | 2018-12-08 06:29:58 -0800 | [diff] [blame] | 326 | private String getPrintedMessage() { |
| 327 | ArgumentCaptor<String> messageCaptor = ArgumentCaptor.forClass(String.class); |
| 328 | verify(ansiTerminalPrinter).printLn(messageCaptor.capture()); |
| 329 | return messageCaptor.getValue(); |
Eran Shalom | f1db75c | 2018-08-27 07:09:19 -0700 | [diff] [blame] | 330 | } |
| 331 | |
Googler | ba6fdb9 | 2018-12-08 06:29:58 -0800 | [diff] [blame] | 332 | private void verifyNoSummaryPrinted() { |
| 333 | verify(ansiTerminalPrinter, never()).printLn(any()); |
Eran Shalom | f1db75c | 2018-08-27 07:09:19 -0700 | [diff] [blame] | 334 | } |
| 335 | |
Googler | ba6fdb9 | 2018-12-08 06:29:58 -0800 | [diff] [blame] | 336 | private static String info(String message) { |
| 337 | return AnsiTerminalPrinter.Mode.INFO + message + AnsiTerminalPrinter.Mode.DEFAULT; |
Eran Shalom | f1db75c | 2018-08-27 07:09:19 -0700 | [diff] [blame] | 338 | } |
| 339 | |
Googler | ba6fdb9 | 2018-12-08 06:29:58 -0800 | [diff] [blame] | 340 | private static String error(String message) { |
| 341 | return AnsiTerminalPrinter.Mode.ERROR + message + AnsiTerminalPrinter.Mode.DEFAULT; |
Eran Shalom | f1db75c | 2018-08-27 07:09:19 -0700 | [diff] [blame] | 342 | } |
| 343 | } |