Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / native_client_sdk / src / build_tools / tests / parse_dsc_test.py
blob77f96b801cfc912e473d9445e664ed0a070c7d75
1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium 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.
6 import copy
7 import datetime
8 import os
9 import posixpath
10 import subprocess
11 import sys
12 import unittest
14 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
15 BUILD_TOOLS_DIR = os.path.dirname(SCRIPT_DIR)
17 sys.path.append(BUILD_TOOLS_DIR)
18 import generate_make
19 import parse_dsc
21 BASIC_DESC = {
22 'TOOLS': ['newlib', 'glibc'],
23 'TARGETS': [
25 'NAME' : 'hello_world',
26 'TYPE' : 'main',
27 'SOURCES' : ['hello_world.c'],
30 'DEST' : 'examples/api'
33 class TestValidateFormat(unittest.TestCase):
34 def _validate(self, src, expected_failure):
35 try:
36 parse_dsc.ValidateFormat(src, parse_dsc.DSC_FORMAT)
37 except parse_dsc.ValidationError as e:
38 if expected_failure:
39 self.assertEqual(str(e), expected_failure)
40 return
41 raise
43 def testGoodDesc(self):
44 testdesc = copy.deepcopy(BASIC_DESC)
45 self._validate(testdesc, None)
47 def testMissingKey(self):
48 testdesc = copy.deepcopy(BASIC_DESC)
49 del testdesc['TOOLS']
50 self._validate(testdesc, 'Missing required key TOOLS.')
52 testdesc = copy.deepcopy(BASIC_DESC)
53 del testdesc['TARGETS'][0]['NAME']
54 self._validate(testdesc, 'Missing required key NAME.')
56 def testNonEmpty(self):
57 testdesc = copy.deepcopy(BASIC_DESC)
58 testdesc['TOOLS'] = []
59 self._validate(testdesc, 'Expected non-empty value for TOOLS.')
61 testdesc = copy.deepcopy(BASIC_DESC)
62 testdesc['TARGETS'] = []
63 self._validate(testdesc, 'Expected non-empty value for TARGETS.')
65 testdesc = copy.deepcopy(BASIC_DESC)
66 testdesc['TARGETS'][0]['NAME'] = ''
67 self._validate(testdesc, 'Expected non-empty value for NAME.')
69 def testBadValue(self):
70 testdesc = copy.deepcopy(BASIC_DESC)
71 testdesc['TOOLS'] = ['newlib', 'glibc', 'badtool']
72 self._validate(testdesc, 'Value badtool not expected in TOOLS.')
74 def testExpectStr(self):
75 testdesc = copy.deepcopy(BASIC_DESC)
76 testdesc['TOOLS'] = ['newlib', True, 'glibc']
77 self._validate(testdesc, 'Value True not expected in TOOLS.')
79 def testExpectList(self):
80 testdesc = copy.deepcopy(BASIC_DESC)
81 testdesc['TOOLS'] = 'newlib'
82 self._validate(testdesc, 'Key TOOLS expects LIST not STR.')
84 # TODO(bradnelson): Add test which generates a real make and runs it.
86 if __name__ == '__main__':
87 unittest.main()