ghazel-ffi-clang 0.2.0.2 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,178 @@
1
+ # Copyright, 2014, by Masahiro Sano.
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in
11
+ # all copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ # THE SOFTWARE.
20
+
21
+ require 'spec_helper'
22
+
23
+ describe CompilationDatabase do
24
+ let(:dirpath) { fixture_path('') }
25
+ let(:cdb) { CompilationDatabase.new(dirpath) }
26
+ let(:file) { '/home/xxxxx/src/llvm-trunk/lib/Support/APFloat.cpp' }
27
+
28
+ it "can be created" do
29
+ expect(cdb).to be_kind_of(CompilationDatabase)
30
+ end
31
+
32
+ it "raises DatabaseLoadError if cannot be created" do
33
+ expect{CompilationDatabase.new('/not/exist/directory')}.to raise_error FFI::Clang::CompilationDatabase::DatabaseLoadError
34
+ end
35
+
36
+ it "calls compilation_database_dispose on GC" do
37
+ cdb.autorelease = false
38
+ expect(Lib).to receive(:compilation_database_dispose).with(cdb).once
39
+ expect{cdb.free}.not_to raise_error
40
+ end
41
+
42
+ describe '#compile_commands' do
43
+ let(:not_found_file) { '/home/xxxxx/not_found_file_path' }
44
+
45
+ it "returns compile commands used for a file" do
46
+ expect(cdb.compile_commands(file)).to be_kind_of(CompilationDatabase::CompileCommands)
47
+ expect(cdb.compile_commands(file).size).to eq(1)
48
+ end
49
+
50
+ it "returns compile commands if the specified file is not found" do
51
+ expect(cdb.compile_commands(not_found_file)).to be_kind_of(CompilationDatabase::CompileCommands)
52
+ expect(cdb.compile_commands(not_found_file).size).to eq(0)
53
+ end
54
+ end
55
+
56
+ describe '#all_compile_commands', from_3_3: true do
57
+ it "returns all compile commands in the database" do
58
+ expect(cdb.all_compile_commands).to be_kind_of(CompilationDatabase::CompileCommands)
59
+ expect(cdb.all_compile_commands.size).to eq(3)
60
+ end
61
+ end
62
+
63
+ describe CompilationDatabase::CompileCommands do
64
+ let(:commands) { cdb.compile_commands(file) }
65
+
66
+ it "calls compile_commands_dispose on GC" do
67
+ commands.autorelease = false
68
+ expect(Lib).to receive(:compile_commands_dispose).with(commands).once
69
+ expect{commands.free}.not_to raise_error
70
+ end
71
+
72
+ describe '#size' do
73
+ it "returns the number of CompileCommand" do
74
+ expect(commands.size).to be_kind_of(Integer)
75
+ expect(commands.size).to eq(1)
76
+ end
77
+
78
+ it "returns the number of CompileCommand", from_3_3: true do
79
+ expect(cdb.all_compile_commands.size).to eq(3)
80
+ end
81
+ end
82
+
83
+ describe '#command' do
84
+ it "returns the I'th CompileCommand" do
85
+ expect(commands.command(0)).to be_kind_of(CompilationDatabase::CompileCommand)
86
+ end
87
+ end
88
+
89
+ describe "#commands" do
90
+ it "returns all CompileCommand as Array" do
91
+ expect(commands.commands).to be_kind_of(Array)
92
+ expect(commands.commands.first).to be_kind_of(CompilationDatabase::CompileCommand)
93
+ expect(commands.commands.size).to eq(commands.size)
94
+ end
95
+ end
96
+
97
+ describe "#each" do
98
+ let(:spy) { double(stub: nil) }
99
+ it "calls block once for each CompileCommand" do
100
+ expect(spy).to receive(:stub).exactly(commands.size).times
101
+ commands.each { spy.stub }
102
+ end
103
+ end
104
+ end
105
+
106
+ describe CompilationDatabase::CompileCommand do
107
+ let(:cmd) { cdb.compile_commands(file).first }
108
+
109
+ describe '#directory' do
110
+ it "returns the working directory" do
111
+ expect(cmd.directory).to be_kind_of(String)
112
+ expect(cmd.directory).to eq('/home/xxxxx/src/build-trunk/lib/Support')
113
+ end
114
+ end
115
+
116
+ describe '#num_args' do
117
+ it "returns the number of CompileCommand" do
118
+ expect(cmd.num_args).to be_kind_of(Integer)
119
+ expect(cmd.num_args).to eq(31)
120
+ end
121
+ end
122
+
123
+ describe '#arg' do
124
+ it "returns the I'th argument value" do
125
+ expect(cmd.arg(0)).to be_kind_of(String)
126
+ expect(cmd.arg(0)).to eq('/opt/llvm/3.4/bin/clang++')
127
+ end
128
+ end
129
+
130
+ describe '#args' do
131
+ it "returns all argument values as Array" do
132
+ expect(cmd.args).to be_kind_of(Array)
133
+ expect(cmd.args.first).to be_kind_of(String)
134
+ expect(cmd.args.size).to eq(cmd.num_args)
135
+ end
136
+ end
137
+
138
+ describe '#num_mapped_sources', from_3_4: true do
139
+ # TODO: a case which has mapped sources
140
+
141
+ it "returns the number of source mappings" do
142
+ # expect(cmd.num_mapped_sources).to be_kind_of(Integer)
143
+ # expect(cmd.num_mapped_sources).to eq(0)
144
+ end
145
+ end
146
+
147
+ describe '#mapped_source_path', from_3_4: true do
148
+ it "returns the I'th mapped source path" do
149
+ # TODO: a case which returns real source path
150
+ # expect(cmd.mapped_source_path(0)).to be_kind_of(String)
151
+ end
152
+
153
+ it "returns nil if the index exceeds element size" do
154
+ # expect(cmd.mapped_source_path(1000)).to be_nil
155
+ end
156
+ end
157
+
158
+ describe '#mapped_source_content', from_3_4: true do
159
+ it "returns the I'th mapped source content" do
160
+ # TODO: a case which returns real source path
161
+ # expect(cmd.mapped_source_content(0)).to be_kind_of(String)
162
+ end
163
+
164
+ it "returns nil if the index exceeds element size" do
165
+ # expect(cmd.mapped_source_content(1000)).to be_nil
166
+ end
167
+ end
168
+
169
+ describe '#mapped_sources', from_3_4: true do
170
+ # TODO: a case which has mapped sources
171
+
172
+ it "returns all mapped sources as Array" do
173
+ # expect(cmd.mapped_sources).to be_kind_of(Array)
174
+ # expect(cmd.mapped_sources.size).to eq(cmd.num_mapped_sources)
175
+ end
176
+ end
177
+ end
178
+ end
@@ -30,7 +30,8 @@ describe Diagnostic do
30
30
  end
31
31
 
32
32
  it "calls dispose_diagnostic on GC" do
33
- expect(Lib).to receive(:dispose_diagnostic).with(diagnostic).at_least(:once)
33
+ diagnostic.autorelease = false
34
+ expect(Lib).to receive(:dispose_diagnostic).with(diagnostic).once
34
35
  expect{diagnostic.free}.not_to raise_error
35
36
  end
36
37
 
@@ -32,7 +32,8 @@ describe Index do
32
32
  let(:index) { Index.new }
33
33
 
34
34
  it "calls dispose_index_debug_unit on GC" do
35
- expect(Lib).to receive(:dispose_index).with(index).at_least(:once)
35
+ index.autorelease = false
36
+ expect(Lib).to receive(:dispose_index).with(index).once
36
37
  expect{index.free}.not_to raise_error
37
38
  end
38
39
 
@@ -53,7 +54,7 @@ describe Index do
53
54
 
54
55
  describe '#create_translation_unit' do
55
56
  before :all do
56
- system("clang -c #{fixture_path('simple.c')} -emit-ast -o #{TMP_DIR}/simple.ast")
57
+ system("#{CLANG_COMPILER} -c #{fixture_path('simple.c')} -emit-ast -o #{TMP_DIR}/simple.ast")
57
58
  end
58
59
 
59
60
  it "can create translation unit from a ast file" do
@@ -34,6 +34,7 @@ describe Tokens do
34
34
  end
35
35
 
36
36
  it "calls dispose_tokens on GC" do
37
+ tokens.autorelease = false
37
38
  expect(Lib).to receive(:dispose_tokens).at_least(:once)
38
39
  expect{tokens.free}.not_to raise_error
39
40
  end
@@ -46,7 +46,8 @@ describe TranslationUnit do
46
46
  end
47
47
 
48
48
  it "calls dispose_translation_unit on GC" do
49
- expect(Lib).to receive(:dispose_translation_unit).with(tu)
49
+ tu.autorelease = false
50
+ expect(Lib).to receive(:dispose_translation_unit).with(tu).once
50
51
  expect{tu.free}.not_to raise_error
51
52
  end
52
53
 
@@ -207,6 +208,7 @@ describe TranslationUnit do
207
208
 
208
209
  describe "#self.release" do
209
210
  it "releases data by calling 'clang_disposeCXTUResourceUsage'" do
211
+ ru.autorelease = false
210
212
  expect{ ru.free }.not_to raise_error
211
213
  end
212
214
  end
@@ -31,9 +31,8 @@ describe FFI::Clang::Utils do
31
31
 
32
32
  describe '#self.self.clang_version' do
33
33
  let (:version) { Utils::clang_version }
34
- it "returns only a version of clang as string" do
35
- expect(version).to be_kind_of(String)
36
- expect(version).to match(/^\d+\.\d+$/)
34
+ it "returns only a version of clang as array [major, minor]" do
35
+ expect(version).to be_kind_of(Array)
37
36
  end
38
37
  end
39
38
 
@@ -0,0 +1,17 @@
1
+ [
2
+ {
3
+ "directory": "/home/xxxxx/src/build-trunk/lib/Support",
4
+ "command": "/opt/llvm/3.4/bin/clang++ -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -fPIC -fvisibility-inlines-hidden -Wall -W -Wno-unused-parameter -Wwrite-strings -Wmissing-field-initializers -pedantic -Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor -fno-rtti -ffunction-sections -fdata-sections -O3 -I/home/xxxxx/src/build-trunk/lib/Support -I/home/xxxxx/src/llvm-trunk/lib/Support -I/home/xxxxx/src/build-trunk/include -I/home/xxxxx/src/llvm-trunk/include -UNDEBUG -fno-exceptions -o CMakeFiles/LLVMSupport.dir/APFloat.cpp.o -c /home/xxxxx/src/llvm-trunk/lib/Support/APFloat.cpp",
5
+ "file": "/home/xxxxx/src/llvm-trunk/lib/Support/APFloat.cpp"
6
+ },
7
+ {
8
+ "directory": "/home/xxxxx/src/build-trunk/lib/Support",
9
+ "command": "/opt/llvm/3.4/bin/clang++ -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -fPIC -fvisibility-inlines-hidden -Wall -W -Wno-unused-parameter -Wwrite-strings -Wmissing-field-initializers -pedantic -Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor -fno-rtti -ffunction-sections -fdata-sections -O3 -I/home/xxxxx/src/build-trunk/lib/Support -I/home/xxxxx/src/llvm-trunk/lib/Support -I/home/xxxxx/src/build-trunk/include -I/home/xxxxx/src/llvm-trunk/include -UNDEBUG -fno-exceptions -o CMakeFiles/LLVMSupport.dir/APInt.cpp.o -c /home/xxxxx/src/llvm-trunk/lib/Support/APInt.cpp",
10
+ "file": "/home/xxxxx/src/llvm-trunk/lib/Support/APInt.cpp"
11
+ },
12
+ {
13
+ "directory": "/home/xxxxx/src/build-trunk/lib/Support",
14
+ "command": "/opt/llvm/3.4/bin/clang++ -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -fPIC -fvisibility-inlines-hidden -Wall -W -Wno-unused-parameter -Wwrite-strings -Wmissing-field-initializers -pedantic -Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor -fno-rtti -ffunction-sections -fdata-sections -O3 -I/home/xxxxx/src/build-trunk/lib/Support -I/home/xxxxx/src/llvm-trunk/lib/Support -I/home/xxxxx/src/build-trunk/include -I/home/xxxxx/src/llvm-trunk/include -UNDEBUG -fno-exceptions -o CMakeFiles/LLVMSupport.dir/APSInt.cpp.o -c /home/xxxxx/src/llvm-trunk/lib/Support/APSInt.cpp",
15
+ "file": "/home/xxxxx/src/llvm-trunk/lib/Support/APSInt.cpp"
16
+ }
17
+ ]
@@ -0,0 +1,8 @@
1
+ #include <vector>
2
+
3
+ std::vector<int> v1;
4
+ std::vector<> v2;
5
+
6
+ int main(void) {
7
+ v1.
8
+ }
@@ -5,6 +5,15 @@ include FFI::Clang
5
5
 
6
6
  TMP_DIR = File.expand_path("../tmp/", __FILE__)
7
7
 
8
+ if ENV['LLVM_CONFIG']
9
+ llvm_bindir = `#{ENV['LLVM_CONFIG']} --bindir`.chomp
10
+ CLANG_COMPILER = File.expand_path('clang', llvm_bindir)
11
+ CLANGPP_COMPILER = File.expand_path('clang++', llvm_bindir)
12
+ else
13
+ CLANG_COMPILER = 'clang'
14
+ CLANGPP_COMPILER = 'clang++'
15
+ end
16
+
8
17
  module ClangSpecHelper
9
18
  def fixture_path(path)
10
19
  File.join File.expand_path("../fixtures", __FILE__), path
metadata CHANGED
@@ -1,7 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ghazel-ffi-clang
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0.2
4
+ version: 0.2.1
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Jari Bakken
@@ -9,25 +10,28 @@ authors:
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2014-02-17 00:00:00.000000000 Z
13
+ date: 2014-06-23 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: ffi
16
17
  requirement: !ruby/object:Gem::Requirement
18
+ none: false
17
19
  requirements:
18
- - - '>='
20
+ - - ! '>='
19
21
  - !ruby/object:Gem::Version
20
22
  version: '0'
21
23
  type: :runtime
22
24
  prerelease: false
23
25
  version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
24
27
  requirements:
25
- - - '>='
28
+ - - ! '>='
26
29
  - !ruby/object:Gem::Version
27
30
  version: '0'
28
31
  - !ruby/object:Gem::Dependency
29
32
  name: bundler
30
33
  requirement: !ruby/object:Gem::Requirement
34
+ none: false
31
35
  requirements:
32
36
  - - ~>
33
37
  - !ruby/object:Gem::Version
@@ -35,6 +39,7 @@ dependencies:
35
39
  type: :development
36
40
  prerelease: false
37
41
  version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
38
43
  requirements:
39
44
  - - ~>
40
45
  - !ruby/object:Gem::Version
@@ -42,29 +47,33 @@ dependencies:
42
47
  - !ruby/object:Gem::Dependency
43
48
  name: rake
44
49
  requirement: !ruby/object:Gem::Requirement
50
+ none: false
45
51
  requirements:
46
- - - '>='
52
+ - - ! '>='
47
53
  - !ruby/object:Gem::Version
48
54
  version: '0'
49
55
  type: :development
50
56
  prerelease: false
51
57
  version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
52
59
  requirements:
53
- - - '>='
60
+ - - ! '>='
54
61
  - !ruby/object:Gem::Version
55
62
  version: '0'
56
63
  - !ruby/object:Gem::Dependency
57
64
  name: rspec
58
65
  requirement: !ruby/object:Gem::Requirement
66
+ none: false
59
67
  requirements:
60
- - - '>='
68
+ - - ! '>='
61
69
  - !ruby/object:Gem::Version
62
70
  version: '0'
63
71
  type: :development
64
72
  prerelease: false
65
73
  version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
66
75
  requirements:
67
- - - '>='
76
+ - - ! '>='
68
77
  - !ruby/object:Gem::Version
69
78
  version: '0'
70
79
  description: Ruby FFI bindings for libclang C interface.
@@ -85,16 +94,21 @@ files:
85
94
  - ext/teapot.rb
86
95
  - ffi-clang.gemspec
87
96
  - lib/ffi/clang.rb
97
+ - lib/ffi/clang/code_completion.rb
88
98
  - lib/ffi/clang/comment.rb
99
+ - lib/ffi/clang/compilation_database.rb
89
100
  - lib/ffi/clang/cursor.rb
90
101
  - lib/ffi/clang/diagnostic.rb
91
102
  - lib/ffi/clang/file.rb
92
103
  - lib/ffi/clang/index.rb
93
104
  - lib/ffi/clang/lib.rb
105
+ - lib/ffi/clang/lib/code_completion.rb
94
106
  - lib/ffi/clang/lib/comment.rb
107
+ - lib/ffi/clang/lib/compilation_database.rb
95
108
  - lib/ffi/clang/lib/cursor.rb
96
109
  - lib/ffi/clang/lib/diagnostic.rb
97
110
  - lib/ffi/clang/lib/file.rb
111
+ - lib/ffi/clang/lib/inclusions.rb
98
112
  - lib/ffi/clang/lib/index.rb
99
113
  - lib/ffi/clang/lib/source_location.rb
100
114
  - lib/ffi/clang/lib/source_range.rb
@@ -111,7 +125,9 @@ files:
111
125
  - lib/ffi/clang/unsaved_file.rb
112
126
  - lib/ffi/clang/utils.rb
113
127
  - lib/ffi/clang/version.rb
128
+ - spec/clang/code_completion_spec.rb
114
129
  - spec/clang/comment_spec.rb
130
+ - spec/clang/compilation_database_spec.rb
115
131
  - spec/clang/cursor_spec.rb
116
132
  - spec/clang/diagnostic_spec.rb
117
133
  - spec/clang/file_spec.rb
@@ -124,6 +140,8 @@ files:
124
140
  - spec/clang/utils_spec.rb
125
141
  - spec/fixtures/a.c
126
142
  - spec/fixtures/canonical.c
143
+ - spec/fixtures/compile_commands.json
144
+ - spec/fixtures/completion.cxx
127
145
  - spec/fixtures/docs.c
128
146
  - spec/fixtures/docs.cc
129
147
  - spec/fixtures/docs.h
@@ -135,29 +153,32 @@ files:
135
153
  homepage: ''
136
154
  licenses:
137
155
  - MIT
138
- metadata: {}
139
156
  post_install_message:
140
157
  rdoc_options: []
141
158
  require_paths:
142
159
  - lib
143
160
  required_ruby_version: !ruby/object:Gem::Requirement
161
+ none: false
144
162
  requirements:
145
- - - '>='
163
+ - - ! '>='
146
164
  - !ruby/object:Gem::Version
147
165
  version: '0'
148
166
  required_rubygems_version: !ruby/object:Gem::Requirement
167
+ none: false
149
168
  requirements:
150
- - - '>='
169
+ - - ! '>='
151
170
  - !ruby/object:Gem::Version
152
171
  version: '0'
153
172
  requirements: []
154
173
  rubyforge_project:
155
- rubygems_version: 2.0.3
174
+ rubygems_version: 1.8.24
156
175
  signing_key:
157
- specification_version: 4
176
+ specification_version: 3
158
177
  summary: Ruby FFI bindings for libclang C interface.
159
178
  test_files:
179
+ - spec/clang/code_completion_spec.rb
160
180
  - spec/clang/comment_spec.rb
181
+ - spec/clang/compilation_database_spec.rb
161
182
  - spec/clang/cursor_spec.rb
162
183
  - spec/clang/diagnostic_spec.rb
163
184
  - spec/clang/file_spec.rb
@@ -170,6 +191,8 @@ test_files:
170
191
  - spec/clang/utils_spec.rb
171
192
  - spec/fixtures/a.c
172
193
  - spec/fixtures/canonical.c
194
+ - spec/fixtures/compile_commands.json
195
+ - spec/fixtures/completion.cxx
173
196
  - spec/fixtures/docs.c
174
197
  - spec/fixtures/docs.cc
175
198
  - spec/fixtures/docs.h