|
| 1 | +# Copyright 2024 the V8 project authors. All rights reserved. |
| 2 | +# Use of this source code is governed by a BSD-style license that can be |
| 3 | +# found in the LICENSE file. |
| 4 | + |
| 5 | +import mocks |
| 6 | +import textwrap |
| 7 | +import unittest |
| 8 | + |
| 9 | +from pyfakefs import fake_filesystem_unittest |
| 10 | +from v8_importer import V8TestImporter, GitFileStatus |
| 11 | +from v8configs import to_object |
| 12 | + |
| 13 | +fake_host = to_object({ |
| 14 | + 'project_config': { |
| 15 | + 'project_root': |
| 16 | + '.', |
| 17 | + 'paths_to_sync': [{ |
| 18 | + "source": "test/staging", |
| 19 | + "destination": "test/test262/local-tests/test/staging" |
| 20 | + }] |
| 21 | + }, |
| 22 | +}) |
| 23 | +V8_REVISION = 'abcdef123456' |
| 24 | +TEST262_REVISION = '123456abcdef' |
| 25 | + |
| 26 | +class Test_TestV8Importer(fake_filesystem_unittest.TestCase): |
| 27 | + |
| 28 | + def test_phases(self): |
| 29 | + importer = V8TestImporter('ALL', fake_host) |
| 30 | + self.assertTrue(importer.run_prebuild_phase()) |
| 31 | + self.assertTrue(importer.run_build_phase()) |
| 32 | + self.assertTrue(importer.run_postbuild_phase()) |
| 33 | + self.assertTrue(importer.run_upload_phase()) |
| 34 | + |
| 35 | + importer = V8TestImporter('PREBUILD', fake_host) |
| 36 | + self.assertTrue(importer.run_prebuild_phase()) |
| 37 | + self.assertFalse(importer.run_build_phase()) |
| 38 | + self.assertFalse(importer.run_postbuild_phase()) |
| 39 | + self.assertFalse(importer.run_upload_phase()) |
| 40 | + |
| 41 | + importer = V8TestImporter('POSTBUILD', fake_host) |
| 42 | + self.assertFalse(importer.run_prebuild_phase()) |
| 43 | + self.assertFalse(importer.run_build_phase()) |
| 44 | + self.assertTrue(importer.run_postbuild_phase()) |
| 45 | + self.assertFalse(importer.run_upload_phase()) |
| 46 | + |
| 47 | + importer = V8TestImporter('UPLOAD', fake_host) |
| 48 | + self.assertFalse(importer.run_prebuild_phase()) |
| 49 | + self.assertFalse(importer.run_build_phase()) |
| 50 | + self.assertFalse(importer.run_postbuild_phase()) |
| 51 | + self.assertTrue(importer.run_upload_phase()) |
| 52 | + |
| 53 | + def test_sync_folders(self): |
| 54 | + self.setUpPyfakefs(allow_root_user=True) |
| 55 | + |
| 56 | + destination = 'test/test262/local-tests/test/staging' |
| 57 | + self.fs.create_file(f'{destination}/test1.js') |
| 58 | + self.fs.create_file(f'{destination}/features.txt') |
| 59 | + self.fs.create_file(f'{destination}/f1/test1.js') |
| 60 | + self.fs.create_file(f'{destination}/f1/test2.js') |
| 61 | + |
| 62 | + def get_git_file_status(*args): |
| 63 | + path = str(args[2]) |
| 64 | + self.assertFalse(path.endswith('features.txt')) |
| 65 | + return GitFileStatus.ADDED if path.endswith( |
| 66 | + 'test1.js') else GitFileStatus.UNKNOWN |
| 67 | + |
| 68 | + importer = V8TestImporter('X', fake_host) |
| 69 | + importer.local_test262 = to_object({ |
| 70 | + 'path': '.', |
| 71 | + }) |
| 72 | + importer.get_git_file_status = get_git_file_status |
| 73 | + |
| 74 | + importer.sync_folders(V8_REVISION, TEST262_REVISION) |
| 75 | + |
| 76 | + self.assertFalse(self.fs.exists(f'{destination}/test1.js')) |
| 77 | + self.assertTrue(self.fs.exists(f'{destination}/features.txt')) |
| 78 | + self.assertFalse(self.fs.exists(f'{destination}/f1/test1.js')) |
| 79 | + self.assertTrue(self.fs.exists(f'{destination}/f1/test2.js')) |
| 80 | + |
| 81 | + def test_remove_deleted_tests(self): |
| 82 | + self.setUpPyfakefs(allow_root_user=True) |
| 83 | + self.fs.create_file( |
| 84 | + 'test/test262/test262.status', |
| 85 | + contents=textwrap.dedent("""\ |
| 86 | + n'importe quoi |
| 87 | + ... |
| 88 | + 'folder1/sometest1': [FAIL], |
| 89 | + 'deleted_testname': [FAIL], |
| 90 | + 'folder2/sometest1': [FAIL], |
| 91 | + 'folder2/sometest2': [FAIL], |
| 92 | + ... |
| 93 | + """)) |
| 94 | + |
| 95 | + importer = V8TestImporter('X', fake_host) |
| 96 | + importer.test262_git = to_object({ |
| 97 | + 'run': lambda *args: 'test/deleted_testname.js\n', |
| 98 | + }) |
| 99 | + |
| 100 | + tests = importer.remove_deleted_tests(V8_REVISION, TEST262_REVISION) |
| 101 | + |
| 102 | + self.assertEquals(textwrap.dedent("""\ |
| 103 | + n'importe quoi |
| 104 | + ... |
| 105 | + 'folder1/sometest1': [FAIL], |
| 106 | + 'folder2/sometest1': [FAIL], |
| 107 | + 'folder2/sometest2': [FAIL], |
| 108 | + ... |
| 109 | + """), ''.join(tests)) |
| 110 | + |
| 111 | + def test_failed_tests_to_status_lines(self): |
| 112 | + importer = V8TestImporter('X', fake_host) |
| 113 | + result = importer.failed_tests_to_status_lines(['test1', 'test2']) |
| 114 | + self.assertSequenceEqual([" 'test1': [FAIL],\n", " 'test2': [FAIL],\n"], |
| 115 | + result) |
| 116 | + |
| 117 | + def test_rewrite_status_file_content(self): |
| 118 | + # Below \n is used inside the text block to avoid a trailing whitespace |
| 119 | + # check |
| 120 | + updated_status = textwrap.dedent("""\ |
| 121 | + some_testname |
| 122 | + some random line |
| 123 | + some other testname\n |
| 124 | + ] |
| 125 | + """) |
| 126 | + updated_status = updated_status.splitlines(keepends=True) |
| 127 | + added_lines = [' new test 1\n', ' new test 2\n'] |
| 128 | + |
| 129 | + importer = V8TestImporter('X', fake_host) |
| 130 | + result = importer.rewrite_status_file_content(updated_status, added_lines, |
| 131 | + V8_REVISION, TEST262_REVISION) |
| 132 | + |
| 133 | + self.assertEquals(textwrap.dedent("""\ |
| 134 | + some_testname |
| 135 | + some random line |
| 136 | + some other testname\n |
| 137 | + #### |
| 138 | + # Import test262@123456ab |
| 139 | + # https://chromium.googlesource.com/external/github.com/tc39/test262/+log/abcdef12..123456ab |
| 140 | + [ALWAYS, { |
| 141 | + new test 1 |
| 142 | + new test 2 |
| 143 | + }], |
| 144 | + # End import test262@123456ab |
| 145 | + ####\n |
| 146 | + ] |
| 147 | + """), ''.join(result)) |
| 148 | + |
| 149 | + def test_get_updated_tests(self): |
| 150 | + importer = V8TestImporter('X', fake_host) |
| 151 | + importer.test262_git = to_object({ |
| 152 | + 'run': lambda *args: textwrap.dedent("""\ |
| 153 | + test/should_not_match.js extra garbage |
| 154 | + test/should_not_match2.js |
| 155 | + test/some_testname.js |
| 156 | + practically garbage |
| 157 | + """), |
| 158 | + }) |
| 159 | + |
| 160 | + tests = importer.get_updated_tests('a', 'b') |
| 161 | + self.assertEquals(['some_testname'], tests) |
| 162 | + |
| 163 | + |
| 164 | +if __name__ == '__main__': |
| 165 | + unittest.main() |
0 commit comments