File: testutil

package info (click to toggle)
hg-git 1.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,244 kB
  • sloc: python: 8,702; sh: 185; makefile: 23
file content (112 lines) | stat: -rwxr-xr-x 3,241 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/bin/sh

# This file holds logic that is used in many tests.
# It can be called in a test like this:
#  $ . "$TESTDIR/testutil"

# force terminal width, otherwise terminal width may cause progress
# tests to fail
export COLUMNS=80

# our test suite relies on being able to create symlinks, even on
# Windows
export MSYS=winsymlinks:nativestrict

# Always trust root - which may own the repository we're working off
echo "[trusted]" >> $HGRCPATH
echo "users=root" >> $HGRCPATH

# silence some output related to templates
mkdir -p $TESTTMP/gittemplates
export GIT_TEMPLATE_DIR=$TESTTMP/gittemplates

# Activate extensions
echo "[extensions]" >> $HGRCPATH
echo "hggit=$(echo $(dirname $TESTDIR))/hggit" >> $HGRCPATH

# Enable git subrepository
echo '[subrepos]' >> $HGRCPATH
echo 'git:allowed = yes' >> $HGRCPATH

# silence warning from recent git
cat >> $TESTTMP/.gitconfig <<EOF
[init]
defaultBranch = master
[protocol.file]
allow = always
EOF

# Standard checks for external dependencies
# We use the git command-line client and dulwich in pretty much all the tests.
# Thus, to avoid repetitively declaring that requirement in almost every test,
# we just call the checks in all tests that include this library.
"$TESTDIR/hghave" dulwich || exit 80
"$TESTDIR/hghave" git || exit 80

GIT_AUTHOR_NAME='test'; export GIT_AUTHOR_NAME
GIT_AUTHOR_EMAIL='test@example.org'; export GIT_AUTHOR_EMAIL
GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0000"; export GIT_AUTHOR_DATE
GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME"; export GIT_COMMITTER_NAME
GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL"; export GIT_COMMITTER_EMAIL
GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"; export GIT_COMMITTER_DATE

# Functions to commit and tag in Mercurial and Git in a predictable manner
count=10

fn_get_date() {
    h=$(expr $count / 60 / 60)
    m=$(expr $count / 60 % 60)
    s=$(expr $count % 60)
    printf "2007-01-01 %02d:%02d:%02d +0000" $h $m $s
}

fn_git_commit() {
    GIT_AUTHOR_DATE="$(fn_get_date)"
    GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
    git commit "$@" >/dev/null || echo "git commit error"
    count=`expr $count + 1`
}

fn_git_rebase() {
    GIT_AUTHOR_DATE="$(fn_get_date)"
    GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
    git rebase --quiet "$@" >/dev/null || echo "git rebase error"
    count=`expr $count + 1`
}

fn_hg_commit() {
    HGDATE="$(fn_get_date)"
    hg commit -d "$HGDATE" "$@" >/dev/null || echo "hg commit error"
    count=`expr $count + 1`
}

fn_hg_commitextra() {
    HGDATE="$(fn_get_date)"
    hg --config extensions.commitextra=$TESTDIR/testlib/ext-commit-extra.py \
       commitextra -d "$HGDATE" "$@" >/dev/null || echo "hg commit error"
    count=`expr $count + 1`
}

fn_git_tag() {
    GIT_AUTHOR_DATE="$(fn_get_date)"
    GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
    git tag "$@" >/dev/null || echo "git tag error"
    count=`expr $count + 1`
}

fn_hg_tag() {
    HGDATE="$(fn_get_date)"
    hg tag -d "$HGDATE" "$@" >/dev/null || echo "hg tag error"
    count=`expr $count + 1`
}

fn_touch_escaped() {
    python - "$@" <<EOF
import os, sys
for p in sys.argv[1:]:
  p = p.encode('ascii').decode('unicode_escape').encode('utf-8')
  if b'/' in p and not os.path.exists(os.path.dirname(p)):
    os.makedirs(os.path.dirname(p))
  open(p, 'w')
EOF
}