File: git-browse.bats

package info (click to toggle)
git-extras 7.4.0-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 2,120 kB
  • sloc: sh: 4,312; python: 994; makefile: 146
file content (123 lines) | stat: -rw-r--r-- 3,167 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
113
114
115
116
117
118
119
120
121
122
123
# shellcheck shell=bash

source "$BATS_TEST_DIRNAME/test_util.sh"

setup_file() {
	test_util.setup_file

	PATH="$BATS_TEST_DIRNAME/bin:$PATH"
}

setup() {
	test_util.cd_test

	test_util.git_init
	touch ./browse_this
	git add ./browse_this
	git commit -m 'Add test file'
}

get_file_uri() {
	local mode=$1
	local filename=$2

	local commit_hash=
	commit_hash=$(git rev-parse HEAD)
	if [ "$mode" = 'github' ]; then
		REPLY="https://github.com/tj/git-extras/blob/$commit_hash/${filename}"
	elif [ "$mode" = 'gitlab' ]; then
		REPLY="https://gitlab.com/tj/git-extras/-/blob/${commit_hash}/${filename}"
	elif [ "$mode" = 'bitbucket' ]; then
		REPLY="https://bitbucket.org/tj/git-extras/src/${commit_hash}/${filename}"
	fi
}

@test "works with mac and github" {
	get_file_uri github ./browse_this
	local expected_url=$REPLY

	git remote add upstream https://github.com/tj/git-extras
	OSTYPE=darwin run git browse upstream ./browse_this
	assert_output "open $expected_url"
	assert_success
}

@test "works with mac and gitlab" {
	get_file_uri gitlab ./browse_this
	local expected_url=$REPLY

	git remote add upstream https://gitlab.com/tj/git-extras
	OSTYPE=darwin run git browse upstream ./browse_this
	assert_output "open $expected_url"
	assert_success
}

@test "works with mac and bitbucket" {
	get_file_uri bitbucket ./browse_this
	local expected_url=$REPLY

	git remote add upstream https://bitbucket.org/tj/git-extras
	OSTYPE=darwin run git browse upstream ./browse_this
	assert_output "open $expected_url"
	assert_success
}

@test "works with windows and github" {
	get_file_uri github ./browse_this
	local expected_url=$REPLY

	git remote add upstream https://github.com/tj/git-extras
	OSTYPE=msys run git browse upstream ./browse_this
	assert_output "start $expected_url"
	assert_success
}

@test "works with windows and gitlab" {
	get_file_uri gitlab ./browse_this
	local expected_url=$REPLY

	git remote add upstream https://gitlab.com/tj/git-extras
	OSTYPE=msys run git browse upstream ./browse_this
	assert_output "start $expected_url"
	assert_success
}

@test "works with windows and bitbucket" {
	get_file_uri bitbucket ./browse_this
	local expected_url=$REPLY

	git remote add upstream https://bitbucket.org/tj/git-extras
	OSTYPE=msys run git browse upstream ./browse_this
	assert_output "start $expected_url"
	assert_success
}

@test "works with linux and github" {
	get_file_uri github ./browse_this
	local expected_url=$REPLY

	git remote add upstream https://github.com/tj/git-extras
	OSTYPE=linux-gnu run git browse upstream ./browse_this
	assert_output "xdg-open $expected_url"
	assert_success
}

@test "works with linux and gitlab" {
	get_file_uri gitlab ./browse_this
	local expected_url=$REPLY

	git remote add upstream https://gitlab.com/tj/git-extras
	OSTYPE=linux-gnu run git browse upstream ./browse_this
	assert_output "xdg-open $expected_url"
	assert_success
}

@test "works with linux and bitbucket" {
	get_file_uri bitbucket ./browse_this
	local expected_url=$REPLY

	git remote add upstream https://bitbucket.org/tj/git-extras
	OSTYPE=linux-gnu run git browse upstream ./browse_this
	assert_output "xdg-open $expected_url"
	assert_success
}