<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/106302>106302</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[llvm-lit] Lit's built-in cat command not handling carriage returns correctly
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
connieyzhu
</td>
</tr>
</table>
<pre>
When using lit's internal shell to run [clang-tools-extra/test/clang-apply-replacements/crlf.cpp](https://github.com/llvm/llvm-project/blob/main/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.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykVV2v4jYQ_TXmZUQUDCHkIQ97lyKtdPvSD_V5kkwSt44d2Q6Q_fXVOHAvl2qr7VZCIDOej3PmzBi9V50hKkX2IrLjCqfQW1fW1hhF89d-WlW2mcs_ejIweWU60CoImXtQJpAzqMH3pDUEC24yILKXWqPp1sFa7dd0DQ6FPAXyQcjTYsJx1PPa0aixpoFM8Gxyuk3qcRTZUchDH8LoxfaTkCchT50K_VQltR2EPGl9vv-sR2f_pJojV9pWQp4GVOYtzw-XIAshP0PoCdgJWl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