[M120 Migration][Gamepad]Add gamepad event latency Test code
[platform/framework/web/chromium-efl.git] / build / gn_helpers_unittest.py
old mode 100644 (file)
new mode 100755 (executable)
index f4b756c..6e305d7
@@ -1,11 +1,16 @@
-# Copyright 2016 The Chromium Authors. All rights reserved.
+#!/usr/bin/env python3
+# Copyright 2016 The Chromium Authors
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
-import mock
+import os
+import pathlib
+import shutil
 import sys
+import tempfile
 import textwrap
 import unittest
+from unittest import mock
 
 import gn_helpers
 
@@ -310,6 +315,39 @@ class UnitTest(unittest.TestCase):
           textwrap.dedent('import("some/relative/args/file.gni")'))
       parser.ReplaceImports()
 
+  def test_CreateBuildCommand(self):
+    with tempfile.TemporaryDirectory() as temp_dir:
+      suffix = '.bat' if sys.platform.startswith('win32') else ''
+      self.assertEqual(f'autoninja{suffix}',
+                       gn_helpers.CreateBuildCommand(temp_dir)[0])
+
+      siso_deps = pathlib.Path(temp_dir) / '.siso_deps'
+      siso_deps.touch()
+      self.assertEqual(f'autosiso{suffix}',
+                       gn_helpers.CreateBuildCommand(temp_dir)[0])
+
+      with mock.patch('shutil.which', lambda x: None):
+        cmd = gn_helpers.CreateBuildCommand(temp_dir)
+        self.assertIn('third_party', cmd[0])
+        self.assertIn(f'{os.sep}siso', cmd[0])
+        self.assertEqual(['ninja', '-C', temp_dir], cmd[1:])
+
+      ninja_deps = pathlib.Path(temp_dir) / '.ninja_deps'
+      ninja_deps.touch()
+
+      with self.assertRaisesRegex(Exception, 'Found both'):
+        gn_helpers.CreateBuildCommand(temp_dir)
+
+      siso_deps.unlink()
+      self.assertEqual(f'autoninja{suffix}',
+                       gn_helpers.CreateBuildCommand(temp_dir)[0])
+
+      with mock.patch('shutil.which', lambda x: None):
+        cmd = gn_helpers.CreateBuildCommand(temp_dir)
+        self.assertIn('third_party', cmd[0])
+        self.assertIn(f'{os.sep}ninja', cmd[0])
+        self.assertEqual(['-C', temp_dir], cmd[1:])
+
 
 if __name__ == '__main__':
   unittest.main()