Skip to content

Commit 833bbf7

Browse files
committed
add test for recursive submodules for golang
1 parent 34e0ff3 commit 833bbf7

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

tests/repository_test.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import re_assert
1111

1212
import pre_commit.constants as C
13+
from pre_commit import git
1314
from pre_commit.clientlib import CONFIG_SCHEMA
1415
from pre_commit.clientlib import load_manifest
1516
from pre_commit.envcontext import envcontext
@@ -346,6 +347,59 @@ def test_golang_hook_still_works_when_gobin_is_set(tempdir_factory, store):
346347
assert os.listdir(gobin_dir) == []
347348

348349

350+
def test_golang_with_recursive_submodule(tmpdir, tempdir_factory, store):
351+
sub_go = '''\
352+
package sub
353+
354+
import "fmt"
355+
356+
func Func() {
357+
fmt.Println("hello hello world")
358+
}
359+
'''
360+
sub = tmpdir.join('sub').ensure_dir()
361+
sub.join('sub.go').write(sub_go)
362+
cmd_output('git', '-C', str(sub), 'init', '.')
363+
cmd_output('git', '-C', str(sub), 'add', '.')
364+
git.commit(str(sub))
365+
366+
pre_commit_hooks = '''\
367+
- id: example
368+
name: example
369+
entry: example
370+
language: golang
371+
verbose: true
372+
'''
373+
go_mod = '''\
374+
module github.com/asottile/example
375+
376+
go 1.14
377+
'''
378+
main_go = '''\
379+
package main
380+
381+
import "github.com/asottile/example/sub"
382+
383+
func main() {
384+
sub.Func()
385+
}
386+
'''
387+
repo = tmpdir.join('repo').ensure_dir()
388+
repo.join('.pre-commit-hooks.yaml').write(pre_commit_hooks)
389+
repo.join('go.mod').write(go_mod)
390+
repo.join('main.go').write(main_go)
391+
cmd_output('git', '-C', str(repo), 'init', '.')
392+
cmd_output('git', '-C', str(repo), 'add', '.')
393+
cmd_output('git', '-C', str(repo), 'submodule', 'add', str(sub), 'sub')
394+
git.commit(str(repo))
395+
396+
config = make_config_from_repo(str(repo))
397+
hook = _get_hook(config, store, 'example')
398+
ret, out = _hook_run(hook, (), color=False)
399+
assert ret == 0
400+
assert _norm_out(out) == b'hello hello world\n'
401+
402+
349403
def test_rust_hook(tempdir_factory, store):
350404
_test_hook_repo(
351405
tempdir_factory, store, 'rust_hooks_repo',

0 commit comments

Comments
 (0)