[ninjalog_uploader] add tests
Use unittest module instead of doctest. Bug: 900161 Change-Id: I2e8265afb66345814c4c4b8e94618171b7aaaaf3 Reviewed-on: https://chromium-review.googlesource.com/c/1379441 Commit-Queue: Takuto Ikuta <tikuta@chromium.org> Reviewed-by: Dirk Pranke <dpranke@chromium.org> Reviewed-by: Shinya Kawanaka <shinyak@chromium.org>changes/41/1379441/7
parent
fb8c1a203d
commit
61cb9d6ba7
@ -0,0 +1 @@
|
||||
per-file ninjalog_uploader_test.py=tikuta@chromium.org
|
||||
@ -0,0 +1,68 @@
|
||||
#!/usr/bin/env python
|
||||
# Copyright (c) 2018 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 json
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
sys.path.insert(0, ROOT_DIR)
|
||||
|
||||
import ninjalog_uploader
|
||||
|
||||
|
||||
class NinjalogUploaderTest(unittest.TestCase):
|
||||
def test_parse_gn_args(self):
|
||||
self.assertEqual(ninjalog_uploader.ParseGNArgs(json.dumps([])), {})
|
||||
|
||||
# Extract current configs from GN's output json.
|
||||
self.assertEqual(ninjalog_uploader.ParseGNArgs(json.dumps([
|
||||
{
|
||||
'current': {'value': 'true'},
|
||||
'default': {'value': 'false'},
|
||||
'name': 'is_component_build'
|
||||
},
|
||||
])), {'is_component_build': 'true'})
|
||||
|
||||
self.assertEqual(ninjalog_uploader.ParseGNArgs(json.dumps([
|
||||
{
|
||||
'current': {'value': 'true'},
|
||||
'default': {'value': 'false'},
|
||||
'name': 'is_component_build'
|
||||
},
|
||||
{
|
||||
'current': {'value': 'false'},
|
||||
'default': {'value': 'false'},
|
||||
'name': 'use_goma'
|
||||
},
|
||||
])), {'is_component_build': 'true',
|
||||
'use_goma': 'false'})
|
||||
|
||||
def test_get_ninjalog(self):
|
||||
# No args => default to cwd.
|
||||
self.assertEqual(ninjalog_uploader.GetNinjalog(['ninja']),
|
||||
'./.ninja_log')
|
||||
|
||||
# Specified by -C case.
|
||||
self.assertEqual(
|
||||
ninjalog_uploader.GetNinjalog(['ninja', '-C', 'out/Release']),
|
||||
'out/Release/.ninja_log')
|
||||
self.assertEqual(
|
||||
ninjalog_uploader.GetNinjalog(['ninja', '-Cout/Release']),
|
||||
'out/Release/.ninja_log')
|
||||
|
||||
# Invalid -C flag case.
|
||||
self.assertEqual(ninjalog_uploader.GetNinjalog(['ninja', '-C']),
|
||||
'./.ninja_log')
|
||||
|
||||
# Multiple target directories => use the last directory.
|
||||
self.assertEqual(ninjalog_uploader.GetNinjalog(
|
||||
['ninja', '-C', 'out/Release', '-C', 'out/Debug']),
|
||||
'out/Debug/.ninja_log')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Loading…
Reference in New Issue