Skip to content

[llvm-lit] Lit's built-in cat command not handling carriage returns correctly #106302

Open
@connieyzhu

Description

@connieyzhu

When using lit's internal shell to run clang-tools-extra/test/clang-apply-replacements/crlf.cpp, the test fails. Upon further inspection, this is due to lit's built-in cat command not behaving the same as many systems' cat (e.g. Linux). It is not able to identify carriage returns (^M) in files.

This problem was diagnosed by running cat %S/Inputs/crlf/crlf.cpp (in line 2 of the above file) with both the internal shell and with a Linux shell, and redirecting output to two different files. When analyzing the files with cat -e in the Linux shell, the following is displayed:

cat %S/Inputs/crlf/crlf.cpp run with Linux shell (expected output):

^M$
// This file intentionally uses a CRLF newlines!^M$
^M$
void foo() {^M$
  int *x = 0;^M$
}^M$

cat %S/Inputs/crlf/crlf.cpp run with lit internal shell (actual output):

$
// This file intentionally uses a CRLF newlines!$
$
void foo() {$
  int *x = 0;$
}$

This poses an issue, as the tests in this file rely on precise character offset to make text replacements.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions