File tree 3 files changed +63
-0
lines changed
lib/overcommit/hook/pre_push
spec/overcommit/hook/pre_push
3 files changed +63
-0
lines changed Original file line number Diff line number Diff line change @@ -1117,6 +1117,13 @@ PrePush:
1117
1117
flags : ['--exit-on-warn', '--quiet', '--summary']
1118
1118
install_command : ' gem install brakeman'
1119
1119
1120
+ CargoTest :
1121
+ enabled : false
1122
+ description : ' Run tests with cargo'
1123
+ required_executable : ' cargo'
1124
+ flags : ['test']
1125
+ include : ' src/**/*.rs'
1126
+
1120
1127
GitLfs :
1121
1128
enabled : false
1122
1129
description : ' Upload files tracked by Git LFS'
Original file line number Diff line number Diff line change
1
+ module Overcommit ::Hook ::PrePush
2
+ # Runs `cargo test` before push if Rust files changed
3
+ class CargoTest < Base
4
+ def run
5
+ result = execute ( command )
6
+ return :pass if result . success?
7
+ [ :fail , result . stdout ]
8
+ end
9
+ end
10
+ end
Original file line number Diff line number Diff line change
1
+ require 'spec_helper'
2
+
3
+ describe Overcommit ::Hook ::PrePush ::CargoTest do
4
+ let ( :config ) { Overcommit ::ConfigurationLoader . default_configuration }
5
+ let ( :context ) { double ( 'context' ) }
6
+ subject { described_class . new ( config , context ) }
7
+
8
+ context 'when all tests succeed' do
9
+ before do
10
+ result = double ( 'result' )
11
+ result . stub ( :success? ) . and_return ( true )
12
+ subject . stub ( :execute ) . and_return ( result )
13
+ end
14
+
15
+ it { should pass }
16
+ end
17
+
18
+ context 'when one test fails' do
19
+ before do
20
+ result = double ( 'result' )
21
+ result . stub ( :success? ) . and_return ( false )
22
+ result . stub ( stdout : <<-ERRORMSG )
23
+ running 2 tests
24
+ test tests::foo ... ok
25
+ test tests::bar ... FAILED
26
+
27
+ failures:
28
+
29
+ ---- tests::bar stdout ----
30
+ thread 'tests::bar' panicked at 'assertion failed: `(left == right)`
31
+ left: `None`,
32
+ right: `Some(Bar)`', src/foobar.rs:88:9
33
+ note: Run with `RUST_BACKTRACE=1` for a backtrace.
34
+
35
+
36
+ failures:
37
+ tests::bar
38
+
39
+ test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out
40
+ ERRORMSG
41
+ subject . stub ( :execute ) . and_return ( result )
42
+ end
43
+
44
+ it { should fail_hook }
45
+ end
46
+ end
You can’t perform that action at this time.
0 commit comments