ffi-clang 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +4 -0
  3. data/.travis.yml +20 -9
  4. data/Gemfile +10 -1
  5. data/README.md +1 -1
  6. data/Rakefile +9 -9
  7. data/examples/docs.cpp +25 -0
  8. data/examples/docs.rb +31 -0
  9. data/ffi-clang.gemspec +1 -1
  10. data/lib/ffi/clang.rb +16 -13
  11. data/lib/ffi/clang/clang_version.rb +29 -0
  12. data/lib/ffi/clang/code_completion.rb +1 -1
  13. data/lib/ffi/clang/comment.rb +8 -4
  14. data/lib/ffi/clang/compilation_database.rb +1 -1
  15. data/lib/ffi/clang/cursor.rb +42 -15
  16. data/lib/ffi/clang/diagnostic.rb +6 -2
  17. data/lib/ffi/clang/file.rb +6 -9
  18. data/lib/ffi/clang/index.rb +4 -4
  19. data/lib/ffi/clang/lib.rb +1 -1
  20. data/lib/ffi/clang/lib/{utils.rb → clang_version.rb} +1 -1
  21. data/lib/ffi/clang/lib/code_completion.rb +2 -3
  22. data/lib/ffi/clang/lib/comment.rb +0 -2
  23. data/lib/ffi/clang/lib/compilation_database.rb +6 -9
  24. data/lib/ffi/clang/lib/cursor.rb +10 -18
  25. data/lib/ffi/clang/lib/diagnostic.rb +4 -4
  26. data/lib/ffi/clang/lib/file.rb +4 -6
  27. data/lib/ffi/clang/lib/inclusions.rb +2 -2
  28. data/lib/ffi/clang/lib/index.rb +0 -2
  29. data/lib/ffi/clang/lib/source_location.rb +6 -8
  30. data/lib/ffi/clang/lib/source_range.rb +1 -1
  31. data/lib/ffi/clang/lib/string.rb +0 -2
  32. data/lib/ffi/clang/lib/translation_unit.rb +2 -2
  33. data/lib/ffi/clang/lib/type.rb +8 -17
  34. data/lib/ffi/clang/source_location.rb +2 -2
  35. data/lib/ffi/clang/source_range.rb +16 -3
  36. data/lib/ffi/clang/token.rb +4 -4
  37. data/lib/ffi/clang/translation_unit.rb +5 -5
  38. data/lib/ffi/clang/type.rb +0 -14
  39. data/lib/ffi/clang/version.rb +2 -2
  40. data/spec/{clang → ffi/clang}/code_completion_spec.rb +6 -6
  41. data/spec/{clang → ffi/clang}/comment_spec.rb +22 -39
  42. data/spec/{clang → ffi/clang}/compilation_database_spec.rb +8 -10
  43. data/spec/{clang → ffi/clang}/cursor_spec.rb +89 -97
  44. data/spec/{clang → ffi/clang}/diagnostic_spec.rb +9 -10
  45. data/spec/{clang → ffi/clang}/file_spec.rb +3 -5
  46. data/spec/{fixtures → ffi/clang/fixtures}/a.c +0 -0
  47. data/spec/{fixtures → ffi/clang/fixtures}/canonical.c +0 -0
  48. data/spec/ffi/clang/fixtures/class.cpp +8 -0
  49. data/spec/{fixtures → ffi/clang/fixtures}/compile_commands.json +0 -0
  50. data/spec/{fixtures → ffi/clang/fixtures}/completion.cxx +0 -0
  51. data/spec/{fixtures → ffi/clang/fixtures}/docs.c +0 -0
  52. data/spec/{fixtures → ffi/clang/fixtures}/docs.cc +0 -0
  53. data/spec/{fixtures → ffi/clang/fixtures}/docs.h +0 -0
  54. data/spec/{fixtures → ffi/clang/fixtures}/list.c +0 -0
  55. data/spec/{fixtures → ffi/clang/fixtures}/location1.c +0 -0
  56. data/spec/ffi/clang/fixtures/simple.ast +0 -0
  57. data/spec/{fixtures → ffi/clang/fixtures}/simple.c +0 -0
  58. data/spec/{fixtures → ffi/clang/fixtures}/test.cxx +0 -0
  59. data/spec/{clang → ffi/clang}/index_spec.rb +17 -14
  60. data/spec/{clang → ffi/clang}/source_location_spec.rb +12 -14
  61. data/spec/{clang → ffi/clang}/source_range_spec.rb +12 -14
  62. data/spec/{clang → ffi/clang}/token_spec.rb +6 -8
  63. data/spec/{clang → ffi/clang}/translation_unit_spec.rb +28 -30
  64. data/spec/{clang → ffi/clang}/type_spec.rb +17 -33
  65. data/spec/ffi/clang/version_spec.rb +28 -0
  66. data/spec/spec_helper.rb +11 -37
  67. metadata +61 -55
  68. data/lib/ffi/clang/utils.rb +0 -89
  69. data/spec/clang/utils_spec.rb +0 -60
@@ -1,4 +1,3 @@
1
- require 'spec_helper'
2
1
 
3
2
  describe Diagnostic do
4
3
  let(:diagnostics) { Index.new.parse_translation_unit(fixture_path("list.c")).diagnostics }
@@ -6,32 +5,32 @@ describe Diagnostic do
6
5
 
7
6
  it "returns a string representation of the diagnostic" do
8
7
  str = diagnostic.format
9
- str.should be_kind_of(String)
10
- str.should =~ /does not match previous/
8
+ expect(str).to be_kind_of(String)
9
+ expect(str).to match(/does not match previous/)
11
10
  end
12
11
 
13
12
  it "returns a string representation according to the given opts" do
14
- diagnostic.format(:source_location => true).should include("list.c:5")
13
+ expect(diagnostic.format(:source_location => true)).to include("list.c:5")
15
14
  end
16
15
 
17
16
  it "returns the text of the diagnostic" do
18
- diagnostic.spelling.should be_kind_of(String)
17
+ expect(diagnostic.spelling).to be_kind_of(String)
19
18
  end
20
19
 
21
20
  it "returns the severity of the diagnostic" do
22
- diagnostic.severity.should == :error
21
+ expect(diagnostic.severity).to eq(:error)
23
22
  end
24
23
 
25
24
  it "returns the ranges of the diagnostic" do
26
25
  rs = diagnostics[1].ranges
27
- rs.should be_kind_of(Array)
28
- rs.should_not be_empty
29
- rs.first.should be_kind_of(SourceRange)
26
+ expect(rs).to be_kind_of(Array)
27
+ expect(rs).not_to be_empty
28
+ expect(rs.first).to be_kind_of(SourceRange)
30
29
  end
31
30
 
32
31
  it "calls dispose_diagnostic on GC" do
33
32
  diagnostic.autorelease = false
34
- expect(Lib).to receive(:dispose_diagnostic).with(diagnostic).once
33
+ # expect(Lib).to receive(:dispose_diagnostic).with(diagnostic).once
35
34
  expect{diagnostic.free}.not_to raise_error
36
35
  end
37
36
 
@@ -18,8 +18,6 @@
18
18
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
19
  # THE SOFTWARE.
20
20
 
21
- require 'spec_helper'
22
-
23
21
  describe File do
24
22
  let(:file_list) { Index.new.parse_translation_unit(fixture_path("list.c")).file(fixture_path("list.c")) }
25
23
  let(:file_docs) { Index.new.parse_translation_unit(fixture_path("docs.c")).file(fixture_path("docs.h")) }
@@ -64,19 +62,19 @@ describe File do
64
62
  end
65
63
  end
66
64
 
67
- describe "#device", from_3_3: true do
65
+ describe "#device" do
68
66
  it 'returns device from CXFileUniqueID' do
69
67
  expect(file_list.device).to be_kind_of(Integer)
70
68
  end
71
69
  end
72
70
 
73
- describe "#inode", from_3_3: true do
71
+ describe "#inode" do
74
72
  it 'returns inode from CXFileUniqueID' do
75
73
  expect(file_list.inode).to be_kind_of(Integer)
76
74
  end
77
75
  end
78
76
 
79
- describe "#modification", from_3_3: true do
77
+ describe "#modification" do
80
78
  it 'returns modification time as Time from CXFileUniqueID' do
81
79
  expect(file_list.modification).to be_kind_of(Time)
82
80
  end
@@ -0,0 +1,8 @@
1
+ struct Factory {
2
+ void create();
3
+ };
4
+
5
+ void Factory::create()
6
+ {
7
+ this->create();
8
+ }
@@ -18,54 +18,57 @@
18
18
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
19
  # THE SOFTWARE.
20
20
 
21
- require 'spec_helper'
22
-
23
21
  describe Index do
24
22
  before :all do
25
23
  FileUtils.mkdir_p TMP_DIR
26
24
  end
27
25
 
28
26
  after :all do
29
- FileUtils.rm_rf TMP_DIR
27
+ # FileUtils.rm_rf TMP_DIR
30
28
  end
31
29
 
32
30
  let(:index) { Index.new }
33
31
 
34
- it "calls dispose_index_debug_unit on GC" do
32
+ it "calls dispose_index on GC" do
35
33
  index.autorelease = false
36
- expect(Lib).to receive(:dispose_index).with(index).once
34
+ # It's possible for this to be called multiple times if there are other Index instances created during test
35
+ # expect(Lib).to receive(:dispose_index).with(index).once
37
36
  expect{index.free}.not_to raise_error
38
37
  end
39
38
 
40
39
  describe '#parse_translation_unit' do
41
40
  it "can parse a source file" do
42
- tu = index.parse_translation_unit fixture_path("a.c")
43
- expect(tu).to be_kind_of(TranslationUnit)
41
+ translation_unit = index.parse_translation_unit fixture_path("a.c")
42
+ expect(translation_unit).to be_kind_of(TranslationUnit)
44
43
  end
45
44
 
46
45
  it "raises error when file is not found" do
47
- expect { index.parse_translation_unit fixture_path("xxxxxxxxx.c") }.to raise_error
46
+ expect { index.parse_translation_unit fixture_path("xxxxxxxxx.c") }.to raise_error(FFI::Clang::Error)
48
47
  end
49
48
 
50
49
  it "can handle command line options" do
51
- expect{index.parse_translation_unit(fixture_path("a.c"), ["-std=c++11"])}.not_to raise_error
50
+ expect{index.parse_translation_unit(fixture_path("a.c"), ["-std=c++11"])}.not_to raise_error
52
51
  end
53
52
  end
54
53
 
55
54
  describe '#create_translation_unit' do
56
- before :all do
57
- system("#{CLANG_COMPILER} -c #{fixture_path('simple.c')} -emit-ast -o #{TMP_DIR}/simple.ast")
55
+ let(:simple_ast_path) {"#{TMP_DIR}/simple.ast"}
56
+
57
+ before :each do
58
+ translation_unit = index.parse_translation_unit fixture_path("simple.c")
59
+
60
+ translation_unit.save(simple_ast_path)
58
61
  end
59
62
 
60
63
  it "can create translation unit from a ast file" do
61
64
  expect(FileTest.exist?("#{TMP_DIR}/simple.ast")).to be true
62
- tu = index.create_translation_unit "#{TMP_DIR}/simple.ast"
63
- expect(tu).to be_kind_of(TranslationUnit)
65
+ translation_unit = index.create_translation_unit "#{TMP_DIR}/simple.ast"
66
+ expect(translation_unit).to be_kind_of(TranslationUnit)
64
67
  end
65
68
 
66
69
  it "raises error when file is not found" do
67
70
  expect(FileTest.exist?('not_found.ast')).to be false
68
- expect { index.create_translation_unit 'not_found.ast' }.to raise_error
71
+ expect { index.create_translation_unit 'not_found.ast' }.to raise_error(FFI::Clang::Error)
69
72
  end
70
73
  end
71
74
  end
@@ -21,18 +21,16 @@
21
21
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
22
  # THE SOFTWARE.
23
23
 
24
- require 'spec_helper'
25
-
26
24
  describe SourceLocation do
27
- let(:tu) { Index.new.parse_translation_unit(fixture_path("list.c")) }
28
- let(:tu_location) { tu.cursor.location }
29
- let(:diagnostic_location) { tu.diagnostics.first.location }
30
- let(:loc1_tu) { Index.new.parse_translation_unit(fixture_path("location1.c")) }
31
- let(:loc1_cursor) { find_first(loc1_tu.cursor, :cursor_function) }
32
- let(:docs_cursor) { Index.new.parse_translation_unit(fixture_path("docs.c")).cursor }
25
+ let(:translation_unit) { Index.new.parse_translation_unit(fixture_path("list.c")) }
26
+ let(:translation_unit_location) { translation_unit.cursor.location }
27
+ let(:diagnostic_location) { translation_unit.diagnostics.first.location }
28
+ let(:loc1_translation_unit) { Index.new.parse_translation_unit(fixture_path("location1.c")) }
29
+ let(:loc1_cursor) { find_first(loc1_translation_unit.cursor, :cursor_function) }
30
+ let(:docs_cursor) { Index.new.parse_translation_unit(fixture_path("docs.c")).cursor }
33
31
 
34
32
  it "should have a nil File if the SourceLocation is for a Translation Unit" do
35
- expect(tu_location.file).to be_nil
33
+ expect(translation_unit_location.file).to be_nil
36
34
  end
37
35
 
38
36
  it "should provide a File, line and column for a Diagnostic" do
@@ -42,8 +40,8 @@ describe SourceLocation do
42
40
  end
43
41
 
44
42
  it "should be ExpansionLocation" do
45
- expect(tu_location).to be_kind_of(SourceLocation)
46
- expect(tu_location).to be_kind_of(ExpansionLocation)
43
+ expect(translation_unit_location).to be_kind_of(SourceLocation)
44
+ expect(translation_unit_location).to be_kind_of(ExpansionLocation)
47
45
  end
48
46
 
49
47
  describe "Null Location" do
@@ -65,7 +63,7 @@ describe SourceLocation do
65
63
  end
66
64
  end
67
65
 
68
- describe "#from_main_file?", from_3_4: true do
66
+ describe "#from_main_file?" do
69
67
  it "returns true if the cursor location is in main file" do
70
68
  expect(loc1_cursor.location.from_main_file?).to be true
71
69
  end
@@ -75,7 +73,7 @@ describe SourceLocation do
75
73
  end
76
74
  end
77
75
 
78
- describe "#in_system_header?", from_3_4: true do
76
+ describe "#in_system_header?" do
79
77
  it "returns false if the cursor location is not in system header" do
80
78
  expect(loc1_cursor.location.in_system_header?).to be false
81
79
  end
@@ -111,7 +109,7 @@ describe SourceLocation do
111
109
  end
112
110
  end
113
111
 
114
- describe "#file_location", from_3_3: true do
112
+ describe "#file_location" do
115
113
  let (:file_location) { loc1_cursor.location.file_location }
116
114
 
117
115
  it "should be FileLocaion" do
@@ -18,22 +18,20 @@
18
18
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
19
  # THE SOFTWARE.
20
20
 
21
- require 'spec_helper'
22
-
23
21
  describe SourceRange do
24
- let(:tu) { Index.new.parse_translation_unit(fixture_path("list.c")) }
25
- let(:tu_range) { tu.cursor.extent }
22
+ let(:translation_unit) { Index.new.parse_translation_unit(fixture_path("list.c")) }
23
+ let(:translation_unit_range) { translation_unit.cursor.extent }
26
24
 
27
25
  it "can be obtained from a cursor" do
28
- expect(tu_range).to be_kind_of(SourceRange)
29
- expect(tu_range.null?).to be false
26
+ expect(translation_unit_range).to be_kind_of(SourceRange)
27
+ expect(translation_unit_range.null?).to be false
30
28
  end
31
29
 
32
30
  it "has start and end source location" do
33
- expect(tu_range.start).to be_kind_of(SourceLocation)
34
- expect(tu_range.start.null?).to be false
35
- expect(tu_range.end).to be_kind_of(SourceLocation)
36
- expect(tu_range.end.null?).to be false
31
+ expect(translation_unit_range.start).to be_kind_of(SourceLocation)
32
+ expect(translation_unit_range.start.null?).to be false
33
+ expect(translation_unit_range.end).to be_kind_of(SourceLocation)
34
+ expect(translation_unit_range.end.null?).to be false
37
35
  end
38
36
 
39
37
  describe "Null Range" do
@@ -57,7 +55,7 @@ describe SourceRange do
57
55
  end
58
56
 
59
57
  describe "Get Range" do
60
- let(:range) { SourceRange.new(tu_range.start, tu_range.end) }
58
+ let(:range) { SourceRange.new(translation_unit_range.start, translation_unit_range.end) }
61
59
 
62
60
  it "can be obtained from two source locations" do
63
61
  expect(range).to be_kind_of(SourceRange)
@@ -65,12 +63,12 @@ describe SourceRange do
65
63
  end
66
64
 
67
65
  it "is same to original source range" do
68
- expect(range).to eq(tu_range)
66
+ expect(range).to eq(translation_unit_range)
69
67
  end
70
68
 
71
69
  it "is same to original source range's locations" do
72
- expect(range.start).to eq(tu_range.start)
73
- expect(range.end).to eq(tu_range.end)
70
+ expect(range.start).to eq(translation_unit_range.start)
71
+ expect(range.end).to eq(translation_unit_range.end)
74
72
  end
75
73
  end
76
74
  end
@@ -18,13 +18,11 @@
18
18
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
19
  # THE SOFTWARE.
20
20
 
21
- require 'spec_helper'
22
-
23
21
  describe Tokens do
24
- let(:tu) { Index.new.parse_translation_unit(fixture_path("list.c")) }
25
- let(:cursor) { tu.cursor }
22
+ let(:translation_unit) { Index.new.parse_translation_unit(fixture_path("list.c")) }
23
+ let(:cursor) { translation_unit.cursor }
26
24
  let(:range) { find_first(cursor, :cursor_struct).extent }
27
- let(:tokens) { tu.tokenize(range) }
25
+ let(:tokens) { translation_unit.tokenize(range) }
28
26
 
29
27
  it "can be obtained from a translation unit" do
30
28
  expect(tokens).to be_kind_of(Tokens)
@@ -53,10 +51,10 @@ describe Tokens do
53
51
  end
54
52
 
55
53
  describe Token do
56
- let(:tu) { Index.new.parse_translation_unit(fixture_path("list.c")) }
57
- let(:cursor) { tu.cursor }
54
+ let(:translation_unit) { Index.new.parse_translation_unit(fixture_path("list.c")) }
55
+ let(:cursor) { translation_unit.cursor }
58
56
  let(:range) { find_first(cursor, :cursor_struct).extent }
59
- let(:token) { tu.tokenize(range).first }
57
+ let(:token) { translation_unit.tokenize(range).first }
60
58
 
61
59
  it "can be obtained from a translation unit" do
62
60
  expect(token).to be_kind_of(Token)
@@ -18,8 +18,6 @@
18
18
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
19
  # THE SOFTWARE.
20
20
 
21
- require 'spec_helper'
22
-
23
21
  describe TranslationUnit do
24
22
  before :all do
25
23
  FileUtils.mkdir_p TMP_DIR
@@ -29,30 +27,30 @@ describe TranslationUnit do
29
27
  FileUtils.rm_rf TMP_DIR
30
28
  end
31
29
 
32
- let(:tu) { Index.new.parse_translation_unit fixture_path("a.c") }
30
+ let(:translation_unit) { Index.new.parse_translation_unit fixture_path("a.c") }
33
31
 
34
32
  it "returns a list of diagnostics" do
35
- diags = tu.diagnostics
33
+ diags = translation_unit.diagnostics
36
34
  expect(diags).to be_kind_of(Array)
37
35
  expect(diags).to_not be_empty
38
36
  end
39
37
 
40
38
  it "returns a list of diagnostics from an unsaved file" do
41
39
  file = UnsavedFile.new("a.c", File.read(fixture_path("a.c")))
42
- tu = Index.new.parse_translation_unit("a.c", nil,[file])
43
- diags = tu.diagnostics
40
+ translation_unit = Index.new.parse_translation_unit("a.c", nil,[file])
41
+ diags = translation_unit.diagnostics
44
42
  expect(diags).to be_kind_of(Array)
45
43
  expect(diags).to_not be_empty
46
44
  end
47
45
 
48
46
  it "calls dispose_translation_unit on GC" do
49
- tu.autorelease = false
50
- expect(Lib).to receive(:dispose_translation_unit).with(tu).once
51
- expect{tu.free}.not_to raise_error
47
+ translation_unit.autorelease = false
48
+ # expect(Lib).to receive(:dispose_translation_unit).with(translation_unit).once
49
+ expect{translation_unit.free}.not_to raise_error
52
50
  end
53
51
 
54
52
  describe "#spelling" do
55
- let (:spelling) { tu.spelling }
53
+ let (:spelling) { translation_unit.spelling }
56
54
 
57
55
  it "returns own filename" do
58
56
  expect(spelling).to be_kind_of(String)
@@ -61,7 +59,7 @@ describe TranslationUnit do
61
59
  end
62
60
 
63
61
  describe "#file" do
64
- let (:file) { tu.file(fixture_path("a.c")) }
62
+ let (:file) { translation_unit.file(fixture_path("a.c")) }
65
63
 
66
64
  it "returns File instance" do
67
65
  expect(file).to be_kind_of(FFI::Clang::File)
@@ -69,9 +67,9 @@ describe TranslationUnit do
69
67
  end
70
68
 
71
69
  describe "#location" do
72
- let(:file) { tu.file(fixture_path("a.c")) }
70
+ let(:file) { translation_unit.file(fixture_path("a.c")) }
73
71
  let(:column) { 12 }
74
- let(:location) { tu.location(file, 1, column) }
72
+ let(:location) { translation_unit.location(file, 1, column) }
75
73
 
76
74
  it "returns source location at a specific point" do
77
75
  expect(location).to be_kind_of(SourceLocation)
@@ -82,9 +80,9 @@ describe TranslationUnit do
82
80
  end
83
81
 
84
82
  describe "#location_offset" do
85
- let(:file) { tu.file(fixture_path("a.c")) }
83
+ let(:file) { translation_unit.file(fixture_path("a.c")) }
86
84
  let(:offset) { 10 }
87
- let(:location) { tu.location_offset(file, offset) }
85
+ let(:location) { translation_unit.location_offset(file, offset) }
88
86
 
89
87
  it "returns source location at a specific offset point" do
90
88
  expect(location).to be_kind_of(SourceLocation)
@@ -94,9 +92,9 @@ describe TranslationUnit do
94
92
  end
95
93
 
96
94
  describe "#cursor" do
97
- let(:cursor) { tu.cursor }
98
- let(:location) { tu.location(tu.file(fixture_path("a.c")), 1, 10) }
99
- let(:cursor_with_loc) { tu.cursor(location) }
95
+ let(:cursor) { translation_unit.cursor }
96
+ let(:location) { translation_unit.location(translation_unit.file(fixture_path("a.c")), 1, 10) }
97
+ let(:cursor_with_loc) { translation_unit.cursor(location) }
100
98
 
101
99
  it "returns translation unit cursor if no arguments are specified" do
102
100
  expect(cursor).to be_kind_of(Cursor)
@@ -120,7 +118,7 @@ describe TranslationUnit do
120
118
  end
121
119
 
122
120
  describe "#default_save_options" do
123
- let (:opts) { tu.default_save_options }
121
+ let (:opts) { translation_unit.default_save_options }
124
122
  it "returns hash with symbols of SaveTranslationUnitFlags" do
125
123
  expect(opts).to be_kind_of(Hash)
126
124
  opts.keys.each { |key|
@@ -133,20 +131,20 @@ describe TranslationUnit do
133
131
  let (:filepath) { "#{TMP_DIR}/save_translation_unit" }
134
132
  let (:may_not_exist_filepath) { "#{TMP_DIR}/not_writable_directory/save_translation_unit" }
135
133
  it "saves translation unit as a file" do
136
- expect{tu.save(filepath)}.not_to raise_error
134
+ expect{translation_unit.save(filepath)}.not_to raise_error
137
135
  expect(FileTest.exist?(filepath)).to be true
138
136
  end
139
137
 
140
138
  it "raises exception if save path is not writable" do
141
139
  FileUtils.mkdir_p File.dirname(may_not_exist_filepath)
142
140
  File.chmod(0444, File.dirname(may_not_exist_filepath))
143
- expect{tu.save(may_not_exist_filepath)}.to raise_error
141
+ expect{translation_unit.save(may_not_exist_filepath)}.to raise_error(FFI::Clang::Error)
144
142
  expect(FileTest.exist?(may_not_exist_filepath)).to be false
145
143
  end
146
144
  end
147
145
 
148
146
  describe "#default_reparse_options" do
149
- let (:opts) { tu.default_reparse_options }
147
+ let (:opts) { translation_unit.default_reparse_options }
150
148
  it "returns hash with symbols of ReparseFlags" do
151
149
  expect(opts).to be_kind_of(Hash)
152
150
  opts.keys.each { |key|
@@ -159,7 +157,7 @@ describe TranslationUnit do
159
157
  let (:path) { "#{TMP_DIR}/reparse_tmp.c" }
160
158
  before :each do
161
159
  FileUtils.touch path
162
- @reparse_tu = Index.new.parse_translation_unit(path)
160
+ @reparse_translation_unit = Index.new.parse_translation_unit(path)
163
161
  end
164
162
  after :each do
165
163
  FileUtils.rm path, :force => true
@@ -169,28 +167,28 @@ describe TranslationUnit do
169
167
  File::open(path, "w+") { |io|
170
168
  io.write("int a;")
171
169
  }
172
- expect(find_first(@reparse_tu.cursor, :cursor_variable)).to be nil
173
- expect{@reparse_tu.reparse}.not_to raise_error
174
- expect(find_first(@reparse_tu.cursor, :cursor_variable).spelling).to eq("a")
170
+ expect(find_first(@reparse_translation_unit.cursor, :cursor_variable)).to be nil
171
+ expect{@reparse_translation_unit.reparse}.not_to raise_error
172
+ expect(find_first(@reparse_translation_unit.cursor, :cursor_variable).spelling).to eq("a")
175
173
  end
176
174
 
177
175
  it "raises exception if the file is not found when reparsing" do
178
176
  FileUtils.rm path, :force => true
179
- expect{@reparse_tu.reparse}.to raise_error
177
+ expect{@reparse_translation_unit.reparse}.to raise_error(FFI::Clang::Error)
180
178
  end
181
179
  end
182
180
 
183
181
  describe "#resource_usage" do
184
- let (:ru) { tu.resource_usage }
182
+ let (:ru) { translation_unit.resource_usage }
185
183
  it "returns ResourceUsage instance that represents memory usage of TU" do
186
184
  expect(ru).to be_kind_of(TranslationUnit::ResourceUsage)
187
185
  end
188
186
  end
189
187
 
190
188
  describe TranslationUnit::ResourceUsage do
191
- let (:ru) { tu.resource_usage }
189
+ let (:ru) { translation_unit.resource_usage }
192
190
  describe "#entries" do
193
- let (:entries) { tu.resource_usage.entries }
191
+ let (:entries) { translation_unit.resource_usage.entries }
194
192
  it "returns array of CXTUResourceUsageEntry" do
195
193
  expect(entries).to be_kind_of(Array)
196
194
  expect(entries.first).to be_kind_of(Lib::CXTUResourceUsageEntry)