[OptTable] Fix typo VALUE => VALUES (NFCI) (#121523)
[llvm-project.git] / libc / utils / hdrgen / tests / test_integration.py
blob49cb08cd1b339d7bfd360f79efef941c0c1ab78d
1 import argparse
2 import subprocess
3 import sys
4 import unittest
5 from pathlib import Path
8 class TestHeaderGenIntegration(unittest.TestCase):
9 def setUp(self):
10 self.output_dir = TestHeaderGenIntegration.output_dir
11 self.source_dir = Path(__file__).parent
12 self.main_script = self.source_dir.parent / "main.py"
14 def run_script(self, yaml_file, output_file, entry_points):
15 command = [
16 "python3",
17 str(self.main_script),
18 str(yaml_file),
19 "--output",
20 str(output_file),
23 for entry_point in entry_points:
24 command.extend(["--entry-point", entry_point])
26 result = subprocess.run(
27 command,
28 capture_output=True,
29 text=True,
32 print("STDOUT:", result.stdout)
33 print("STDERR:", result.stderr)
34 result.check_returncode()
36 def compare_files(self, generated_file, expected_file):
37 with generated_file.open("r") as gen_file:
38 gen_content = gen_file.read()
39 with expected_file.open("r") as exp_file:
40 exp_content = exp_file.read()
42 self.assertEqual(gen_content, exp_content)
44 def test_generate_header(self):
45 yaml_file = self.source_dir / "input/test_small.yaml"
46 expected_output_file = self.source_dir / "expected_output/test_header.h"
47 output_file = self.output_dir / "test_small.h"
48 entry_points = {"func_b", "func_a", "func_c", "func_d", "func_e"}
50 self.run_script(yaml_file, output_file, entry_points)
52 self.compare_files(output_file, expected_output_file)
55 def main():
56 parser = argparse.ArgumentParser(description="TestHeaderGenIntegration arguments")
57 parser.add_argument(
58 "--output_dir",
59 type=Path,
60 help="Output directory for generated headers",
61 required=True,
63 args, remaining_argv = parser.parse_known_args()
65 TestHeaderGenIntegration.output_dir = args.output_dir
67 sys.argv[1:] = remaining_argv
69 unittest.main()
72 if __name__ == "__main__":
73 main()