Skip to content

Commit

Permalink
t/helper: merge test-chmtime into test-tool
Browse files Browse the repository at this point in the history
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
pclouds authored and gitster committed Mar 27, 2018
1 parent efd71f8 commit 0e49649
Show file tree
Hide file tree
Showing 33 changed files with 94 additions and 89 deletions.
3 changes: 2 additions & 1 deletion Makefile
Expand Up @@ -652,7 +652,8 @@ X =

PROGRAMS += $(patsubst %.o,git-%$X,$(PROGRAM_OBJS))

TEST_PROGRAMS_NEED_X += test-chmtime
TEST_BUILTINS_OBJS += test-chmtime.o

TEST_PROGRAMS_NEED_X += test-ctype
TEST_PROGRAMS_NEED_X += test-config
TEST_PROGRAMS_NEED_X += test-date
Expand Down
15 changes: 8 additions & 7 deletions t/helper/test-chmtime.c
Expand Up @@ -5,28 +5,29 @@
*
* The mtime can be changed to an absolute value:
*
* test-chmtime =<seconds> file...
* test-tool chmtime =<seconds> file...
*
* Relative to the current time as returned by time(3):
*
* test-chmtime =+<seconds> (or =-<seconds>) file...
* test-tool chmtime =+<seconds> (or =-<seconds>) file...
*
* Or relative to the current mtime of the file:
*
* test-chmtime <seconds> file...
* test-chmtime +<seconds> (or -<seconds>) file...
* test-tool chmtime <seconds> file...
* test-tool chmtime +<seconds> (or -<seconds>) file...
*
* Examples:
*
* To just print the mtime use --verbose and set the file mtime offset to 0:
*
* test-chmtime -v +0 file
* test-tool chmtime -v +0 file
*
* To set the mtime to current time:
*
* test-chmtime =+0 file
* test-tool chmtime =+0 file
*
*/
#include "test-tool.h"
#include "git-compat-util.h"
#include <utime.h>

Expand Down Expand Up @@ -56,7 +57,7 @@ static int timespec_arg(const char *arg, long int *set_time, int *set_eq)
return 1;
}

int cmd_main(int argc, const char **argv)
int cmd__chmtime(int argc, const char **argv)
{
static int verbose;

Expand Down
1 change: 1 addition & 0 deletions t/helper/test-tool.c
Expand Up @@ -7,6 +7,7 @@ struct test_cmd {
};

static struct test_cmd cmds[] = {
{ "chmtime", cmd__chmtime },
};

int cmd_main(int argc, const char **argv)
Expand Down
2 changes: 2 additions & 0 deletions t/helper/test-tool.h
@@ -1,4 +1,6 @@
#ifndef __TEST_TOOL_H__
#define __TEST_TOOL_H__

int cmd__chmtime(int argc, const char **argv);

#endif
2 changes: 1 addition & 1 deletion t/lib-git-svn.sh
Expand Up @@ -49,7 +49,7 @@ rawsvnrepo="$svnrepo"
svnrepo="file://$svnrepo"

poke() {
test-chmtime +1 "$1"
test-tool chmtime +1 "$1"
}

# We need this, because we should pass empty configuration directory to
Expand Down
12 changes: 6 additions & 6 deletions t/t1700-split-index.sh
Expand Up @@ -332,25 +332,25 @@ test_expect_success 'shared index files expire after 2 weeks by default' '
git update-index --add ten &&
test $(ls .git/sharedindex.* | wc -l) -gt 2 &&
just_under_2_weeks_ago=$((5-14*86400)) &&
test-chmtime =$just_under_2_weeks_ago .git/sharedindex.* &&
test-tool chmtime =$just_under_2_weeks_ago .git/sharedindex.* &&
: >eleven &&
git update-index --add eleven &&
test $(ls .git/sharedindex.* | wc -l) -gt 2 &&
just_over_2_weeks_ago=$((-1-14*86400)) &&
test-chmtime =$just_over_2_weeks_ago .git/sharedindex.* &&
test-tool chmtime =$just_over_2_weeks_ago .git/sharedindex.* &&
: >twelve &&
git update-index --add twelve &&
test $(ls .git/sharedindex.* | wc -l) -le 2
'

test_expect_success 'check splitIndex.sharedIndexExpire set to 16 days' '
git config splitIndex.sharedIndexExpire "16.days.ago" &&
test-chmtime =$just_over_2_weeks_ago .git/sharedindex.* &&
test-tool chmtime =$just_over_2_weeks_ago .git/sharedindex.* &&
: >thirteen &&
git update-index --add thirteen &&
test $(ls .git/sharedindex.* | wc -l) -gt 2 &&
just_over_16_days_ago=$((-1-16*86400)) &&
test-chmtime =$just_over_16_days_ago .git/sharedindex.* &&
test-tool chmtime =$just_over_16_days_ago .git/sharedindex.* &&
: >fourteen &&
git update-index --add fourteen &&
test $(ls .git/sharedindex.* | wc -l) -le 2
Expand All @@ -359,13 +359,13 @@ test_expect_success 'check splitIndex.sharedIndexExpire set to 16 days' '
test_expect_success 'check splitIndex.sharedIndexExpire set to "never" and "now"' '
git config splitIndex.sharedIndexExpire never &&
just_10_years_ago=$((-365*10*86400)) &&
test-chmtime =$just_10_years_ago .git/sharedindex.* &&
test-tool chmtime =$just_10_years_ago .git/sharedindex.* &&
: >fifteen &&
git update-index --add fifteen &&
test $(ls .git/sharedindex.* | wc -l) -gt 2 &&
git config splitIndex.sharedIndexExpire now &&
just_1_second_ago=-1 &&
test-chmtime =$just_1_second_ago .git/sharedindex.* &&
test-tool chmtime =$just_1_second_ago .git/sharedindex.* &&
: >sixteen &&
git update-index --add sixteen &&
test $(ls .git/sharedindex.* | wc -l) -le 2
Expand Down
4 changes: 2 additions & 2 deletions t/t2022-checkout-paths.sh
Expand Up @@ -68,13 +68,13 @@ test_expect_success 'do not touch files that are already up-to-date' '
git add file1 file2 &&
git commit -m base &&
echo modified >file1 &&
test-chmtime =1000000000 file2 &&
test-tool chmtime =1000000000 file2 &&
git update-index -q --refresh &&
git checkout HEAD -- file1 file2 &&
echo one >expect &&
test_cmp expect file1 &&
echo "1000000000 file2" >expect &&
test-chmtime -v +0 file2 >actual &&
test-tool chmtime -v +0 file2 >actual &&
test_cmp expect actual
'

Expand Down
2 changes: 1 addition & 1 deletion t/t3306-notes-prune.sh
Expand Up @@ -22,7 +22,7 @@ test_expect_success 'setup: create a few commits with notes' '
git commit -m 3rd &&
COMMIT_FILE=.git/objects/5e/e1c35e83ea47cd3cc4f8cbee0568915fbbbd29 &&
test -f $COMMIT_FILE &&
test-chmtime =+0 $COMMIT_FILE &&
test-tool chmtime =+0 $COMMIT_FILE &&
git notes add -m "Note #3"
'

Expand Down
4 changes: 2 additions & 2 deletions t/t3404-rebase-interactive.sh
Expand Up @@ -711,13 +711,13 @@ test_expect_success 'rebase -i continue with unstaged submodule' '
test_expect_success 'avoid unnecessary reset' '
git checkout master &&
git reset --hard &&
test-chmtime =123456789 file3 &&
test-tool chmtime =123456789 file3 &&
git update-index --refresh &&
HEAD=$(git rev-parse HEAD) &&
set_fake_editor &&
git rebase -i HEAD~4 &&
test $HEAD = $(git rev-parse HEAD) &&
MTIME=$(test-chmtime -v +0 file3 | sed 's/[^0-9].*$//') &&
MTIME=$(test-tool chmtime -v +0 file3 | sed 's/[^0-9].*$//') &&
test 123456789 = $MTIME
'

Expand Down
4 changes: 2 additions & 2 deletions t/t3418-rebase-continue.sh
Expand Up @@ -24,7 +24,7 @@ test_expect_success 'interactive rebase --continue works with touched file' '
git checkout master &&
FAKE_LINES="edit 1" git rebase -i HEAD^ &&
test-chmtime =-60 F1 &&
test-tool chmtime =-60 F1 &&
git rebase --continue
'

Expand All @@ -36,7 +36,7 @@ test_expect_success 'non-interactive rebase --continue works with touched file'
test_must_fail git rebase --onto master master topic &&
echo "Resolved" >F2 &&
git add F2 &&
test-chmtime =-60 F1 &&
test-tool chmtime =-60 F1 &&
git rebase --continue
'

Expand Down
2 changes: 1 addition & 1 deletion t/t3501-revert-cherry-pick.sh
Expand Up @@ -86,7 +86,7 @@ test_expect_success 'cherry-pick on stat-dirty working tree' '
(
cd copy &&
git checkout initial &&
test-chmtime +40 oops &&
test-tool chmtime +40 oops &&
git cherry-pick added
)
'
Expand Down
4 changes: 2 additions & 2 deletions t/t3510-cherry-pick-sequence.sh
Expand Up @@ -247,9 +247,9 @@ test_expect_success '--abort after last commit in sequence' '
test_expect_success 'cherry-pick does not implicitly stomp an existing operation' '
pristine_detach initial &&
test_expect_code 1 git cherry-pick base..anotherpick &&
test-chmtime -v +0 .git/sequencer >expect &&
test-tool chmtime -v +0 .git/sequencer >expect &&
test_expect_code 128 git cherry-pick unrelatedpick &&
test-chmtime -v +0 .git/sequencer >actual &&
test-tool chmtime -v +0 .git/sequencer >actual &&
test_cmp expect actual
'

Expand Down
2 changes: 1 addition & 1 deletion t/t3600-rm.sh
Expand Up @@ -232,7 +232,7 @@ test_expect_success 'Call "rm" from outside the work tree' '
test_expect_success 'refresh index before checking if it is up-to-date' '
git reset --hard &&
test-chmtime -86400 frotz/nitfol &&
test-tool chmtime -86400 frotz/nitfol &&
git rm frotz/nitfol &&
test ! -f frotz/nitfol
Expand Down
2 changes: 1 addition & 1 deletion t/t3700-add.sh
Expand Up @@ -187,7 +187,7 @@ test_expect_success 'git add --refresh with pathspec' '
echo >foo && echo >bar && echo >baz &&
git add foo bar baz && H=$(git rev-parse :foo) && git rm -f foo &&
echo "100644 $H 3 foo" | git update-index --index-info &&
test-chmtime -60 bar baz &&
test-tool chmtime -60 bar baz &&
>expect &&
git add --refresh bar >actual &&
test_cmp expect actual &&
Expand Down
2 changes: 1 addition & 1 deletion t/t4011-diff-symlink.sh
Expand Up @@ -73,7 +73,7 @@ test_expect_success 'diff identical, but newly created symlink and file' '
>expected &&
rm -f frotz nitfol &&
echo xyzzy >nitfol &&
test-chmtime +10 nitfol &&
test-tool chmtime +10 nitfol &&
if test_have_prereq SYMLINKS
then
ln -s xyzzy frotz
Expand Down
2 changes: 1 addition & 1 deletion t/t4013-diff-various.sh
Expand Up @@ -76,7 +76,7 @@ test_expect_success setup '
mkdir dir3 &&
cp dir/sub dir3/sub &&
test-chmtime +1 dir3/sub &&
test-tool chmtime +1 dir3/sub &&
git config log.showroot false &&
git commit --amend &&
Expand Down
2 changes: 1 addition & 1 deletion t/t4035-diff-quiet.sh
Expand Up @@ -147,7 +147,7 @@ test_expect_success 'git diff --ignore-all-space, both files outside repo' '
'

test_expect_success 'git diff --quiet ignores stat-change only entries' '
test-chmtime +10 a &&
test-tool chmtime +10 a &&
echo modified >>b &&
test_expect_code 1 git diff --quiet
'
Expand Down
4 changes: 2 additions & 2 deletions t/t4151-am-abort.sh
Expand Up @@ -171,7 +171,7 @@ test_expect_success 'am --skip leaves index stat info alone' '
git checkout -f --orphan skip-stat-info &&
git reset &&
test_commit skip-should-be-untouched &&
test-chmtime =0 skip-should-be-untouched.t &&
test-tool chmtime =0 skip-should-be-untouched.t &&
git update-index --refresh &&
git diff-files --exit-code --quiet &&
test_must_fail git am 0001-*.patch &&
Expand All @@ -183,7 +183,7 @@ test_expect_success 'am --abort leaves index stat info alone' '
git checkout -f --orphan abort-stat-info &&
git reset &&
test_commit abort-should-be-untouched &&
test-chmtime =0 abort-should-be-untouched.t &&
test-tool chmtime =0 abort-should-be-untouched.t &&
git update-index --refresh &&
git diff-files --exit-code --quiet &&
test_must_fail git am 0001-*.patch &&
Expand Down
22 changes: 11 additions & 11 deletions t/t4200-rerere.sh
Expand Up @@ -166,7 +166,7 @@ test_expect_success 'first postimage wins' '
git commit -q -a -m "prefer first over second" &&
test -f $rr/postimage &&
oldmtimepost=$(test-chmtime -v -60 $rr/postimage | cut -f 1) &&
oldmtimepost=$(test-tool chmtime -v -60 $rr/postimage | cut -f 1) &&
git checkout -b third master &&
git show second^:a1 | sed "s/To die: t/To die! T/" >a1 &&
Expand All @@ -179,7 +179,7 @@ test_expect_success 'first postimage wins' '
'

test_expect_success 'rerere updates postimage timestamp' '
newmtimepost=$(test-chmtime -v +0 $rr/postimage | cut -f 1) &&
newmtimepost=$(test-tool chmtime -v +0 $rr/postimage | cut -f 1) &&
test $oldmtimepost -lt $newmtimepost
'

Expand Down Expand Up @@ -220,9 +220,9 @@ test_expect_success 'set up for garbage collection tests' '
almost_60_days_ago=$((60-60*86400)) &&
just_over_60_days_ago=$((-1-60*86400)) &&
test-chmtime =$just_over_60_days_ago $rr/preimage &&
test-chmtime =$almost_60_days_ago $rr/postimage &&
test-chmtime =$almost_15_days_ago $rr2/preimage
test-tool chmtime =$just_over_60_days_ago $rr/preimage &&
test-tool chmtime =$almost_60_days_ago $rr/postimage &&
test-tool chmtime =$almost_15_days_ago $rr2/preimage
'

test_expect_success 'gc preserves young or recently used records' '
Expand All @@ -232,8 +232,8 @@ test_expect_success 'gc preserves young or recently used records' '
'

test_expect_success 'old records rest in peace' '
test-chmtime =$just_over_60_days_ago $rr/postimage &&
test-chmtime =$just_over_15_days_ago $rr2/preimage &&
test-tool chmtime =$just_over_60_days_ago $rr/postimage &&
test-tool chmtime =$just_over_15_days_ago $rr2/preimage &&
git rerere gc &&
! test -f $rr/preimage &&
! test -f $rr2/preimage
Expand All @@ -249,8 +249,8 @@ rerere_gc_custom_expiry_test () {
>"$rr/postimage" &&
two_days_ago=$((-2*86400)) &&
test-chmtime =$two_days_ago "$rr/preimage" &&
test-chmtime =$two_days_ago "$rr/postimage" &&
test-tool chmtime =$two_days_ago "$rr/preimage" &&
test-tool chmtime =$two_days_ago "$rr/postimage" &&
find .git/rr-cache -type f | sort >original &&
Expand Down Expand Up @@ -512,7 +512,7 @@ test_expect_success 'multiple identical conflicts' '
count_pre_post 2 0 &&
# Pretend that the conflicts were made quite some time ago
find .git/rr-cache/ -type f | xargs test-chmtime -172800 &&
find .git/rr-cache/ -type f | xargs test-tool chmtime -172800 &&
# Unresolved entries have not expired yet
git -c gc.rerereresolved=5 -c gc.rerereunresolved=5 rerere gc &&
Expand Down Expand Up @@ -568,7 +568,7 @@ test_expect_success 'multiple identical conflicts' '
git rerere &&
# Pretend that the resolutions are old again
find .git/rr-cache/ -type f | xargs test-chmtime -172800 &&
find .git/rr-cache/ -type f | xargs test-tool chmtime -172800 &&
# Resolved entries have not expired yet
git -c gc.rerereresolved=5 -c gc.rerereunresolved=5 rerere gc &&
Expand Down
2 changes: 1 addition & 1 deletion t/t5000-tar-tree.sh
Expand Up @@ -192,7 +192,7 @@ test_expect_success \
'validate file modification time' \
'mkdir extract &&
"$TAR" xf b.tar -C extract a/a &&
test-chmtime -v +0 extract/a/a |cut -f 1 >b.mtime &&
test-tool chmtime -v +0 extract/a/a |cut -f 1 >b.mtime &&
echo "1117231200" >expected.mtime &&
test_cmp expected.mtime b.mtime'

Expand Down

0 comments on commit 0e49649

Please sign in to comment.