aboutsummaryrefslogtreecommitdiff
path: root/tests/remotes.sh
blob: 06d3fdc51e1d3f4993da2ef4336d8ee208df7903 (plain) (blame)
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/bin/sh
set -u

. aux/tests-lib.sh

TEST_PREFIX="$PWD/tests/prefix/$(uuidgen)"
make PREFIX="$TEST_PREFIX" install 1>/dev/null
PATH="$PWD/tests:$TEST_PREFIX/bin:$PATH"

new_repo() {
	REPO="$PWD/tests/remotes/$(uuidgen)"
	mkdir -p "$REPO"
	cd "$REPO" || exit 1
	git init > /dev/null
	git remote add origin "$1"
	echo '' > f.txt
	git add f.txt
	git commit -qam f.txt
}

test_supported_remotes() {
	testing 'supported remotes'

	OUT="$(mktemp)"
	ERR="$(mktemp)"
	new_repo git://euandreh.xyz/remembering
	LANG=POSIX git permalink README.md 123 1>"$OUT" 2>"$ERR"
	STATUS=$?
	assert_status 0
	assert_empty_stdout
	assert_fgrep_stderr 'Opening https://git.euandreh.xyz'
	assert_fgrep_stderr 'xdg-open: https://git.euandreh.xyz'
	cd - > /dev/null || exit 1

	OUT="$(mktemp)"
	ERR="$(mktemp)"
	new_repo https://git.sr.ht/~sircmpwn/ctools
	git permalink -p README.md 123 1>"$OUT" 2>"$ERR"
	STATUS=$?
	assert_status 0
	assert_fgrep_stdout 'https://git.sr.ht'
	assert_empty_stderr
	cd - > /dev/null || exit 1

	OUT="$(mktemp)"
	ERR="$(mktemp)"
	new_repo https://git.kernel.org/pub/scm/git/git.git
	LANG=POSIX git permalink README.md 123 1>"$OUT" 2>"$ERR"
	STATUS=$?
	assert_status 0
	assert_empty_stdout
	assert_fgrep_stderr 'Opening https://git.kernel.org'
	assert_fgrep_stderr 'xdg-open: https://git.kernel.org'
	cd - > /dev/null || exit 1

	OUT="$(mktemp)"
	ERR="$(mktemp)"
	new_repo https://git.savannah.gnu.org/guix.git
	git permalink -p README.md 123 1>"$OUT" 2>"$ERR"
	STATUS=$?
	assert_status 0
	assert_fgrep_stdout 'https://git.savannah.gnu.org'
	assert_empty_stderr
	cd - > /dev/null || exit 1

	OUT="$(mktemp)"
	ERR="$(mktemp)"
	new_repo https://notabug.org/cwebber/guile-gcrypt
	LANG=POSIX git permalink README.md 123 1>"$OUT" 2>"$ERR"
	STATUS=$?
	assert_status 0
	assert_empty_stdout
	assert_fgrep_stderr 'Opening https://notabug.org'
	assert_fgrep_stderr 'xdg-open: https://notabug.org'
	cd - > /dev/null || exit 1

	OUT="$(mktemp)"
	ERR="$(mktemp)"
	new_repo https://codeberg.org/dnkl/yambar
	git permalink -p README.md 123 1>"$OUT" 2>"$ERR"
	STATUS=$?
	assert_status 0
	assert_fgrep_stdout 'https://codeberg.org'
	assert_empty_stderr
	cd - > /dev/null || exit 1

	OUT="$(mktemp)"
	ERR="$(mktemp)"
	new_repo https://bitbucket.org/uprojects/jsmn
	LANG=POSIX git permalink README.md 123 1>"$OUT" 2>"$ERR"
	STATUS=$?
	assert_status 0
	assert_empty_stdout
	assert_fgrep_stderr 'Opening https://bitbucket.org'
	assert_fgrep_stderr 'xdg-open: https://bitbucket.org'
	cd - > /dev/null || exit 1

	OUT="$(mktemp)"
	ERR="$(mktemp)"
	new_repo https://pagure.io/aquedoc
	git permalink -p README.md 123 1>"$OUT" 2>"$ERR"
	STATUS=$?
	assert_status 0
	assert_fgrep_stdout 'https://pagure.io'
	assert_empty_stderr
	cd - > /dev/null || exit 1

	OUT="$(mktemp)"
	ERR="$(mktemp)"
	new_repo https://gitlab.com/nonguix/nonguix
	LANG=POSIX git permalink README.md 123 1>"$OUT" 2>"$ERR"
	STATUS=$?
	assert_status 0
	assert_empty_stdout
	assert_fgrep_stderr 'Opening https://gitlab.com/nonguix/nonguix'
	assert_fgrep_stderr 'xdg-open: https://gitlab.com/nonguix/nonguix'
	cd - > /dev/null || exit 1

	OUT="$(mktemp)"
	ERR="$(mktemp)"
	new_repo https://github.com/skeeto/elfeed
	git permalink -p README.md 123 1>"$OUT" 2>"$ERR"
	STATUS=$?
	assert_status 0
	assert_fgrep_stdout 'https://github.com'
	assert_empty_stderr
	cd - > /dev/null || exit 1

	test_ok
}

test_unsupported_remote() {
	testing 'unsupported remotes'

	OUT="$(mktemp)"
	ERR="$(mktemp)"
	new_repo https://example.com/a/b
	LANG=POSIX git permalink README.md 123 1>"$OUT" 2>"$ERR"
	STATUS=$?
	assert_status 1
	assert_empty_stdout
	assert_fgrep_stderr 'Unsupported origin: https://example.com'

	OUT="$(mktemp)"
	ERR="$(mktemp)"
	git config git-permalink.template-commit-file 'before %s middle %s after'
	git permalink -p README.md 123 1>"$OUT" 2>"$ERR"
	STATUS=$?
	assert_status 0
	assert_grep_stdout 'before .+ middle README.md after'
	assert_empty_stderr

	OUT="$(mktemp)"
	ERR="$(mktemp)"
	git config --unset git-permalink.template-commit-file
	git config         git-permalink.template-file-commit 'before %s middle %s after'
	git permalink -p README.md 123 1>"$OUT" 2>"$ERR"
	STATUS=$?
	assert_status 0
	assert_grep_stdout 'before README.md middle .+ after'
	assert_empty_stderr

	OUT="$(mktemp)"
	ERR="$(mktemp)"
	git config --unset git-permalink.template-file-commit
	LANG=POSIX git permalink -p README.md 123 1>"$OUT" 2>"$ERR"
	STATUS=$?
	assert_status 1
	assert_empty_stdout
	assert_fgrep_stderr 'Unsupported origin: https://example.com'

	test_ok
}

test_supported_remotes
test_unsupported_remote