Skip to content

Commit

Permalink
Add a test for GIT_EXTERN()
Browse files Browse the repository at this point in the history
This means we need to go and write stuff to disk.
  • Loading branch information
carlosmn committed Mar 8, 2014
1 parent 9b51dc1 commit d1492de
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 12 deletions.
31 changes: 19 additions & 12 deletions lib/docurium/docparser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,25 @@ class DocParser
def parse_file(filename, files)
puts "called for #{filename}"

tu = Index.new.parse_translation_unit(filename, nil, unsaved_files(files), {:detailed_preprocessing_record => 1})
#tu = Index.new.parse_translation_unit(filename, ["-Igit2"], unsaved_files(files), {:detailed_preprocessing_record => 1})
# unfortunately Clang wants unsaved files to exist on disk, so
# we need to create at least empty files for each unsaved file
# we're given.

tmpdir = Dir.mktmpdir()

unsaved = files.map do |name, contents|
full_path = File.join(tmpdir, name)
File.new(full_path, File::CREAT).close()

UnsavedFile.new(full_path, contents)
end

# Override the path we want to filter by
filename = File.join(tmpdir, filename)
tu = Index.new.parse_translation_unit(filename, [], unsaved, {:detailed_preprocessing_record => 1})

FileUtils.remove_entry(tmpdir)

cursor = tu.cursor

recs = []
Expand Down Expand Up @@ -233,15 +250,5 @@ def children(cursor)
list
end

def unsaved_files(files)
files.map do |name, content|
fixed = content.gsub(/GIT_EXTERN\((.*?)\)/, '\1')
if name == "attr.h"
puts fixed
end
UnsavedFile.new(name, fixed)
end
end

end
end
50 changes: 50 additions & 0 deletions test/parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,54 @@ def test_single_multiline_function
assert_equal expected, actual
end

def test_parsing_with_extern

name_a = 'common.h'
contents_a = <<EOF
# define GIT_EXTERN(type) extern type
EOF

name_b = 'function.h'
contents_b = <<EOF
#include "common.h"
/**
* Awesomest API
*/
GIT_EXTERN(int) some_public_function(int val);
EOF

actual = @parser.parse_file(name_b, [[name_a, contents_a], [name_b, contents_b]])

# "Fix" the path so we remove the temp dir
actual[0][:file] = File.split(actual[0][:file])[-1]

expected = [{
:file => "function.h",
:line => 6,
:lineto => 6,
:tdef => nil,
:type => :function,
:name => "some_public_function",
:body => "int some_public_function(int val);",
:description => " Awesomest API",
:comments => " Awesomest API",
:sig => "int",
:args => [{
:name=>"val",
:type=>"int",
:comment=>nil
}],
:return => {
:type=>"int",
:comment=>nil
},
:decl =>"int some_public_function(int val)",
:argline =>"int val"
}]

assert_equal expected, actual

end

end

0 comments on commit d1492de

Please sign in to comment.