File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change 1+ defmodule Mix.Tasks.InstallTest do
2+ @ moduledoc false
3+
4+ use ExUnit.Case , async: false
5+ use GitHooks.TestSupport.ConfigCase
6+
7+ alias Mix.Tasks.GitHooks.Install
8+ alias GitHooks.Git.Path , as: GitPath
9+
10+ @ tag capture_log: true
11+
12+ describe "run/1" do
13+ test "replaces the hook template with config values" do
14+ put_git_hook_config (
15+ [ :pre_commit , :pre_push ] ,
16+ tasks: { :cmd , "check" }
17+ )
18+
19+ hooks_file = Install . run ( [ "--dry-run" , "--quiet" ] )
20+
21+ assert hooks_file == [
22+ pre_commit: expect_hook_template ( "pre_commit" ) ,
23+ pre_push: expect_hook_template ( "pre_push" )
24+ ]
25+ end
26+ end
27+
28+ #
29+ # Private functions
30+ #
31+
32+ defp expect_hook_template ( git_hook ) do
33+ app_path = GitPath . resolve_app_path ( )
34+
35+ ~s( #!/bin/sh
36+
37+ [ "#{ app_path } " != "" ] && cd #{ app_path }
38+
39+ mix git_hooks.run #{ git_hook } "$@"
40+ [ $? -ne 0 ] && exit 1
41+ exit 0
42+ )
43+ end
44+ end
You can’t perform that action at this time.
0 commit comments