@@ -56,3 +56,42 @@ def test_output_json(testcase: DataDrivenTestCase) -> None:
5656 normalized_output = [line .replace (test_temp_dir + json_os_separator , "" ) for line in output ]
5757
5858 assert normalized_output == testcase .output
59+
60+
61+ class OutputGitHubsuite (DataSuite ):
62+ files = ["outputgithub.test" ]
63+
64+ def run_case (self , testcase : DataDrivenTestCase ) -> None :
65+ test_output_github (testcase )
66+
67+
68+ def test_output_github (testcase : DataDrivenTestCase ) -> None :
69+ """Run Mypy in a subprocess, and ensure that `--output=github` works as intended."""
70+ mypy_cmdline = ["--output=github" ]
71+ mypy_cmdline .append (f"--python-version={ '.' .join (map (str , PYTHON3_VERSION ))} " )
72+
73+ # Write the program to a file.
74+ program_path = os .path .join (test_temp_dir , "main" )
75+ mypy_cmdline .append (program_path )
76+ with open (program_path , "w" , encoding = "utf8" ) as file :
77+ for s in testcase .input :
78+ file .write (f"{ s } \n " )
79+
80+ output = []
81+ # Type check the program.
82+ out , err , returncode = api .run (mypy_cmdline )
83+ # split lines, remove newlines, and remove directory of test case
84+ for line in (out + err ).rstrip ("\n " ).splitlines ():
85+ if line .startswith (test_temp_dir + os .sep ):
86+ output .append (line [len (test_temp_dir + os .sep ) :].rstrip ("\r \n " ))
87+ else :
88+ output .append (line .rstrip ("\r \n " ))
89+
90+ if returncode > 1 :
91+ output .append ("!!! Mypy crashed !!!" )
92+
93+ # Remove temp file.
94+ os .remove (program_path )
95+
96+ normalized_output = [line .replace (test_temp_dir + os .sep , "" ) for line in output ]
97+ assert normalized_output == testcase .output
0 commit comments