]>
git.immae.eu Git - github/fretlink/pronto-hlint.git/blob - spec/pronto/hlint_spec.rb
1 # frozen_string_literal: true
8 let(:hlint) { Hlint
::Runner.new(patches
) }
12 subject(:run) { hlint
.run
}
14 context
'patches are nil' do
17 it
'returns an empty array' do
18 expect(run
).to
eql([])
22 context
'no patches' do
25 it
'returns an empty array' do
26 expect(run
).to
eql([])
30 context
'patches with a one and a four warnings' do
31 include_context
'test repo'
33 let(:patches) { repo
.diff('master') }
35 it
'returns correct number of errors' do
36 expect(run
.count
).to
eql(3)
39 it
'has correct first message' do
40 expect(run
.first
.msg
).to
match("Unused LANGUAGE pragma")
44 'with files to lint config that never matches',
45 config
: { 'files_to_lint' => 'will never match' }
47 it
'returns zero errors' do
48 expect(run
.count
).to
eql(0)
53 'with files to lint config that matches only .lhs',
54 config
: { 'files_to_lint' => '\.lhs$' }
56 it
'returns correct amount of errors' do
57 expect(run
.count
).to
eql(0)
62 'with different hlint executable',
63 config
: { 'hlint_executable' => './custom_hlint.sh' }
65 it
'calls the custom hlint hlint_executable' do
66 expect
{ run
}.to
raise_error(JSON
::ParserError, /hlint called!/)
72 describe
'#files_to_lint' do
73 subject(:files_to_lint) { hlint
.files_to_lint
}
75 it
'matches .he by default' do
76 expect(files_to_lint
).to
match('Types.hs')
80 describe
'#hlint_executable' do
81 subject(:hlint_executable) { hlint
.hlint_executable
}
83 it
'is `hlint` by default' do
84 expect(hlint_executable
).to
eql('hlint')
88 'with different hlint executable config',
89 config
: { 'hlint_executable' => 'custom_hlint' }
93 expect(hlint_executable
).to
eql('custom_hlint')
98 describe
'#hlint_command_line' do
99 subject(:hlint_command_line) { hlint
.send(:hlint_command_line, path
) }
100 let(:path) { '/some/path.rb' }
102 it
'adds json output flag' do
103 expect(hlint_command_line
).to
include('--json')
107 expect(hlint_command_line
).to
include(path
)
110 it
'starts with hlint executable' do
111 expect(hlint_command_line
).to
start_with(hlint
.hlint_executable
)
114 context
'with path that should be escaped' do
115 let(:path) { '/must be/$escaped' }
117 it
'escapes the path correctly' do
118 expect(hlint_command_line
).to
include('/must\\ be/\\$escaped')
121 it
'does not include unescaped path' do
122 expect(hlint_command_line
).not_to
include(path
)
127 'with some command line options',
128 config
: { 'cmd_line_opts' => '--my command --line opts' }
130 it
'includes the custom command line options' do
132 expect(hlint_command_line
).to
include('--my command --line opts')