Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: tools/tests/gyp_to_android_tests.py

Issue 142173002: Add self tests for gyp_to_android. (Closed) Base URL: https://skia.googlesource.com/skia.git@GYP2
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 #!/usr/bin/python
2
3 # Copyright 2014 Google Inc.
4 #
5 # Use of this source code is governed by a BSD-style license that can be
6 # found in the LICENSE file.
7
8 """
9 Test gyp_to_android.py
10 """
11
12 import os
13 import sys
14
15 # Find this file so we can find the Skia trunk.
16 script_dir = os.path.dirname(__file__)
epoger 2014/01/21 20:00:51 all caps for these constants
scroggo 2014/01/22 16:36:48 Done.
17 skia_trunk = os.path.normpath(os.path.join(script_dir, os.pardir, os.pardir))
18
19 # Path to gyp_to_android
20 sys.path.append(os.path.join('platform_tools', 'android', 'bin'))
epoger 2014/01/21 20:00:51 It worries me that tools/ is running the unittests
scroggo 2014/01/22 16:36:48 I've added a TODO. I think it's fine to move it in
21
22 import gyp_to_android
23
24 def AssertFunctionAsserts(f):
epoger 2014/01/21 20:00:51 Please make the self-test extend unittest.TestCase
scroggo 2014/01/22 16:36:48 Done.
25 """
26 Assert that the passed in function asserts.
27 """
28 try:
29 f()
30 except AssertionError:
31 # Nothing to see here; this is the intended behavior.
32 pass
33 else:
34 assert False
35
36 def TestVarsDict():
37 """
38 Tests for the VarsDict class.
39 """
40 vars_dict = gyp_to_android.VarsDict()
epoger 2014/01/21 20:00:51 Using unittest.TestCase and its assertRaises() wil
scroggo 2014/01/22 16:36:48 Done.
41
42 # Inserting new dictionary entries should throw an exception.
43 def f():
44 vars_dict['c'] = None
45
46 AssertFunctionAsserts(f)
47
48 # ConvertDefines() should append all 'defines' to 'cflags' with '-D'.
epoger 2014/01/21 20:00:51 When you convert this to unittest.TestCase, I thin
scroggo 2014/01/22 16:36:48 Done.
49
50 # 'cflags' starts off empty.
51 assert len(vars_dict['cflags']) == 0
52
53 vars_dict['defines'].extend(['foo', 'bar', 'c++'])
54
55 vars_dict.ConvertDefines()
56
57 assert len(vars_dict['cflags']) == len(vars_dict['defines'])
58
59 for define in vars_dict['defines']:
60 assert ('-D' + define) in vars_dict['cflags']
61
62 # ConvertDefines() can only be called once.
63 def g():
64 vars_dict.ConvertDefines()
65
66 AssertFunctionAsserts(g)
67
68 def TestAddToList():
69 li = []
70 foo = 'foo'
71 gyp_to_android.AddToList(li, foo)
72 assert len(li) == 1
73 assert li[0] == foo
74
75 # Now attempt to add it again
76 gyp_to_android.AddToList(li, foo)
77 assert len(li) == 1
78 assert li[0] == foo
79
80 def TestAndroidMkCreation():
81 if gyp_to_android.main() != 0:
82 raise Exception('gyp_to_android failed!')
83 # Now there should be a file named 'Android.mk' at the root level.
84 path_to_android_mk = os.path.join(skia_trunk, 'Android.mk')
epoger 2014/01/21 20:00:51 I think it's dangerous for unittests to write into
scroggo 2014/01/22 16:36:48 Done. For what it's worth, gyp_to_android calls g
scroggo 2014/01/22 19:32:50 Actually it wasn't so hard. In patch set 5 (and be
85 if not os.path.exists(path_to_android_mk):
86 raise Exception('Failed to create Android.mk!')
87 # Remove Android.mk, which is no longer needed.
88 os.remove(path_to_android_mk)
89
90 # gypd files should have been removed.
91 for filename in os.listdir(os.path.join(skia_trunk, 'gyp')):
92 assert not filename.endswith('gypd')
93
94 def main():
95 print 'Running gyp_to_android tests...'
96 TestAndroidMkCreation()
97 TestVarsDict()
98 TestAddToList()
99 print 'gyp_to_android tests succeeded!'
100
101 if __name__ == "__main__":
102 main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698