From 7960e5bc2c3a6c448d615b5f2d2cb2f9df9d3e2c Mon Sep 17 00:00:00 2001 From: Michael Hendricks Date: Fri, 4 Sep 2015 04:51:30 -0600 Subject: [PATCH] Test: end of line comments 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. --- README.md | 7 ++++++ t/eol-comment.t | 63 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 t/eol-comment.t diff --git a/README.md b/README.md index feffd65..5b741c2 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,13 @@ The table of results below is based on these VCS versions: Ok Fail + + eol-comment + Fail + Fail + Fail + Fail + move-modify Ok diff --git a/t/eol-comment.t b/t/eol-comment.t new file mode 100644 index 0000000..d6667fb --- /dev/null +++ b/t/eol-comment.t @@ -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 +#include +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 +#include +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';