8dc1225ea9545331b70a9647c390201a37e1d629b4b2cd016cb231ee9f8a380340be1b515219b42cd6717a9ac9c1b2157f115be303b9d43a9a35a719bd79a7 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/usr/bin/env python3
  2. # Copyright (c) 2012 Google Inc. 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.
  5. """ Unit tests for the ninja.py file. """
  6. from pathlib import Path
  7. import sys
  8. import unittest
  9. import gyp.generator.ninja as ninja
  10. class TestPrefixesAndSuffixes(unittest.TestCase):
  11. def test_BinaryNamesWindows(self):
  12. # These cannot run on non-Windows as they require a VS installation to
  13. # correctly handle variable expansion.
  14. if sys.platform.startswith("win"):
  15. writer = ninja.NinjaWriter(
  16. "foo", "wee", ".", ".", "build.ninja", ".", "build.ninja", "win"
  17. )
  18. spec = {"target_name": "wee"}
  19. self.assertTrue(
  20. writer.ComputeOutputFileName(spec, "executable").endswith(".exe")
  21. )
  22. self.assertTrue(
  23. writer.ComputeOutputFileName(spec, "shared_library").endswith(".dll")
  24. )
  25. self.assertTrue(
  26. writer.ComputeOutputFileName(spec, "static_library").endswith(".lib")
  27. )
  28. def test_BinaryNamesLinux(self):
  29. writer = ninja.NinjaWriter(
  30. "foo", "wee", ".", ".", "build.ninja", ".", "build.ninja", "linux"
  31. )
  32. spec = {"target_name": "wee"}
  33. self.assertTrue("." not in writer.ComputeOutputFileName(spec, "executable"))
  34. self.assertTrue(
  35. writer.ComputeOutputFileName(spec, "shared_library").startswith("lib")
  36. )
  37. self.assertTrue(
  38. writer.ComputeOutputFileName(spec, "static_library").startswith("lib")
  39. )
  40. self.assertTrue(
  41. writer.ComputeOutputFileName(spec, "shared_library").endswith(".so")
  42. )
  43. self.assertTrue(
  44. writer.ComputeOutputFileName(spec, "static_library").endswith(".a")
  45. )
  46. def test_GenerateCompileDBWithNinja(self):
  47. build_dir = (
  48. Path(__file__).resolve().parent.parent.parent.parent / "data" / "ninja"
  49. )
  50. compile_db = ninja.GenerateCompileDBWithNinja(build_dir)
  51. assert len(compile_db) == 1
  52. assert compile_db[0]["directory"] == str(build_dir)
  53. assert compile_db[0]["command"] == "cc my.in my.out"
  54. assert compile_db[0]["file"] == "my.in"
  55. assert compile_db[0]["output"] == "my.out"
  56. if __name__ == "__main__":
  57. unittest.main()