Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file unit_version_control.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235openCommonopenOUnitmoduleLib=Lib_vcs(*****************************************************************************)(* Helpers *)(*****************************************************************************)letwith_tmp_directoryf=Common2.with_tmp_dir(funtmp_dir->Common.finalize(fun()->ftmp_dir)(fun()->(* yep, rm -rf, I'm not scared *)Common.command2(spf"rm -rf %s/.git"tmp_dir);Common.command2(spf"rm -rf %s/.hg"tmp_dir);))letexec_cmds~basedirxs=xs+>List.iter(funcmd->letexit_status=Sys.command(spf"cd %s; %s"basedircmd)inmatchexit_statuswith|0->()|_->failwith(spf"command '%s' failed, exit code = %d"cmdexit_status))(*****************************************************************************)(* Unit tests *)(*****************************************************************************)letunittest="version_control">:::[(*****************************************************************************)(* Basic *)(*****************************************************************************)"find root">::(fun()->letpfff_home=Config_pfff.pathintryassert_equal(Git.find_root_from_absolute_pathpfff_home)pfff_home;assert_equal(Git.find_root_from_absolute_path(pfff_home^"/"))pfff_home;assert_equal(Git.find_root_from_absolute_path(pfff_home^"/h_version-control/unit_version_control.ml"))pfff_home;assert_raisesNot_found(fun()->Git.find_root_from_absolute_path"/");withNot_found->assert_failure"fail to find root for pfff_home";);"parsing file status">::(fun()->assert_equal(Lib.Added,"a/b/foo.php")(Lib.parse_file_status"A\ta/b/foo.php");assert_equal(Lib.Renamed(99,"a/b/foo.php"),"a/c/bar.php")(Lib.parse_file_status"R099\ta/b/foo.php\ta/c/bar.php"););(*****************************************************************************)(* Git *)(*****************************************************************************)"git">::(fun()->with_tmp_directory(funbasedir->Flag_version_control.verbose:=false;exec_cmds~basedir["git init > /dev/null";"echo 'foo' > foo.txt";"echo 'bar' > bar.txt";"git add bar.txt foo.txt";"git commit -m 'first commit' > /dev/null";];letcommit_id=Lib.VersionId"HEAD"inletprevious_id=Lib.VersionId"HEAD^"inletxs=Git.files_involved_in_diff~basedircommit_idinassert_equal~msg:"it should find all added files in a diff"[Lib.Added,"bar.txt";Lib.Added,"foo.txt"](Common.sortxs);letxs=Git.grep~basedir"ba"inassert_equal~msg:"it should find files containing ba with git grep"["bar.txt"]xs;letxs=Git.grep~basedir"nothing"inassert_equal~msg:"it should return an empty list when git grep found nothing"[]xs;exec_cmds~basedir["echo new_content > bar.txt";"git commit -a -m'first modif' > /dev/null";];lettmpfile=Git.show~basedir"bar.txt"commit_idinletxs=Common.cattmpfileinassert_equal~msg:"it should show the current content of the file"["new_content"]xs;lettmpfile=Git.show~basedir"bar.txt"previous_idinletxs=Common.cattmpfileinassert_equal~msg:"it should show the past content of the file"["bar"]xs;););(*****************************************************************************)(* Mercurial *)(*****************************************************************************)"mercurial">::(fun()->with_tmp_directory(funbasedir->Flag_version_control.verbose:=false;exec_cmds~basedir["hg init > /dev/null";"echo 'foo' > foo.txt";"echo 'bar' > bar.txt";"hg add bar.txt foo.txt";"hg commit -m 'first commit' > /dev/null";];letcommit_id=Lib.VersionId"."inletprevious_id=Lib.VersionId".^"inletxs=Mercurial.files_involved_in_diff~basedircommit_idinassert_equal~msg:"it should find all added files in a diff"[Lib.Added,"bar.txt";Lib.Added,"foo.txt"](Common.sortxs);letxs=Mercurial.grep~basedir"ba"inassert_equal~msg:"it should find files containing ba with hg grep"["bar.txt"]xs;letxs=Mercurial.grep~basedir"nothing"inassert_equal~msg:"it should return an empty list when hg grep found nothing"[]xs;exec_cmds~basedir["echo new_content > bar.txt";"hg commit -m'first modif' > /dev/null";];lettmpfile=Mercurial.show~basedir"bar.txt"commit_idinletxs=Common.cattmpfileinassert_equal~msg:"it should show the current content of the file"["new_content"]xs;lettmpfile=Mercurial.show~basedir"bar.txt"previous_idinletxs=Common.cattmpfileinassert_equal~msg:"it should show the past content of the file"["bar"]xs;exec_cmds~basedir["echo new_content > foo.txt";"hg remove bar.txt";"hg commit -m'second modif' > /dev/null";];letxs=Mercurial.files_involved_in_diff~basedircommit_idinassert_equal~msg:"it should find modified and removed files in a diff"[Lib.Deleted,"bar.txt";Lib.Modified,"foo.txt"](Common.sortxs);));(*****************************************************************************)(* OO interface *)(*****************************************************************************)"generic vcs">::(fun()->with_tmp_directory(funbasedir->Flag_version_control.verbose:=false;exec_cmds~basedir["git init > /dev/null";"echo 'foo' > foo.txt";"echo 'bar' > bar.txt";"git add bar.txt foo.txt";"git commit -m 'first commit' > /dev/null";];letcommit_id=Lib.VersionId"HEAD"inlet_previous_id=Lib.VersionId"HEAD^"inletvcs=Generic_vcs.mk_vcs~basedirinletxs=vcs#files_involved_in_diffcommit_idinassert_equal~msg:"it should find all added files in a diff via generic interface"[Lib.Added,"bar.txt";Lib.Added,"foo.txt"](Common.sortxs);));]