OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # Copyright 2017 the V8 project authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
5 | |
6 import os | |
7 import shutil | |
8 import subprocess | |
9 import sys | |
10 import tempfile | |
11 import unittest | |
12 | |
13 import update_node | |
14 | |
15 # Base paths. | |
16 BASE_DIR = os.path.dirname(os.path.abspath(__file__)) | |
17 TEST_DATA = os.path.join(BASE_DIR, 'testdata') | |
18 | |
19 # Expectations. | |
20 EXPECTED_GITIGNORE = """ | |
21 /testing/gtest/* | |
22 !/testing/gtest/include | |
23 /testing/gtest/include/* | |
24 !/testing/gtest/include/gtest | |
25 /testing/gtest/include/gtest/* | |
26 !/testing/gtest/include/gtest/gtest_prod.h | |
27 !/third_party/jinja2 | |
28 !/third_party/markupsafe | |
29 /unrelated | |
30 """ | |
31 | |
32 ADDED_FILES = [ | |
33 'v8_new', | |
34 'new/v8_new', | |
35 'baz/v8_new', | |
36 'testing/gtest/gtest_new', | |
37 'testing/gtest/new/gtest_new', | |
38 'testing/gtest/baz/gtest_new', | |
Michael Achenbach
2017/03/14 08:37:26
nit: The files from marupsafe and jinja2 could be
| |
39 ] | |
40 | |
41 REMOVED_FILES = [ | |
42 'delete_me', | |
43 'baz/delete_me', | |
44 'testing/gtest/delete_me', | |
45 'testing/gtest/baz/delete_me', | |
46 ] | |
47 | |
48 def gitify(path): | |
49 files = os.listdir(path) | |
50 subprocess.check_call(['git', 'init'], cwd=path) | |
51 subprocess.check_call(['git', 'add'] + files, cwd=path) | |
52 subprocess.check_call(['git', 'commit', '-m="Initial"'], cwd=path) | |
53 | |
54 | |
55 class TestUpdateNode(unittest.TestCase): | |
56 def setUp(self): | |
57 self.workdir = tempfile.mkdtemp(prefix='tmp_test_node_') | |
58 | |
59 def tearDown(self): | |
60 shutil.rmtree(self.workdir) | |
61 | |
62 def testUpdate(self): | |
63 v8_cwd = os.path.join(self.workdir, 'v8') | |
64 gtest_cwd = os.path.join(self.workdir, 'v8', 'testing', 'gtest') | |
65 node_cwd = os.path.join(self.workdir, 'node') | |
66 | |
67 # Set up V8 test fixture. | |
68 shutil.copytree(src=os.path.join(TEST_DATA, 'v8'), dst=v8_cwd) | |
69 gitify(v8_cwd) | |
70 for repository in update_node.SUB_REPOSITORIES: | |
71 gitify(os.path.join(v8_cwd, *repository)) | |
Yang
2017/03/14 08:26:27
They are gitified here :)
Michael Achenbach
2017/03/14 08:37:26
Ah right, then this nit:
Unused variable gtest_cwd
| |
72 | |
73 # Set up node test fixture (no git repo required). | |
74 shutil.copytree(src=os.path.join(TEST_DATA, 'node'), dst=node_cwd) | |
75 | |
76 # Run update script. | |
77 update_node.Main([v8_cwd, node_cwd]) | |
78 | |
79 # Check expectations. | |
80 with open(os.path.join(node_cwd, 'deps', 'v8', '.gitignore')) as f: | |
81 actual_gitignore = f.read() | |
82 self.assertEquals(EXPECTED_GITIGNORE.strip(), actual_gitignore.strip()) | |
83 for f in ADDED_FILES: | |
84 added_file = os.path.join(node_cwd, 'deps', 'v8', *f.split('/')) | |
85 self.assertTrue(os.path.exists(added_file)) | |
86 for f in REMOVED_FILES: | |
87 removed_file = os.path.join(node_cwd, 'deps', 'v8', *f.split('/')) | |
88 self.assertFalse(os.path.exists(removed_file)) | |
89 | |
90 if __name__ == "__main__": | |
91 unittest.main() | |
OLD | NEW |