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 | |
Franzi
2017/03/14 10:02:42
When are *test.py tests run? Only manually?
| |
14 | |
15 # Overwrite repositories to test only with gtest. | |
16 update_node.REPOSITORIES = [ [""], ["testing", "gtest"]] | |
17 | |
18 # Base paths. | |
19 BASE_DIR = os.path.dirname(os.path.abspath(__file__)) | |
20 TEST_DATA = os.path.join(BASE_DIR, 'testdata') | |
21 | |
22 # Expectations. | |
23 EXPECTED_GITIGNORE = """ | |
24 /testing/gtest/* | |
25 !/testing/gtest/include | |
26 /testing/gtest/include/* | |
27 !/testing/gtest/include/gtest | |
28 /testing/gtest/include/gtest/* | |
29 !/testing/gtest/include/gtest/gtest_prod.h | |
30 !/third_party/jinja2 | |
31 !/third_party/markupsafe | |
32 /unrelated | |
33 """ | |
34 | |
35 ADDED_FILES = [ | |
36 'v8_new', | |
37 'new/v8_new', | |
38 'baz/v8_new', | |
39 'testing/gtest/gtest_new', | |
40 'testing/gtest/new/gtest_new', | |
41 'testing/gtest/baz/gtest_new', | |
42 ] | |
43 | |
44 REMOVED_FILES = [ | |
45 'delete_me', | |
46 'baz/delete_me', | |
47 'testing/gtest/delete_me', | |
48 'testing/gtest/baz/delete_me', | |
49 ] | |
50 | |
51 def gitify(path): | |
52 files = os.listdir(path) | |
53 subprocess.check_call(['git', 'init'], cwd=path) | |
54 subprocess.check_call(['git', 'add'] + files, cwd=path) | |
55 subprocess.check_call(['git', 'commit', '-m="Initial"'], cwd=path) | |
56 | |
57 | |
58 class TestUpdateNode(unittest.TestCase): | |
59 def setUp(self): | |
60 self.workdir = tempfile.mkdtemp(prefix='tmp_test_node_') | |
61 | |
62 def tearDown(self): | |
63 shutil.rmtree(self.workdir) | |
64 | |
65 def testUpdate(self): | |
66 v8_cwd = os.path.join(self.workdir, 'v8') | |
67 gtest_cwd = os.path.join(self.workdir, 'v8', 'testing', 'gtest') | |
68 node_cwd = os.path.join(self.workdir, 'node') | |
69 | |
70 # Set up V8 test fixture. | |
71 shutil.copytree(src=os.path.join(TEST_DATA, 'v8'), dst=v8_cwd) | |
72 gitify(v8_cwd) | |
73 | |
74 # Set up gtest test fixture. | |
75 shutil.copytree(src=os.path.join(TEST_DATA, 'gtest'), dst=gtest_cwd) | |
76 gitify(gtest_cwd) | |
77 | |
78 # Set up node test fixture (no git repo required). | |
79 shutil.copytree(src=os.path.join(TEST_DATA, 'node'), dst=node_cwd) | |
80 | |
81 # Run update script. | |
82 update_node.Main([v8_cwd, node_cwd]) | |
83 | |
84 # Check expectations. | |
85 with open(os.path.join(node_cwd, 'deps', 'v8', '.gitignore')) as f: | |
86 actual_gitignore = f.read() | |
87 self.assertEquals(EXPECTED_GITIGNORE.strip(), actual_gitignore.strip()) | |
88 for f in ADDED_FILES: | |
89 added_file = os.path.join(node_cwd, 'deps', 'v8', *f.split('/')) | |
90 self.assertTrue(os.path.exists(added_file)) | |
91 for f in REMOVED_FILES: | |
92 removed_file = os.path.join(node_cwd, 'deps', 'v8', *f.split('/')) | |
93 self.assertFalse(os.path.exists(removed_file)) | |
OLD | NEW |