public
Description: Ruby library to parse and query C++ header files using GCCXML
Homepage: http://rbplusplus.rubyforge.org/rbgccxml
Clone URL: git://github.com/jameskilton/rbgccxml.git
rbgccxml / test / parser_test.rb
100644 74 lines (61 sloc) 2.031 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
require File.join(File.dirname(__FILE__), 'test_helper')
 
context "Default parsing configuration" do
 
  specify "can parse a single header file" do
    should.not.raise do
      RbGCCXML.parse(full_dir("headers/Adder.h"))
    end
  end
 
  specify "can parse a glob" do
    should.not.raise do
      RbGCCXML.parse(full_dir("headers/*.hpp"))
    end
  end
 
  specify "can parse all files in a directory" do
    should.not.raise do
      RbGCCXML.parse(full_dir("headers"),
                    :includes => full_dir("headers/include"),
                    :cxxflags => "-DMUST_BE_DEFINED")
    end
  end
 
  specify "can take an array of files" do
    files = [full_dir("headers/Adder.h"),
              full_dir("headers/Subtracter.hpp")]
    should.not.raise do
      RbGCCXML.parse(files)
    end
  end
 
  specify "can take an array of globs" do
    files = [full_dir("headers/*.h"),
              full_dir("headers/*.hpp")]
    should.not.raise do
      RbGCCXML.parse(files, :includes => full_dir("headers/include"))
    end
  end
 
  specify "should throw an error if files aren't found" do
    should.raise RbGCCXML::SourceNotFoundError do
      RbGCCXML.parse(full_dir("headers/Broken.hcc"))
    end
 
    should.raise RbGCCXML::SourceNotFoundError do
      RbGCCXML.parse(full_dir("hockers"))
    end
 
    should.raise RbGCCXML::SourceNotFoundError do
      RbGCCXML.parse(full_dir("something/*"))
    end
 
    should.raise RbGCCXML::SourceNotFoundError do
      RbGCCXML.parse([full_dir("something/*"), full_dir("anotherthing/*")])
    end
  end
end
 
context "Configurable parsing configuration" do
  specify "can give extra include directories for parsing" do
    found = RbGCCXML.parse full_dir("headers/with_includes.h"),
      :includes => full_dir("headers/include")
    found.namespaces("code").should.not.be.nil
  end
 
  specify "can be given extra cxxflags for parsing" do
    should.not.raise do
      RbGCCXML.parse full_dir("headers/requires_define.hxx"),
        :cxxflags => "-DMUST_BE_DEFINED"
    end
  end
end