I have included tests, and will add a script here to do some randomly generated
tests of diff3. I would really appreciate more test cases, I am not sure this
exercises all the forms of output diff3 can generate, but I think it is time
for more eyes.
The random tests unearthed a missing case in the ed script generation, that fix
is included in this review.
'''
#!/bin/sh
bsddiff3=/usr/obj/code/freebsd/worktrees/diff3/amd64.amd64/usr.bin/diff3/diff3
randomfile()
{
dd if=/dev/random bs=100k count=1 | b64encode - > $1
}
checkdiff3()
{
set -x
gdiff3 $@ > gdiff3.out
gr=$?
$bsddiff3 $@ > bsddiff3.out
br=$?
if [ $gr -ne $br ]
then
echo test failed return codes differ: diff3 $@
exit
fi
diff gdiff3.out bsddiff3.out
if [ $? -ne 0 ]
then
sdiff gdiff3.out bsddiff3.out | head
echo test failed, output differs: diff3 $@
exit
fi
echo test passed diff3 $@
}
randomfiles()
{
randomfile o
cp o m
cp o y
}
checkscripts()
{
checkdiff3 -e m o y
checkdiff3 -A m o y
checkdiff3 -m m o y
}
test_all_differ()
{
randomfile o
randomfile m
randomfile y
checkscripts
}
test_m_additions()
{
randomfiles
echo "mine" >> m
echo "mine" >> m
echo "mine" >> m
echo "mine" >> m
checkscripts
}
test_y_additions()
{
randomfiles
echo "yours" >> m
echo "yours" >> m
echo "yours" >> m
echo "yours" >> m
checkscripts
}
test_my_same_additions()
{
randomfiles
echo "both" >> m
echo "both" >> m
echo "both" >> m
echo "both" >> m
echo "both" >> y
echo "both" >> y
echo "both" >> y
echo "both" >> y
checkscripts
}
test_my_conflicting_additions()
{
randomfiles
echo "mine" >> m
echo "mine" >> m
echo "mine" >> m
echo "mine" >> m
echo "yours" >> y
echo "yours" >> y
echo "yours" >> y
echo "yours" >> y
checkscripts
}
test_same_delete()
{
randomfiles
edscript=""
edscript="$edscript\n$(ed_delete 12 24)"
echo -e $edscript | ed m
echo -e $edscript | ed y
checkscripts
}
random_ed_add()
{
printf "%da%s\n"
}
ed_move()
{
printf "%d,%dm%d" $1 $2 $3
}
ed_delete()
{
printf "%d,%dd" $1 $2
}
test_ed_script()
{
randomfiles
edscript=""
edscript="$edscript\n$(ed_delete 12 24)"
edscript="$edscript\n$(ed_move 45 69 23)"
edscript="$edscript\nwq\n"
echo -e $edscript
echo -e $edscript | ed m
echo -e $edscript | ed y
checkscripts
}
make -C ..
test_m_additions
test_y_additions
test_my_same_additions
test_my_conflicting_additions
test_ed_script
echo if we got here all the tests passed
'''