Skip to content

Commit c5c2f21

Browse files
Vampiretnyblom
authored andcommitted
Add Bats tests
1 parent cac4fde commit c5c2f21

28 files changed

+248
-1
lines changed

.github/workflows/build.yaml

+7-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ jobs:
3737
qtbase5-dev
3838
3939
- name: 'Checkout Git branch'
40-
uses: actions/checkout@v2.0.0
40+
uses: actions/checkout@v2
41+
with:
42+
submodules: true
4143

4244
- name: 'Configure'
4345
run: |-
@@ -47,6 +49,10 @@ jobs:
4749
run: |-
4850
make
4951
52+
- name: 'Test'
53+
run: |-
54+
./test.sh --no-make
55+
5056
- name: 'Install'
5157
run: |-
5258
set -e

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ Makefile
22
*~
33
*.o
44
svn-all-fast-export
5+
svn-all-fast-export.exe
56
src/local-config.pri
7+
/build/

.gitmodules

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[submodule "test/libs/bats-core"]
2+
path = test/libs/bats-core
3+
url = https://github.com/bats-core/bats-core
4+
[submodule "test/libs/bats-assert"]
5+
path = test/libs/bats-assert
6+
url = https://github.com/bats-core/bats-assert
7+
[submodule "test/libs/bats-support"]
8+
path = test/libs/bats-support
9+
url = https://github.com/bats-core/bats-support
10+
[submodule "test/libs/bats-file"]
11+
path = test/libs/bats-file
12+
url = https://github.com/tralston/bats-file

README.md

+13
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,19 @@ Run `qmake && make`. You get `./svn-all-fast-export`.
3333
You will need to have some packages to compile it. For Ubuntu distros, use this command to install them all:
3434
`sudo apt-get install build-essential subversion git qtchooser qt5-default libapr1 libapr1-dev libsvn-dev`
3535

36+
To run all tests you can simply call the `test.sh` script in the root directory.
37+
This will run all [Bats](https://github.com/bats-core/bats-core) based tests
38+
found in `.bats` files in the directory `test`. Running the script will automatically
39+
execute `qmake` and `make` first to build the current code if necessary.
40+
If you want to run tests without running make, you can give `--no-make` as first parameter.
41+
If you want to only run a subset of the tests, you can specify the base-name of one
42+
or multiple `.bats` files to only run these tests like `./test.sh command-line svn-ignore`.
43+
If you want to investigate the temporary files generated during a test run,
44+
you can set the environment variables `BATSLIB_TEMP_PRESERVE=1` or `BATSLIB_TEMP_PRESERVE_ON_FAILURE=1`.
45+
So if for example some test in `svn-ignore.bats` failed, you can investigate the failed case like
46+
`BATSLIB_TEMP_PRESERVE_ON_FAILURE=1 ./test.sh --no-make svn-ignore` and then look
47+
in `build/tmp` to investigate the situation.
48+
3649
KDE
3750
---
3851
there is a repository kde-ruleset which has several example files and one file that should become the final ruleset for the whole of KDE called 'kde-rules-main'.

test.sh

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
# Ensure needed tools are present
6+
svn --version >/dev/null
7+
git --version >/dev/null
8+
9+
# Determine SCRIPT_DIR
10+
# Resolve links: $0 may be a link
11+
PRG="$0"
12+
# Need this for relative symlinks.
13+
while [ -h "$PRG" ]; do
14+
ls=$(ls -ld "$PRG")
15+
link=$(expr "$ls" : '.*-> \(.*\)$')
16+
if expr "$link" : '/.*' >/dev/null; then
17+
PRG="$link"
18+
else
19+
PRG=$(dirname "$PRG")"/$link"
20+
fi
21+
done
22+
cd "$(dirname "$PRG")/" >/dev/null
23+
SCRIPT_DIR="$(pwd -P)"
24+
25+
if [ "${1-}" == "--no-make" ]; then
26+
shift
27+
else
28+
qmake
29+
make
30+
fi
31+
32+
if [ $# -eq 0 ]; then
33+
set -- test
34+
else
35+
set -- "${@/#/test/}"
36+
set -- "${@/%/.bats}"
37+
fi
38+
39+
mkdir -p "$SCRIPT_DIR/build/tmp"
40+
TMPDIR="$SCRIPT_DIR/build/tmp" test/libs/bats-core/bin/bats "$@"

test/base-fixture/README.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
This is a Subversion repository; use the 'svnadmin' and 'svnlook'
2+
tools to examine it. Do not add, delete, or modify files here
3+
unless you know how to avoid corrupting the repository.
4+
5+
Visit http://subversion.apache.org/ for more information.

test/base-fixture/db/current

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0

test/base-fixture/db/format

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
7
2+
layout sharded 1000
3+
addressing logical

test/base-fixture/db/fs-type

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fsfs

test/base-fixture/db/min-unpacked-rev

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0

test/base-fixture/db/revprops/0/0

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
K 8
2+
svn:date
3+
V 27
4+
2020-04-14T02:34:44.217594Z
5+
END

test/base-fixture/db/revs/0/0

253 Bytes
Binary file not shown.

test/base-fixture/db/transactions/.gitignore

Whitespace-only changes.

test/base-fixture/db/txn-current

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0

test/base-fixture/db/txn-current-lock

Whitespace-only changes.

test/base-fixture/db/txn-protorevs/.gitignore

Whitespace-only changes.

test/base-fixture/db/uuid

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
800c7d3e-7df8-11ea-8a4d-cdbd2a1a7b77
2+
800c7e56-7df8-11ea-8a4d-cdbd2a1a7b77

test/base-fixture/db/write-lock

Whitespace-only changes.

test/base-fixture/format

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
5

test/base-fixture/locks/db-logs.lock

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This file is not used by Subversion 1.3.x or later.
2+
However, its existence is required for compatibility with
3+
Subversion 1.2.x or earlier.

test/base-fixture/locks/db.lock

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This file is not used by Subversion 1.3.x or later.
2+
However, its existence is required for compatibility with
3+
Subversion 1.2.x or earlier.

test/command-line.bats

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
load 'common'
2+
3+
setup() {
4+
: # suppress common setup, no repository needed
5+
}
6+
7+
@test 'specifying version parameter should output version and exit with 0 no matter what' {
8+
run svn2git --version --non-existing repo-a repo-b
9+
assert_success
10+
assert_output --partial 'Git version:'
11+
12+
run svn2git --non-existing repo-a --version repo-b
13+
assert_success
14+
assert_output --partial 'Git version:'
15+
16+
run svn2git --non-existing repo-a repo-b --version
17+
assert_success
18+
assert_output --partial 'Git version:'
19+
20+
run svn2git -v --non-existing repo-a repo-b
21+
assert_success
22+
assert_output --partial 'Git version:'
23+
24+
run svn2git --non-existing repo-a -v repo-b
25+
assert_success
26+
assert_output --partial 'Git version:'
27+
28+
run svn2git --non-existing repo-a repo-b -v
29+
assert_success
30+
assert_output --partial 'Git version:'
31+
}
32+
33+
@test 'specifying help parameter should output usage and exit with 0 no matter what' {
34+
run svn2git --help --non-existing repo-a repo-b
35+
assert_success
36+
assert_output --partial 'Usage:'
37+
38+
run svn2git --non-existing repo-a --help repo-b
39+
assert_success
40+
assert_output --partial 'Usage:'
41+
42+
run svn2git --non-existing repo-a repo-b --help
43+
assert_success
44+
assert_output --partial 'Usage:'
45+
46+
run svn2git -h --non-existing repo-a repo-b
47+
assert_success
48+
assert_output --partial 'Usage:'
49+
50+
run svn2git --non-existing repo-a -h repo-b
51+
assert_success
52+
assert_output --partial 'Usage:'
53+
54+
run svn2git --non-existing repo-a repo-b -h
55+
assert_success
56+
assert_output --partial 'Usage:'
57+
}

test/common.bash

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
load 'libs/bats-support/load'
2+
load 'libs/bats-assert/load'
3+
load 'libs/bats-file/load'
4+
5+
setup() {
6+
commonSetup
7+
}
8+
9+
commonSetup() {
10+
TEST_TEMP_DIR="$(temp_make --prefix 'svn2git-')"
11+
BATSLIB_FILE_PATH_REM="#${TEST_TEMP_DIR}"
12+
BATSLIB_FILE_PATH_ADD='<temp>'
13+
14+
SVN_REPO="$TEST_TEMP_DIR/svn-repo"
15+
SVN_WORKTREE="$TEST_TEMP_DIR/svn-worktree"
16+
17+
cp -a "$BATS_TEST_DIRNAME/base-fixture" "$SVN_REPO"
18+
svn checkout "file:///$SVN_REPO" "$SVN_WORKTREE"
19+
cd "$SVN_WORKTREE"
20+
}
21+
22+
teardown() {
23+
commonTeardown
24+
}
25+
26+
commonTeardown() {
27+
if [ -n "${TEST_TEMP_DIR-}" ]; then
28+
temp_del "$TEST_TEMP_DIR"
29+
fi
30+
}
31+
32+
svn2git() {
33+
"$BATS_TEST_DIRNAME/../svn-all-fast-export" "$@"
34+
}

test/libs/bats-assert

Submodule bats-assert added at d750c5a

test/libs/bats-core

Submodule bats-core added at c706d14

test/libs/bats-file

Submodule bats-file added at 1b2ad14

test/libs/bats-support

Submodule bats-support added at 24a72e1

test/svn-ignore.bats

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
load 'common'
2+
3+
@test 'svn:ignore entries should only ignore matching direct children' {
4+
svn mkdir dir-a
5+
svn commit -m 'add dir-a'
6+
svn update
7+
svn propset svn:ignore $'ignore-a\nignore-b' dir-a
8+
svn commit -m 'ignore ignore-a and ignore-b on dir-a'
9+
10+
cd "$TEST_TEMP_DIR"
11+
svn2git "$SVN_REPO" --svn-ignore --rules <(echo "
12+
create repository git-repo
13+
end repository
14+
15+
match /([^/]+(/|$))
16+
repository git-repo
17+
branch master
18+
prefix \1
19+
end match
20+
")
21+
22+
assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" "$(cat <<-EOF
23+
/ignore-a
24+
/ignore-b
25+
EOF
26+
)"
27+
}
28+
29+
@test 'svn:global-ignores entries should ignore all matching descendents' {
30+
svn mkdir dir-a
31+
svn commit -m 'add dir-a'
32+
svn update
33+
svn propset svn:global-ignores $'ignore-a\nignore-b' dir-a
34+
svn commit -m 'ignore ignore-a and ignore-b on dir-a and descendents'
35+
36+
cd "$TEST_TEMP_DIR"
37+
svn2git "$SVN_REPO" --svn-ignore --rules <(echo "
38+
create repository git-repo
39+
end repository
40+
41+
match /([^/]+(/|$))
42+
repository git-repo
43+
branch master
44+
prefix \1
45+
end match
46+
")
47+
48+
assert_equal "$(git -C git-repo show master:dir-a/.gitignore)" "$(cat <<-EOF
49+
ignore-a
50+
ignore-b
51+
EOF
52+
)"
53+
}

0 commit comments

Comments
 (0)