summaryrefslogtreecommitdiffstats
path: root/build/gyp_chromium_test.py
blob: 0ae74faf31d53109c0e9d2987f0a3fb02d590d94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import os
import sys
import unittest

SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))
SRC_DIR = os.path.dirname(SCRIPT_DIR)

sys.path.append(os.path.join(SRC_DIR, 'third_party', 'pymock'))

import mock

import gyp_chromium


class TestGetOutputDirectory(unittest.TestCase):
  @mock.patch('os.environ', {})
  @mock.patch('sys.argv', [__file__])
  def testDefaultValue(self):
    self.assertEqual(gyp_chromium.GetOutputDirectory(), 'out')

  @mock.patch('os.environ', {'GYP_GENERATOR_FLAGS': 'output_dir=envfoo'})
  @mock.patch('sys.argv', [__file__])
  def testEnvironment(self):
    self.assertEqual(gyp_chromium.GetOutputDirectory(), 'envfoo')

  @mock.patch('os.environ', {'GYP_GENERATOR_FLAGS': 'output_dir=envfoo'})
  @mock.patch('sys.argv', [__file__, '-Goutput_dir=cmdfoo'])
  def testGFlagOverridesEnv(self):
    self.assertEqual(gyp_chromium.GetOutputDirectory(), 'cmdfoo')

  @mock.patch('os.environ', {})
  @mock.patch('sys.argv', [__file__, '-G', 'output_dir=foo'])
  def testGFlagWithSpace(self):
    self.assertEqual(gyp_chromium.GetOutputDirectory(), 'foo')


class TestGetGypVars(unittest.TestCase):
  @mock.patch('os.environ', {})
  def testDefault(self):
    self.assertEqual(gyp_chromium.GetGypVars([]), {})

  @mock.patch('os.environ', {})
  @mock.patch('sys.argv', [__file__, '-D', 'foo=bar'])
  def testDFlags(self):
    self.assertEqual(gyp_chromium.GetGypVars([]), {'foo': 'bar'})

  @mock.patch('os.environ', {})
  @mock.patch('sys.argv', [__file__, '-D', 'foo'])
  def testDFlagsNoValue(self):
    self.assertEqual(gyp_chromium.GetGypVars([]), {'foo': '1'})

  @mock.patch('os.environ', {})
  @mock.patch('sys.argv', [__file__, '-D', 'foo=bar', '-Dbaz'])
  def testDFlagMulti(self):
    self.assertEqual(gyp_chromium.GetGypVars([]), {'foo': 'bar', 'baz': '1'})


if __name__ == '__main__':
  unittest.main()