|
10 | 10 | import re_assert |
11 | 11 |
|
12 | 12 | import pre_commit.constants as C |
13 | | -from pre_commit import git |
14 | 13 | from pre_commit.clientlib import CONFIG_SCHEMA |
15 | 14 | from pre_commit.clientlib import load_manifest |
16 | | -from pre_commit.envcontext import envcontext |
17 | 15 | from pre_commit.hook import Hook |
18 | | -from pre_commit.languages import golang |
19 | 16 | from pre_commit.languages import helpers |
20 | 17 | from pre_commit.languages import python |
21 | 18 | from pre_commit.languages.all import languages |
@@ -169,92 +166,6 @@ def test_system_hook_with_spaces(tempdir_factory, store): |
169 | 166 | ) |
170 | 167 |
|
171 | 168 |
|
172 | | -def test_golang_system_hook(tempdir_factory, store): |
173 | | - _test_hook_repo( |
174 | | - tempdir_factory, store, 'golang_hooks_repo', |
175 | | - 'golang-hook', ['system'], b'hello world from system\n', |
176 | | - config_kwargs={ |
177 | | - 'hooks': [{ |
178 | | - 'id': 'golang-hook', |
179 | | - 'language_version': 'system', |
180 | | - }], |
181 | | - }, |
182 | | - ) |
183 | | - |
184 | | - |
185 | | -def test_golang_versioned_hook(tempdir_factory, store): |
186 | | - _test_hook_repo( |
187 | | - tempdir_factory, store, 'golang_hooks_repo', |
188 | | - 'golang-hook', [], b'hello world from go1.18.4\n', |
189 | | - config_kwargs={ |
190 | | - 'hooks': [{ |
191 | | - 'id': 'golang-hook', |
192 | | - 'language_version': '1.18.4', |
193 | | - }], |
194 | | - }, |
195 | | - ) |
196 | | - |
197 | | - |
198 | | -def test_golang_hook_still_works_when_gobin_is_set(tempdir_factory, store): |
199 | | - gobin_dir = tempdir_factory.get() |
200 | | - with envcontext((('GOBIN', gobin_dir),)): |
201 | | - test_golang_system_hook(tempdir_factory, store) |
202 | | - assert os.listdir(gobin_dir) == [] |
203 | | - |
204 | | - |
205 | | -def test_golang_with_recursive_submodule(tmpdir, tempdir_factory, store): |
206 | | - sub_go = '''\ |
207 | | -package sub |
208 | | -
|
209 | | -import "fmt" |
210 | | -
|
211 | | -func Func() { |
212 | | - fmt.Println("hello hello world") |
213 | | -} |
214 | | -''' |
215 | | - sub = tmpdir.join('sub').ensure_dir() |
216 | | - sub.join('sub.go').write(sub_go) |
217 | | - cmd_output('git', '-C', str(sub), 'init', '.') |
218 | | - cmd_output('git', '-C', str(sub), 'add', '.') |
219 | | - git.commit(str(sub)) |
220 | | - |
221 | | - pre_commit_hooks = '''\ |
222 | | -- id: example |
223 | | - name: example |
224 | | - entry: example |
225 | | - language: golang |
226 | | - verbose: true |
227 | | -''' |
228 | | - go_mod = '''\ |
229 | | -module github.com/asottile/example |
230 | | -
|
231 | | -go 1.14 |
232 | | -''' |
233 | | - main_go = '''\ |
234 | | -package main |
235 | | -
|
236 | | -import "github.com/asottile/example/sub" |
237 | | -
|
238 | | -func main() { |
239 | | - sub.Func() |
240 | | -} |
241 | | -''' |
242 | | - repo = tmpdir.join('repo').ensure_dir() |
243 | | - repo.join('.pre-commit-hooks.yaml').write(pre_commit_hooks) |
244 | | - repo.join('go.mod').write(go_mod) |
245 | | - repo.join('main.go').write(main_go) |
246 | | - cmd_output('git', '-C', str(repo), 'init', '.') |
247 | | - cmd_output('git', '-C', str(repo), 'add', '.') |
248 | | - cmd_output('git', '-C', str(repo), 'submodule', 'add', str(sub), 'sub') |
249 | | - git.commit(str(repo)) |
250 | | - |
251 | | - config = make_config_from_repo(str(repo)) |
252 | | - hook = _get_hook(config, store, 'example') |
253 | | - ret, out = _hook_run(hook, (), color=False) |
254 | | - assert ret == 0 |
255 | | - assert _norm_out(out) == b'hello hello world\n' |
256 | | - |
257 | | - |
258 | 169 | def test_missing_executable(tempdir_factory, store): |
259 | 170 | _test_hook_repo( |
260 | 171 | tempdir_factory, store, 'not_found_exe', |
@@ -419,43 +330,6 @@ def test_repository_state_compatibility(tempdir_factory, store, v): |
419 | 330 | assert _hook_installed(hook) is True |
420 | 331 |
|
421 | 332 |
|
422 | | -def test_additional_golang_dependencies_installed( |
423 | | - tempdir_factory, store, |
424 | | -): |
425 | | - path = make_repo(tempdir_factory, 'golang_hooks_repo') |
426 | | - config = make_config_from_repo(path) |
427 | | - # A small go package |
428 | | - deps = ['golang.org/x/example/hello@latest'] |
429 | | - config['hooks'][0]['additional_dependencies'] = deps |
430 | | - hook = _get_hook(config, store, 'golang-hook') |
431 | | - envdir = helpers.environment_dir( |
432 | | - hook.prefix, |
433 | | - golang.ENVIRONMENT_DIR, |
434 | | - golang.get_default_version(), |
435 | | - ) |
436 | | - binaries = os.listdir(os.path.join(envdir, 'bin')) |
437 | | - # normalize for windows |
438 | | - binaries = [os.path.splitext(binary)[0] for binary in binaries] |
439 | | - assert 'hello' in binaries |
440 | | - |
441 | | - |
442 | | -def test_local_golang_additional_dependencies(store): |
443 | | - config = { |
444 | | - 'repo': 'local', |
445 | | - 'hooks': [{ |
446 | | - 'id': 'hello', |
447 | | - 'name': 'hello', |
448 | | - 'entry': 'hello', |
449 | | - 'language': 'golang', |
450 | | - 'additional_dependencies': ['golang.org/x/example/hello@latest'], |
451 | | - }], |
452 | | - } |
453 | | - hook = _get_hook(config, store, 'hello') |
454 | | - ret, out = _hook_run(hook, (), color=False) |
455 | | - assert ret == 0 |
456 | | - assert _norm_out(out) == b'Hello, Go examples!\n' |
457 | | - |
458 | | - |
459 | 333 | def test_fail_hooks(store): |
460 | 334 | config = { |
461 | 335 | 'repo': 'local', |
|
0 commit comments