fix(stubgen): write LF to stdout on Windows
When --out was not given, stubgen wrote the generated code and debt lines to sys.stdout, which translates LF to CRLF on Windows, so redirecting stdout produced CRLF files. stdout is now reconfigured to utf-8 with LF newlines, matching the --out path. A subprocess test checks the bytes on stdout. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01V9UU71SP1UKGR51Sowbgmq
This commit is contained in:
parent
77b9f7270c
commit
f6d5404f45
|
|
@ -87,6 +87,8 @@ if(BUILD_TESTING)
|
|||
${CMAKE_CURRENT_SOURCE_DIR}/tools/tests/test_stubgen.py)
|
||||
add_test(NAME debt_split COMMAND ${Python3_EXECUTABLE}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tools/tests/test_debt_split.py)
|
||||
add_test(NAME stubgen_stdout_newlines COMMAND ${Python3_EXECUTABLE}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tools/tests/test_stubgen_stdout_newlines.py)
|
||||
add_test(NAME hardware_oracle COMMAND ${Python3_EXECUTABLE}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/tools/hw-oracle/test_hw_oracle.py)
|
||||
add_test(NAME pr_overlap_exports COMMAND ${Python3_EXECUTABLE}
|
||||
|
|
|
|||
|
|
@ -211,6 +211,7 @@ def main(argv=None):
|
|||
ap.add_argument("--td-out", required=False, default=None, help="output file for TechnicalDebt lines, which go in docs/dev/debt/MODULE.md, default stderr when code uses stdout, otherwise stdout")
|
||||
ap.add_argument("--td-only", action="store_true", help="print only TechnicalDebt lines, no code")
|
||||
args = ap.parse_args(argv)
|
||||
sys.stdout.reconfigure(encoding="utf-8", newline="\n")
|
||||
try:
|
||||
if not args.td_only and args.out and args.td_out and same_file(args.out, args.td_out):
|
||||
ap.error("--out and --td-out must name different files")
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
tools = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
class StubgenStdoutNewlineTests(unittest.TestCase):
|
||||
def run_stubgen(self, *extra):
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
nids = Path(d) / "nids.txt"
|
||||
nids.write_text("AC1FtjqMCL0\n", encoding="utf-8", newline="\n")
|
||||
return subprocess.run(
|
||||
[sys.executable, str(tools / "stubgen.py"), "--module", "libkernel", "--nids", str(nids)] + list(extra),
|
||||
capture_output=True,
|
||||
check=True,
|
||||
)
|
||||
|
||||
def test_code_on_stdout_uses_lf(self):
|
||||
result = self.run_stubgen()
|
||||
self.assertIn(b"\n", result.stdout)
|
||||
self.assertNotIn(b"\r\n", result.stdout)
|
||||
|
||||
def test_td_only_on_stdout_uses_lf(self):
|
||||
result = self.run_stubgen("--td-only")
|
||||
self.assertIn(b"\n", result.stdout)
|
||||
self.assertNotIn(b"\r\n", result.stdout)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Loading…
Reference in New Issue