Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cram tests on Windows, line termination and Git warning #8358

Open
maroneze opened this issue Aug 9, 2023 · 2 comments
Open

Cram tests on Windows, line termination and Git warning #8358

maroneze opened this issue Aug 9, 2023 · 2 comments
Labels

Comments

@maroneze
Copy link

maroneze commented Aug 9, 2023

When running Cram tests on Windows (from a Linux-based project), I ran into a few issues.

I created a .t file and ran the test on Linux, then updated the oracles (with LF as line terminator) to Git.

Then, on Windows (Cygwin, to be more precise), I cloned the git and re-ran the test (with dune test), and everything seemd fine.

However, if I change the .t file (e.g. add a new command, $ ls in the example below) and run dune test, the git diff message contains the entire output, as in:

--- a/_build/.sandbox/5de018a501f867385a42b6a127dad346/default/test/test.t/run.t
+++ b/_build/.sandbox/5de018a501f867385a42b6a127dad346/default/test/test.t/run.t.corrected
@@ -1,4 +1,5 @@
-  $ echo "hello world" > a.txt
-  $ cat a.txt
-  hello world
-  $ ls
+  $ echo "hello world" > a.txt
+  $ cat a.txt
+  hello world
+  $ ls
+  a.txt

I need to do dune promote and then git diff to better see the diff:

diff --git a/proj/test/test.t/run.t b/proj/test/test.t/run.t
index 1e57b8a..03672c9 100644
--- a/proj/test/test.t/run.t
+++ b/proj/test/test.t/run.t
@@ -1,3 +1,5 @@
-  $ echo "hello world" > a.txt
-  $ cat a.txt
-  hello world
+  $ echo "hello world" > a.txt^M
+  $ cat a.txt^M
+  hello world^M
+  $ ls^M
+  a.txt^M

Here, the ^M clearly shows the issue is the CR added by Windows.

The issue is that, by default on a fresh Cygwin, git config core.autocrlf true is not set. In this kind of setup, it should be. My question is: is there a reason why the result of dune promote does not display the ^M, as git diff does? It could help diagnose such issues earlier.

I then ran git config core.autocrlf true to avoid the issue and obtained the expected diff.

Now, the remaining issue is that, if I change the .t file again (for instance, to add a new command), whenever I run dune test, I get this warning:

warning: in the working copy of 'proj/_build/.sandbox/bff183ecfd14b3674cf935851dd8dc12/default/test/test.t/run.t', LF will be replaced by CRLF the next time Git touches it

Because the message is related to Dune's sandbox directory, I'm afraid there's not much I can do about it. Or is there some configuration that avoids emitting it? Otherwise, could you please confirm that this warning is indeed harmless?

To reproduce it, I simply did (on a Linux) a dune init project, then added a test.t directory with a run.t, inside the test directory, ran dune test, dune promote, committed it to git, and then, on a Cygwin machine (with git config core.autocrlf true set), cloned the project, modified run.t and re-ran dune test.

Specifications

  • Version of dune (output of dune --version): 3.9.1 on both Linux and Windows
  • Version of ocaml (output of ocamlc --version): 4.13.1 on Linux, 4.14.0 on Windows
  • Operating system (distribution and version): Fedora 38, Cygwin 2.925 on Windows 10
@Alizter Alizter added the windows label Aug 9, 2023
@nojb
Copy link
Collaborator

nojb commented Aug 9, 2023

My question is: is there a reason why the result of dune promote does not display the ^M, as git diff does? It could help diagnose such issues earlier.

If memory serves, dune promote tries to avoid reporting whitespace diffs, so it probably uses git diff -w to produce the diff. Perhaps it should call git diff twice; the first one with -w to check if there is a (non-whitespace) diff, and the second one without -w to produce the actual diff to show to the user.

Otherwise, could you please confirm that this warning is indeed harmless?

This warning is harmless. The warning is generated by Git and it is telling you that Git will modify the line endings of the working copy of a file (exactly how the line endings will be modified depends on your Git configuration). I haven't looked at the details, but my hunch is that the reason that you see this warning each time you do dune test is that Dune is probably calling git diff at some point and any Git operation that touches a file may generate the above warning.

@yawaramin
Copy link
Contributor

Or is there some configuration that avoids emitting it?

See actions/checkout#135 (comment)

Long story short, add a .gitattributes file to your repo with the content: * -text.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants