Skip to content
This repository has been archived by the owner on Feb 8, 2020. It is now read-only.

Commit

Permalink
Test: end of line comments
Browse files Browse the repository at this point in the history
This scenario is fairly common in the real world. It might be a stretch
to expect VCS tools to handle it correctly but it's not impossible.
  • Loading branch information
mndrix committed Sep 4, 2015
1 parent 47ec994 commit 7960e5b
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ The table of results below is based on these VCS versions:
<td>Ok</td>
<td>Fail</td>
</tr>
<tr>
<th>eol-comment</th>
<td>Fail</td>
<td>Fail</td>
<td>Fail</td>
<td>Fail</td>
</tr>
<tr>
<th>move-modify</th>
<td>Ok</td>
Expand Down
63 changes: 63 additions & 0 deletions t/eol-comment.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
use strict;
use warnings;
use Test::More tests => 2;
use Test::Merges;

# Add an end-of-line comment and change the same line
#
# Developers sometimes add comments to a block of code when they
# encounter it for the first time. It's a good opportunity to
# document subtle assumptions. When this is done with end of line
# comments, conflicts can result.
#
# A good VCS should notice that an end of line comment is independent
# of changes earlier on the line. This might require knowing a language's
# semantics to get it right.

# build expected output
file 'greet.c', <<'END';
#include <stdio.h>
#include <stdlib.h>
int main () {
printf("hi\n");
printf("bye\n");
exit(0);
}
END

file 'run', <<'END';
#!/bin/sh
gcc -o greet greet.c && \
./greet
END
chmod 0755, 'run';

# expected output after all merges are done
file 'expected.txt', <<'END';
hello
bye
END

# build a common starting point
add 'greet.c', 'run', 'expected.txt';
commit 'intial state';

branch 'a', sub {
file 'greet.c', <<'END';
#include <stdio.h>
#include <stdlib.h>
int main () {
printf("hi\n"); // greet the user
printf("bye\n");
exit(0);
}
END
commit 'add eol comment';
};

branch 'b', sub {
sed 's/hi/hello/', 'greet.c';
commit 'longer greeting';
};

merge_ok 'a', 'b';

0 comments on commit 7960e5b

Please sign in to comment.