1""" 2Copyright © 2024 Google, Inc. 3 4Permission is hereby granted, free of charge, to any person obtaining a 5copy of this software and associated documentation files (the "Software"), 6to deal in the Software without restriction, including without limitation 7the rights to use, copy, modify, merge, publish, distribute, sublicense, 8and/or sell copies of the Software, and to permit persons to whom the 9Software is furnished to do so, subject to the following conditions: 10 11The above copyright notice and this permission notice (including the next 12paragraph) shall be included in all copies or substantial portions of the 13Software. 14 15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21SOFTWARE. 22""" 23 24import unittest 25from pathlib import Path 26 27import meson_to_hermetic.meson_impl as impl 28 29abs_toml_path = Path(__file__).parent.resolve() / 'test_toml_files' 30 31 32class TestConfigParsing(unittest.TestCase): 33 """ 34 Contains methods that directly parse project config files 35 I.E. *.toml files 36 """ 37 38 def test_load_dependencies(self): 39 expected = { 40 'test_dep': { 41 'test_target': 1 42 }, 43 'test_dep_two': { 44 'test_target': 1 45 }, 46 } 47 path = str(abs_toml_path / 'load_dependencies.toml') 48 impl.load_dependencies(path) 49 self.assertEqual(impl.external_dep, expected) 50 51 def test_empty_dependencies(self): 52 expected = {} 53 path = str(abs_toml_path / 'empty_dependencies.toml') 54 impl.load_dependencies(path) 55 self.assertEqual(impl.external_dep, expected) 56 57 58class TestMesonAPI(unittest.TestCase): 59 def test_dependency(self): 60 path = str(abs_toml_path / 'load_dependencies.toml') 61 # { 62 # 'test_dep': { 63 # 'test_target': 1 64 # }, 65 # 'test_dep_two': { 66 # 'test_target': 1 67 # }, 68 # } 69 impl.load_dependencies(path) 70 71 dep = impl.dependency('test_dep') 72 expected = impl.Dependency( 73 'test_dep', 74 targets=[ 75 impl.DependencyTarget('test_target', impl.DependencyTargetType.SHARED_LIBRARY) 76 ], 77 version='', 78 found=True, 79 ) 80 81 self.assertEqual( 82 dep.name, 83 expected.name 84 ) 85 self.assertEqual( 86 dep.found(), 87 expected.found() 88 ) 89 self.assertEqual( 90 len(dep.targets), 91 len(expected.targets), 92 ) 93 for index, target in enumerate(dep.targets): 94 expected_target = expected.targets[index] 95 self.assertEqual( 96 target.target_name, 97 expected_target.target_name, 98 ) 99 self.assertEqual( 100 target.target_type, 101 expected_target.target_type, 102 ) 103 104 105if __name__ == '__main__': 106 unittest.main() 107