blob: ec7a81b8d1ee47e3d2f40bee88d32b48913d72d8 [file] [log] [blame] [edit]
"""Tests for gn_utils.
Before running these tests, run test_data/gn_utils/generate_test_data.sh with
a recent version of gn to make sure the test data is up to date.
"""
from __future__ import absolute_import
import datetime
import os
import re
import sys
import unittest
# Allow imports from cq/scripts folder
sys.path.insert(
0,
os.path.realpath(os.path.join(os.path.dirname(__file__), os.pardir)))
from helpers import gn_utils
class GnUtilsTest(unittest.TestCase):
def testValidGnLabelToTargetName(self):
"""Tests that gn_label_to_target_name handles valid input properly."""
self.assertEqual('baz', gn_utils.gn_label_to_target_name('//foo/bar:baz'))
self.assertEqual('baz', gn_utils.gn_label_to_target_name('//foo/bar/baz'))
self.assertEqual('foo', gn_utils.gn_label_to_target_name('//foo'))
self.assertEqual('qux', gn_utils.gn_label_to_target_name('qux'))
def testBadGnLabelToTargetName(self):
"""Tests that gn_label_to_target_name raises exceptions on bad input."""
with self.assertRaises(ValueError):
gn_utils.gn_label_to_target_name('')
with self.assertRaises(ValueError):
gn_utils.gn_label_to_target_name(None)
with self.assertRaises(ValueError):
gn_utils.gn_label_to_target_name('//foo/')
with self.assertRaises(ValueError):
gn_utils.gn_label_to_target_name('//foo:')
def testFilePathToGnLabel(self):
self.assertEqual(
'//:*',
gn_utils.filepath_to_gn_path('chromium/src/BUILD.gn'))
self.assertEqual(
'//foo:*',
gn_utils.filepath_to_gn_path('chromium/src/foo/BUILD.gn'))
self.assertEqual(
'//foo/bar/baz:*',
gn_utils.filepath_to_gn_path('chromium/src/foo/bar/baz/BUILD.gn'))
def testFilePathToGnLabel_RaisesNotBuildGn(self):
with self.assertRaises(ValueError):
gn_utils.filepath_to_gn_path('chromium/src/x.cc')
with self.assertRaises(ValueError):
gn_utils.filepath_to_gn_path('chromium/src/foo.gni')
with self.assertRaises(ValueError):
gn_utils.filepath_to_gn_path('chromium/src/foo/bar')
def testFilePathToGnLabel_RaisesNotChromiumSrc(self):
with self.assertRaises(ValueError):
gn_utils.filepath_to_gn_path('src/BUILD.gn')
with self.assertRaises(ValueError):
gn_utils.filepath_to_gn_path('BUILD.gn')
with self.assertRaises(ValueError):
gn_utils.filepath_to_gn_path('chromecast/internal/BUILD.gn')
if __name__ == '__main__':
unittest.main()