| OLD | NEW |
| 1 #!/bin/env python | 1 #!/bin/env python |
| 2 # Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Unittests to make sure we generate and update the expected-*.txt files | 6 """Unittests to make sure we generate and update the expected-*.txt files |
| 7 properly after running layout tests.""" | 7 properly after running layout tests.""" |
| 8 | 8 |
| 9 import os | 9 import os |
| 10 import shutil | 10 import shutil |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 exist or the user explicitly asks to make new files.""" | 41 exist or the user explicitly asks to make new files.""" |
| 42 failures = self.GetTestFailures() | 42 failures = self.GetTestFailures() |
| 43 | 43 |
| 44 # Test to make sure we generate baseline files if the file doesn't exist. | 44 # Test to make sure we generate baseline files if the file doesn't exist. |
| 45 os.remove(os.path.join(self.GetTmpDir(), 'expected-passing.txt')) | 45 os.remove(os.path.join(self.GetTmpDir(), 'expected-passing.txt')) |
| 46 os.remove(os.path.join(self.GetTmpDir(), 'expected-failures.txt')) | 46 os.remove(os.path.join(self.GetTmpDir(), 'expected-failures.txt')) |
| 47 os.remove(os.path.join(self.GetTmpDir(), 'expected-crashes.txt')) | 47 os.remove(os.path.join(self.GetTmpDir(), 'expected-crashes.txt')) |
| 48 | 48 |
| 49 # Test force generation of new baseline files with a new failure and one | 49 # Test force generation of new baseline files with a new failure and one |
| 50 # less passing. | 50 # less passing. |
| 51 pass_file = os.path.join(path_utils.LayoutDataDir(), 'fast', 'pass1.html') | 51 pass_file = os.path.join(path_utils.LayoutTestsDir(), 'fast', 'pass1.html') |
| 52 failures[pass_file] = [test_failures.FailureTextMismatch(None)] | 52 failures[pass_file] = [test_failures.FailureTextMismatch(None)] |
| 53 | 53 |
| 54 cf = compare_failures.CompareFailures(self.GetTestFiles(), failures, | 54 cf = compare_failures.CompareFailures(self.GetTestFiles(), failures, |
| 55 set(), set(), | 55 set(), set(), |
| 56 self.GetTmpDir(), False) | 56 self.GetTmpDir(), False) |
| 57 cf.UpdateFailuresOnDisk() | 57 cf.UpdateFailuresOnDisk() |
| 58 self.CheckOutputWithExpectedFiles('expected-passing-new-baseline.txt', | 58 self.CheckOutputWithExpectedFiles('expected-passing-new-baseline.txt', |
| 59 'expected-failures-added.txt', | 59 'expected-failures-added.txt', |
| 60 'expected-crashes.txt') | 60 'expected-crashes.txt') |
| 61 | 61 |
| 62 def testPassingToFailure(self): | 62 def testPassingToFailure(self): |
| 63 """When there's a new failure, we don't add it to the baseline.""" | 63 """When there's a new failure, we don't add it to the baseline.""" |
| 64 failures = self.GetTestFailures() | 64 failures = self.GetTestFailures() |
| 65 | 65 |
| 66 # Test case where we don't update new baseline. We have a new failure, | 66 # Test case where we don't update new baseline. We have a new failure, |
| 67 # but it shouldn't be added to the expected-failures.txt file. | 67 # but it shouldn't be added to the expected-failures.txt file. |
| 68 pass_file = os.path.join(path_utils.LayoutDataDir(), 'fast', 'pass1.html') | 68 pass_file = os.path.join(path_utils.LayoutTestsDir(), 'fast', 'pass1.html') |
| 69 failures[pass_file] = [test_failures.FailureTextMismatch(None)] | 69 failures[pass_file] = [test_failures.FailureTextMismatch(None)] |
| 70 self.CheckNoChanges(failures) | 70 self.CheckNoChanges(failures) |
| 71 | 71 |
| 72 # Same thing as before: pass -> crash | 72 # Same thing as before: pass -> crash |
| 73 failures[pass_file] = [test_failures.FailureCrash()] | 73 failures[pass_file] = [test_failures.FailureCrash()] |
| 74 self.CheckNoChanges(failures) | 74 self.CheckNoChanges(failures) |
| 75 | 75 |
| 76 def testFailureToCrash(self): | 76 def testFailureToCrash(self): |
| 77 """When there's a new crash, we don't add it to the baseline or remove it | 77 """When there's a new crash, we don't add it to the baseline or remove it |
| 78 from the failure list.""" | 78 from the failure list.""" |
| 79 failures = self.GetTestFailures() | 79 failures = self.GetTestFailures() |
| 80 | 80 |
| 81 # Test case where we don't update new baseline. A failure moving to a | 81 # Test case where we don't update new baseline. A failure moving to a |
| 82 # crash shouldn't be added to the expected-crashes.txt file. | 82 # crash shouldn't be added to the expected-crashes.txt file. |
| 83 failure_file = os.path.join(path_utils.LayoutDataDir(), | 83 failure_file = os.path.join(path_utils.LayoutTestsDir(), |
| 84 'fast', 'foo', 'fail1.html') | 84 'fast', 'foo', 'fail1.html') |
| 85 failures[failure_file] = [test_failures.FailureCrash()] | 85 failures[failure_file] = [test_failures.FailureCrash()] |
| 86 self.CheckNoChanges(failures) | 86 self.CheckNoChanges(failures) |
| 87 | 87 |
| 88 def testFailureToPassing(self): | 88 def testFailureToPassing(self): |
| 89 """This is better than before, so we should update the failure list.""" | 89 """This is better than before, so we should update the failure list.""" |
| 90 failures = self.GetTestFailures() | 90 failures = self.GetTestFailures() |
| 91 | 91 |
| 92 # Remove one of the failing test cases from the failures dictionary. This | 92 # Remove one of the failing test cases from the failures dictionary. This |
| 93 # makes failure_file considered to be passing. | 93 # makes failure_file considered to be passing. |
| 94 failure_file = os.path.join(path_utils.LayoutDataDir(), | 94 failure_file = os.path.join(path_utils.LayoutTestsDir(), |
| 95 'fast', 'bar', 'fail2.html') | 95 'fast', 'bar', 'fail2.html') |
| 96 del failures[failure_file] | 96 del failures[failure_file] |
| 97 | 97 |
| 98 cf = compare_failures.CompareFailures(self.GetTestFiles(), failures, | 98 cf = compare_failures.CompareFailures(self.GetTestFiles(), failures, |
| 99 set(), set(), | 99 set(), set(), |
| 100 self.GetTmpDir(), False) | 100 self.GetTmpDir(), False) |
| 101 cf.UpdateFailuresOnDisk() | 101 cf.UpdateFailuresOnDisk() |
| 102 self.CheckOutputWithExpectedFiles('expected-passing-new-passing2.txt', | 102 self.CheckOutputWithExpectedFiles('expected-passing-new-passing2.txt', |
| 103 'expected-failures-new-passing.txt', | 103 'expected-failures-new-passing.txt', |
| 104 'expected-crashes.txt') | 104 'expected-crashes.txt') |
| 105 | 105 |
| 106 def testCrashToPassing(self): | 106 def testCrashToPassing(self): |
| 107 """This is better than before, so we update the crashes file.""" | 107 """This is better than before, so we update the crashes file.""" |
| 108 failures = self.GetTestFailures() | 108 failures = self.GetTestFailures() |
| 109 | 109 |
| 110 crash_file = os.path.join(path_utils.LayoutDataDir(), | 110 crash_file = os.path.join(path_utils.LayoutTestsDir(), |
| 111 'fast', 'bar', 'betz', 'crash3.html') | 111 'fast', 'bar', 'betz', 'crash3.html') |
| 112 del failures[crash_file] | 112 del failures[crash_file] |
| 113 cf = compare_failures.CompareFailures(self.GetTestFiles(), failures, | 113 cf = compare_failures.CompareFailures(self.GetTestFiles(), failures, |
| 114 set(), set(), | 114 set(), set(), |
| 115 self.GetTmpDir(), False) | 115 self.GetTmpDir(), False) |
| 116 cf.UpdateFailuresOnDisk() | 116 cf.UpdateFailuresOnDisk() |
| 117 self.CheckOutputWithExpectedFiles('expected-passing-new-passing.txt', | 117 self.CheckOutputWithExpectedFiles('expected-passing-new-passing.txt', |
| 118 'expected-failures.txt', | 118 'expected-failures.txt', |
| 119 'expected-crashes-new-passing.txt') | 119 'expected-crashes-new-passing.txt') |
| 120 | 120 |
| 121 def testCrashToFailure(self): | 121 def testCrashToFailure(self): |
| 122 """This is better than before, so we should update both lists.""" | 122 """This is better than before, so we should update both lists.""" |
| 123 failures = self.GetTestFailures() | 123 failures = self.GetTestFailures() |
| 124 | 124 |
| 125 crash_file = os.path.join(path_utils.LayoutDataDir(), | 125 crash_file = os.path.join(path_utils.LayoutTestsDir(), |
| 126 'fast', 'bar', 'betz', 'crash3.html') | 126 'fast', 'bar', 'betz', 'crash3.html') |
| 127 failures[crash_file] = [test_failures.FailureTextMismatch(None)] | 127 failures[crash_file] = [test_failures.FailureTextMismatch(None)] |
| 128 cf = compare_failures.CompareFailures(self.GetTestFiles(), failures, | 128 cf = compare_failures.CompareFailures(self.GetTestFiles(), failures, |
| 129 set(), set(), | 129 set(), set(), |
| 130 self.GetTmpDir(), False) | 130 self.GetTmpDir(), False) |
| 131 cf.UpdateFailuresOnDisk() | 131 cf.UpdateFailuresOnDisk() |
| 132 self.CheckOutputWithExpectedFiles('expected-passing.txt', | 132 self.CheckOutputWithExpectedFiles('expected-passing.txt', |
| 133 'expected-failures-new-crash.txt', | 133 'expected-failures-new-crash.txt', |
| 134 'expected-crashes-new-passing.txt') | 134 'expected-crashes-new-passing.txt') |
| 135 | 135 |
| 136 def testNewTestPass(self): | 136 def testNewTestPass(self): |
| 137 """After a merge, we need to update new passing tests properly.""" | 137 """After a merge, we need to update new passing tests properly.""" |
| 138 files = self.GetTestFiles() | 138 files = self.GetTestFiles() |
| 139 new_test_file = os.path.join(path_utils.LayoutDataDir(), "new-test.html") | 139 new_test_file = os.path.join(path_utils.LayoutTestsDir(), "new-test.html") |
| 140 files.add(new_test_file) | 140 files.add(new_test_file) |
| 141 failures = self.GetTestFailures() | 141 failures = self.GetTestFailures() |
| 142 | 142 |
| 143 # New test file passing | 143 # New test file passing |
| 144 cf = compare_failures.CompareFailures(files, failures, set(), set(), | 144 cf = compare_failures.CompareFailures(files, failures, set(), set(), |
| 145 self.GetTmpDir(), False) | 145 self.GetTmpDir(), False) |
| 146 cf.UpdateFailuresOnDisk() | 146 cf.UpdateFailuresOnDisk() |
| 147 self.CheckOutputWithExpectedFiles('expected-passing-new-test.txt', | 147 self.CheckOutputWithExpectedFiles('expected-passing-new-test.txt', |
| 148 'expected-failures.txt', | 148 'expected-failures.txt', |
| 149 'expected-crashes.txt') | 149 'expected-crashes.txt') |
| 150 | 150 |
| 151 def testNewTestFail(self): | 151 def testNewTestFail(self): |
| 152 """After a merge, we need to update new failing tests properly.""" | 152 """After a merge, we need to update new failing tests properly.""" |
| 153 files = self.GetTestFiles() | 153 files = self.GetTestFiles() |
| 154 new_test_file = os.path.join(path_utils.LayoutDataDir(), "new-test.html") | 154 new_test_file = os.path.join(path_utils.LayoutTestsDir(), "new-test.html") |
| 155 files.add(new_test_file) | 155 files.add(new_test_file) |
| 156 failures = self.GetTestFailures() | 156 failures = self.GetTestFailures() |
| 157 | 157 |
| 158 # New test file failing | 158 # New test file failing |
| 159 failures[new_test_file] = [test_failures.FailureTextMismatch(None)] | 159 failures[new_test_file] = [test_failures.FailureTextMismatch(None)] |
| 160 cf = compare_failures.CompareFailures(files, failures, set(), set(), | 160 cf = compare_failures.CompareFailures(files, failures, set(), set(), |
| 161 self.GetTmpDir(), False) | 161 self.GetTmpDir(), False) |
| 162 cf.UpdateFailuresOnDisk() | 162 cf.UpdateFailuresOnDisk() |
| 163 self.CheckOutputWithExpectedFiles('expected-passing.txt', | 163 self.CheckOutputWithExpectedFiles('expected-passing.txt', |
| 164 'expected-failures-new-test.txt', | 164 'expected-failures-new-test.txt', |
| 165 'expected-crashes.txt') | 165 'expected-crashes.txt') |
| 166 | 166 |
| 167 def testNewTestCrash(self): | 167 def testNewTestCrash(self): |
| 168 """After a merge, we need to update new crashing tests properly.""" | 168 """After a merge, we need to update new crashing tests properly.""" |
| 169 files = self.GetTestFiles() | 169 files = self.GetTestFiles() |
| 170 new_test_file = os.path.join(path_utils.LayoutDataDir(), "new-test.html") | 170 new_test_file = os.path.join(path_utils.LayoutTestsDir(), "new-test.html") |
| 171 files.add(new_test_file) | 171 files.add(new_test_file) |
| 172 failures = self.GetTestFailures() | 172 failures = self.GetTestFailures() |
| 173 | 173 |
| 174 # New test file crashing | 174 # New test file crashing |
| 175 failures[new_test_file] = [test_failures.FailureCrash()] | 175 failures[new_test_file] = [test_failures.FailureCrash()] |
| 176 cf = compare_failures.CompareFailures(files, failures, set(), set(), | 176 cf = compare_failures.CompareFailures(files, failures, set(), set(), |
| 177 self.GetTmpDir(), False) | 177 self.GetTmpDir(), False) |
| 178 cf.UpdateFailuresOnDisk() | 178 cf.UpdateFailuresOnDisk() |
| 179 self.CheckOutputWithExpectedFiles('expected-passing.txt', | 179 self.CheckOutputWithExpectedFiles('expected-passing.txt', |
| 180 'expected-failures.txt', | 180 'expected-failures.txt', |
| 181 'expected-crashes-new-test.txt') | 181 'expected-crashes-new-test.txt') |
| 182 | 182 |
| 183 def testHasNewFailures(self): | 183 def testHasNewFailures(self): |
| 184 files = self.GetTestFiles() | 184 files = self.GetTestFiles() |
| 185 failures = self.GetTestFailures() | 185 failures = self.GetTestFailures() |
| 186 | 186 |
| 187 # no changes, no new failures | 187 # no changes, no new failures |
| 188 cf = compare_failures.CompareFailures(files, failures, set(), set(), | 188 cf = compare_failures.CompareFailures(files, failures, set(), set(), |
| 189 self.GetTmpDir(), False) | 189 self.GetTmpDir(), False) |
| 190 self.failUnless(not cf.HasNewFailures()) | 190 self.failUnless(not cf.HasNewFailures()) |
| 191 | 191 |
| 192 # test goes from passing to failing | 192 # test goes from passing to failing |
| 193 pass_file = os.path.join(path_utils.LayoutDataDir(), 'fast', 'pass1.html') | 193 pass_file = os.path.join(path_utils.LayoutTestsDir(), 'fast', 'pass1.html') |
| 194 failures[pass_file] = [test_failures.FailureTextMismatch(None)] | 194 failures[pass_file] = [test_failures.FailureTextMismatch(None)] |
| 195 cf = compare_failures.CompareFailures(files, failures, set(), set(), | 195 cf = compare_failures.CompareFailures(files, failures, set(), set(), |
| 196 self.GetTmpDir(), False) | 196 self.GetTmpDir(), False) |
| 197 self.failUnless(cf.HasNewFailures()) | 197 self.failUnless(cf.HasNewFailures()) |
| 198 | 198 |
| 199 # Failing to passing | 199 # Failing to passing |
| 200 failures = self.GetTestFailures() | 200 failures = self.GetTestFailures() |
| 201 failure_file = os.path.join(path_utils.LayoutDataDir(), | 201 failure_file = os.path.join(path_utils.LayoutTestsDir(), |
| 202 'fast', 'bar', 'fail2.html') | 202 'fast', 'bar', 'fail2.html') |
| 203 del failures[failure_file] | 203 del failures[failure_file] |
| 204 cf = compare_failures.CompareFailures(files, failures, set(), set(), | 204 cf = compare_failures.CompareFailures(files, failures, set(), set(), |
| 205 self.GetTmpDir(), False) | 205 self.GetTmpDir(), False) |
| 206 self.failUnless(not cf.HasNewFailures()) | 206 self.failUnless(not cf.HasNewFailures()) |
| 207 | 207 |
| 208 # A new test that fails, this doesn't count as a new failure. | 208 # A new test that fails, this doesn't count as a new failure. |
| 209 new_test_file = os.path.join(path_utils.LayoutDataDir(), "new-test.html") | 209 new_test_file = os.path.join(path_utils.LayoutTestsDir(), "new-test.html") |
| 210 files.add(new_test_file) | 210 files.add(new_test_file) |
| 211 failures = self.GetTestFailures() | 211 failures = self.GetTestFailures() |
| 212 failures[new_test_file] = [test_failures.FailureCrash()] | 212 failures[new_test_file] = [test_failures.FailureCrash()] |
| 213 cf = compare_failures.CompareFailures(files, failures, set(), set(), | 213 cf = compare_failures.CompareFailures(files, failures, set(), set(), |
| 214 self.GetTmpDir(), False) | 214 self.GetTmpDir(), False) |
| 215 self.failUnless(not cf.HasNewFailures()) | 215 self.failUnless(not cf.HasNewFailures()) |
| 216 | 216 |
| 217 | 217 |
| 218 ########################################################################### | 218 ########################################################################### |
| 219 # Helper methods | 219 # Helper methods |
| (...skipping 23 matching lines...) Expand all Loading... |
| 243 | 243 |
| 244 def GetTestDataDir(self): | 244 def GetTestDataDir(self): |
| 245 return os.path.abspath('testdata') | 245 return os.path.abspath('testdata') |
| 246 | 246 |
| 247 def GetTmpDir(self): | 247 def GetTmpDir(self): |
| 248 return self._tempdir | 248 return self._tempdir |
| 249 | 249 |
| 250 def GetTestFiles(self): | 250 def GetTestFiles(self): |
| 251 """Get a set of files that includes the expected crashes and failures | 251 """Get a set of files that includes the expected crashes and failures |
| 252 along with two passing tests.""" | 252 along with two passing tests.""" |
| 253 layout_dir = path_utils.LayoutDataDir() | 253 layout_dir = path_utils.LayoutTestsDir() |
| 254 files = [ | 254 files = [ |
| 255 'fast\\pass1.html', | 255 'fast\\pass1.html', |
| 256 'fast\\foo\\pass2.html', | 256 'fast\\foo\\pass2.html', |
| 257 'fast\\foo\\crash1.html', | 257 'fast\\foo\\crash1.html', |
| 258 'fast\\bar\\crash2.html', | 258 'fast\\bar\\crash2.html', |
| 259 'fast\\bar\\betz\\crash3.html', | 259 'fast\\bar\\betz\\crash3.html', |
| 260 'fast\\foo\\fail1.html', | 260 'fast\\foo\\fail1.html', |
| 261 'fast\\bar\\fail2.html', | 261 'fast\\bar\\fail2.html', |
| 262 'fast\\bar\\betz\\fail3.html', | 262 'fast\\bar\\betz\\fail3.html', |
| 263 ] | 263 ] |
| 264 | 264 |
| 265 return set([os.path.join(layout_dir, f) for f in files]) | 265 return set([os.path.join(layout_dir, f) for f in files]) |
| 266 | 266 |
| 267 def GetTestFailures(self): | 267 def GetTestFailures(self): |
| 268 """Get a dictionary representing the crashes and failures in the | 268 """Get a dictionary representing the crashes and failures in the |
| 269 expected-*.txt files.""" | 269 expected-*.txt files.""" |
| 270 failures = {} | 270 failures = {} |
| 271 for filename in self.GetTestFiles(): | 271 for filename in self.GetTestFiles(): |
| 272 if filename.find('crash') != -1: | 272 if filename.find('crash') != -1: |
| 273 failures[filename] = [test_failures.FailureCrash()] | 273 failures[filename] = [test_failures.FailureCrash()] |
| 274 elif filename.find('fail') != -1: | 274 elif filename.find('fail') != -1: |
| 275 failures[filename] = [test_failures.FailureTextMismatch(None)] | 275 failures[filename] = [test_failures.FailureTextMismatch(None)] |
| 276 | 276 |
| 277 return failures | 277 return failures |
| 278 | 278 |
| 279 if '__main__' == __name__: | 279 if '__main__' == __name__: |
| 280 unittest.main() | 280 unittest.main() |
| 281 | 281 |
| OLD | NEW |