mkrf 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (186) hide show
  1. data/CHANGELOG +2 -0
  2. data/MIT-LICENSE +7 -0
  3. data/README +54 -0
  4. data/Rakefile +107 -0
  5. data/lib/mkrf.rb +4 -0
  6. data/lib/mkrf/availability.rb +219 -0
  7. data/lib/mkrf/generator.rb +146 -0
  8. data/test/abstract_unit.rb +4 -0
  9. data/test/fixtures/down_a_directory/header_down_a_directory.h +1 -0
  10. data/test/fixtures/stdmkrf.h +1 -0
  11. data/test/sample_files/libtrivial/Rakefile +31 -0
  12. data/test/sample_files/libtrivial/extconf.rb +3 -0
  13. data/test/sample_files/libtrivial/lib/libtrivial.c +5 -0
  14. data/test/sample_files/libtrivial/lib/libtrivial.o +0 -0
  15. data/test/sample_files/libtrivial/libtrivial_so.bundle +0 -0
  16. data/test/sample_files/libtrivial/mkrf.log +1 -0
  17. data/test/sample_files/libxml-ruby-0.3.8/CHANGELOG +74 -0
  18. data/test/sample_files/libxml-ruby-0.3.8/LICENSE +22 -0
  19. data/test/sample_files/libxml-ruby-0.3.8/README +144 -0
  20. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/cbg.c +76 -0
  21. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/extconf.rb +49 -0
  22. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/libxml.c +86 -0
  23. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/libxml.h +82 -0
  24. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/libxml.rb +107 -0
  25. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/mkrf.log +1 -0
  26. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/old_extconf.rb +95 -0
  27. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_attr.c +372 -0
  28. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_attr.h +21 -0
  29. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_attribute.c +224 -0
  30. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_attribute.h +21 -0
  31. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_document.c +1159 -0
  32. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_document.h +27 -0
  33. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_dtd.c +168 -0
  34. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_dtd.h +17 -0
  35. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_input_cbg.c +167 -0
  36. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_input_cbg.h +21 -0
  37. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_node.c +2139 -0
  38. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_node.h +28 -0
  39. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_node_set.c +248 -0
  40. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_node_set.h +26 -0
  41. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_ns.c +153 -0
  42. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_ns.h +21 -0
  43. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_parser.c +1417 -0
  44. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_parser.h +31 -0
  45. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_parser_context.c +715 -0
  46. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_parser_context.h +22 -0
  47. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_sax_parser.c +426 -0
  48. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_sax_parser.h +52 -0
  49. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_schema.c +142 -0
  50. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_schema.h +16 -0
  51. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_tree.c +43 -0
  52. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_tree.h +12 -0
  53. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xinclude.c +20 -0
  54. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xinclude.h +13 -0
  55. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpath.c +363 -0
  56. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpath.h +24 -0
  57. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpath_context.c +125 -0
  58. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpath_context.h +24 -0
  59. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpointer.c +100 -0
  60. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpointer.h +27 -0
  61. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpointer_context.c +21 -0
  62. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpointer_context.h +18 -0
  63. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/sax_parser_callbacks.inc +202 -0
  64. data/test/sample_files/syck-0.55/CHANGELOG +186 -0
  65. data/test/sample_files/syck-0.55/COPYING +54 -0
  66. data/test/sample_files/syck-0.55/Makefile +582 -0
  67. data/test/sample_files/syck-0.55/Makefile.am +5 -0
  68. data/test/sample_files/syck-0.55/Makefile.in +582 -0
  69. data/test/sample_files/syck-0.55/README +105 -0
  70. data/test/sample_files/syck-0.55/README.BYTECODE +484 -0
  71. data/test/sample_files/syck-0.55/README.EXT +444 -0
  72. data/test/sample_files/syck-0.55/RELEASE +123 -0
  73. data/test/sample_files/syck-0.55/TODO +25 -0
  74. data/test/sample_files/syck-0.55/aclocal.m4 +883 -0
  75. data/test/sample_files/syck-0.55/bootstrap +7 -0
  76. data/test/sample_files/syck-0.55/config.h +79 -0
  77. data/test/sample_files/syck-0.55/config.h.in +78 -0
  78. data/test/sample_files/syck-0.55/config.status +1197 -0
  79. data/test/sample_files/syck-0.55/config/README +14 -0
  80. data/test/sample_files/syck-0.55/config/depcomp +529 -0
  81. data/test/sample_files/syck-0.55/config/install-sh +323 -0
  82. data/test/sample_files/syck-0.55/config/missing +357 -0
  83. data/test/sample_files/syck-0.55/configure +6728 -0
  84. data/test/sample_files/syck-0.55/configure.in +36 -0
  85. data/test/sample_files/syck-0.55/ext/ruby/CHANGELOG +303 -0
  86. data/test/sample_files/syck-0.55/ext/ruby/README +400 -0
  87. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/MANIFEST +1 -0
  88. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/bytecode.c +1170 -0
  89. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/emitter.c +1224 -0
  90. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/extconf.rb +10 -0
  91. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/gram.c +1894 -0
  92. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/gram.h +79 -0
  93. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/handler.c +174 -0
  94. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/implicit.c +2989 -0
  95. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/mkrf.log +1 -0
  96. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/node.c +407 -0
  97. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/rubyext.c +2385 -0
  98. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/syck.c +504 -0
  99. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/syck.h +458 -0
  100. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/token.c +2707 -0
  101. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/yaml2byte.c +250 -0
  102. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/yamlbyte.h +170 -0
  103. data/test/sample_files/syck-0.55/ext/ruby/install.rb +1022 -0
  104. data/test/sample_files/syck-0.55/ext/ruby/lib/okay.rb +161 -0
  105. data/test/sample_files/syck-0.55/ext/ruby/lib/okay/news.rb +69 -0
  106. data/test/sample_files/syck-0.55/ext/ruby/lib/okay/rpc.rb +434 -0
  107. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml.rb +436 -0
  108. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/baseemitter.rb +247 -0
  109. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/basenode.rb +216 -0
  110. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/compat.rb +26 -0
  111. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/constants.rb +45 -0
  112. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/dbm.rb +111 -0
  113. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/emitter.rb +107 -0
  114. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/encoding.rb +33 -0
  115. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/error.rb +34 -0
  116. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/rubytypes.rb +438 -0
  117. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/store.rb +29 -0
  118. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/stream.rb +40 -0
  119. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/stringio.rb +83 -0
  120. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/syck.rb +19 -0
  121. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/tag.rb +86 -0
  122. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/types.rb +188 -0
  123. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/yamlnode.rb +54 -0
  124. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/ypath.rb +52 -0
  125. data/test/sample_files/syck-0.55/ext/ruby/lib/yod.rb +1168 -0
  126. data/test/sample_files/syck-0.55/ext/ruby/samples/okayNews-modules.rb +27 -0
  127. data/test/sample_files/syck-0.55/ext/ruby/samples/okayNews-sample.rb +336 -0
  128. data/test/sample_files/syck-0.55/ext/ruby/samples/okayNews-validate.rb +341 -0
  129. data/test/sample_files/syck-0.55/ext/ruby/samples/okayRpc-client.rb +51 -0
  130. data/test/sample_files/syck-0.55/ext/ruby/samples/okayRpc-server.rb +85 -0
  131. data/test/sample_files/syck-0.55/ext/ruby/samples/yaml-sortHashKeys.rb +128 -0
  132. data/test/sample_files/syck-0.55/ext/ruby/tests/basic.rb +1653 -0
  133. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsAnchorAlias.yml +51 -0
  134. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsBasicTests.yml +282 -0
  135. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsBlockMapping.yml +78 -0
  136. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsBlockSequence.yml +0 -0
  137. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsDocumentSeparator.yml +102 -0
  138. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsErrorTests.yml +23 -0
  139. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsFlowCollections.yml +73 -0
  140. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsFoldedScalars.yml +215 -0
  141. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsMapInSeq.yml +0 -0
  142. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsNullsAndEmpties.yml +66 -0
  143. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsRubyTests.yml +182 -0
  144. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsSpecificationExamples.yml +2699 -0
  145. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsTypeTransfers.yml +265 -0
  146. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsYpath.yml +221 -0
  147. data/test/sample_files/syck-0.55/ext/ruby/yts/cookbook.rb +159 -0
  148. data/test/sample_files/syck-0.55/ext/ruby/yts/index.yml +10 -0
  149. data/test/sample_files/syck-0.55/ext/ruby/yts/yts.rb +193 -0
  150. data/test/sample_files/syck-0.55/lib/Makefile +497 -0
  151. data/test/sample_files/syck-0.55/lib/Makefile.am +27 -0
  152. data/test/sample_files/syck-0.55/lib/Makefile.in +497 -0
  153. data/test/sample_files/syck-0.55/lib/bytecode.c +1170 -0
  154. data/test/sample_files/syck-0.55/lib/bytecode.re +525 -0
  155. data/test/sample_files/syck-0.55/lib/emitter.c +1224 -0
  156. data/test/sample_files/syck-0.55/lib/gram.c +1894 -0
  157. data/test/sample_files/syck-0.55/lib/gram.h +79 -0
  158. data/test/sample_files/syck-0.55/lib/gram.output +2005 -0
  159. data/test/sample_files/syck-0.55/lib/gram.y +481 -0
  160. data/test/sample_files/syck-0.55/lib/handler.c +174 -0
  161. data/test/sample_files/syck-0.55/lib/implicit.c +2989 -0
  162. data/test/sample_files/syck-0.55/lib/implicit.re +206 -0
  163. data/test/sample_files/syck-0.55/lib/node.c +407 -0
  164. data/test/sample_files/syck-0.55/lib/syck.c +504 -0
  165. data/test/sample_files/syck-0.55/lib/syck.h +458 -0
  166. data/test/sample_files/syck-0.55/lib/syck_st.c +577 -0
  167. data/test/sample_files/syck-0.55/lib/syck_st.h +46 -0
  168. data/test/sample_files/syck-0.55/lib/token.c +2707 -0
  169. data/test/sample_files/syck-0.55/lib/token.re +1139 -0
  170. data/test/sample_files/syck-0.55/lib/yaml2byte.c +250 -0
  171. data/test/sample_files/syck-0.55/lib/yamlbyte.h +170 -0
  172. data/test/sample_files/syck-0.55/stamp-h1 +1 -0
  173. data/test/sample_files/syck-0.55/tests/Basic.c +141 -0
  174. data/test/sample_files/syck-0.55/tests/CuTest.c +294 -0
  175. data/test/sample_files/syck-0.55/tests/CuTest.h +84 -0
  176. data/test/sample_files/syck-0.55/tests/Emit.c +87 -0
  177. data/test/sample_files/syck-0.55/tests/Makefile +480 -0
  178. data/test/sample_files/syck-0.55/tests/Makefile.am +13 -0
  179. data/test/sample_files/syck-0.55/tests/Makefile.in +480 -0
  180. data/test/sample_files/syck-0.55/tests/Parse.c +208 -0
  181. data/test/sample_files/syck-0.55/tests/YTS.c +2310 -0
  182. data/test/sample_files/syck-0.55/tests/YTS.c.erb +326 -0
  183. data/test/sample_files/syck-0.55/tests/YTS.c.rb +44 -0
  184. data/test/test_availability.rb +68 -0
  185. data/test/test_generator.rb +74 -0
  186. metadata +252 -0
@@ -0,0 +1,326 @@
1
+ //
2
+ // YTS.c
3
+ //
4
+ // $Author: why $
5
+ // $Date: 2005/04/13 06:27:54 $
6
+ //
7
+ // Copyright (C) 2004 why the lucky stiff
8
+ //
9
+ // Well, this is the Yaml Testing Suite in the form of a plain C
10
+ // API. Basically, this is as good as C integration gets for Syck.
11
+ // You've got to have a symbol table around. From there, you can
12
+ // query your data.
13
+ //
14
+
15
+ #include <string.h>
16
+ #include "syck.h"
17
+ #include "CuTest.h"
18
+
19
+ /* YAML test node structures */
20
+ #define T_STR 10
21
+ #define T_SEQ 20
22
+ #define T_MAP 30
23
+ #define T_END 40
24
+ #define ILEN 2
25
+
26
+ struct test_node {
27
+ int type;
28
+ char *tag;
29
+ char *key;
30
+ struct test_node *value;
31
+ };
32
+ struct test_node end_node = { T_END };
33
+
34
+ /*
35
+ * Assertion which compares a YAML document with an
36
+ * equivalent set of test_node structs.
37
+ */
38
+ SYMID
39
+ syck_copy_handler(p, n)
40
+ SyckParser *p;
41
+ SyckNode *n;
42
+ {
43
+ int i = 0;
44
+ struct test_node *tn = S_ALLOC_N( struct test_node, 1 );
45
+
46
+ switch ( n->kind )
47
+ {
48
+ case syck_str_kind:
49
+ tn->type = T_STR;
50
+ tn->key = syck_strndup( n->data.str->ptr, n->data.str->len );
51
+ tn->value = 0;
52
+ break;
53
+
54
+ case syck_seq_kind:
55
+ {
56
+ struct test_node *val;
57
+ struct test_node *seq = S_ALLOC_N( struct test_node, n->data.list->idx + 1 );
58
+ tn->type = T_SEQ;
59
+ tn->key = 0;
60
+ for ( i = 0; i < n->data.list->idx; i++ )
61
+ {
62
+ SYMID oid = syck_seq_read( n, i );
63
+ syck_lookup_sym( p, oid, (char **)&val );
64
+ seq[i] = val[0];
65
+ }
66
+ seq[n->data.list->idx] = end_node;
67
+ tn->value = seq;
68
+ }
69
+ break;
70
+
71
+ case syck_map_kind:
72
+ {
73
+ struct test_node *val;
74
+ struct test_node *map = S_ALLOC_N( struct test_node, ( n->data.pairs->idx * 2 ) + 1 );
75
+ tn->type = T_MAP;
76
+ tn->key = 0;
77
+ for ( i = 0; i < n->data.pairs->idx; i++ )
78
+ {
79
+ SYMID oid = syck_map_read( n, map_key, i );
80
+ syck_lookup_sym( p, oid, (char **)&val );
81
+ map[i * 2] = val[0];
82
+
83
+ oid = syck_map_read( n, map_value, i );
84
+ syck_lookup_sym( p, oid, (char **)&val );
85
+ map[(i * 2) + 1] = val[0];
86
+ }
87
+ map[n->data.pairs->idx * 2] = end_node;
88
+ tn->value = map;
89
+ }
90
+ break;
91
+ }
92
+
93
+ tn->tag = 0;
94
+ if ( n->type_id != NULL ) {
95
+ tn->tag = syck_strndup( n->type_id, strlen( n->type_id ) );
96
+ }
97
+
98
+ return syck_add_sym( p, (char *) tn );
99
+ }
100
+
101
+ int
102
+ syck_free_copies( char *key, struct test_node *tn, char *arg )
103
+ {
104
+ if ( tn != NULL ) {
105
+ switch ( tn->type ) {
106
+ case T_STR:
107
+ S_FREE( tn->key );
108
+ break;
109
+
110
+ case T_SEQ:
111
+ case T_MAP:
112
+ S_FREE( tn->value );
113
+ break;
114
+ }
115
+ if ( tn->tag != NULL ) S_FREE( tn->tag );
116
+ S_FREE( tn );
117
+ }
118
+ tn = NULL;
119
+ return ST_CONTINUE;
120
+ }
121
+
122
+ void CuStreamCompareX( CuTest* tc, struct test_node *s1, struct test_node *s2 ) {
123
+ int i = 0;
124
+ while ( 1 ) {
125
+ CuAssertIntEquals( tc, s1[i].type, s2[i].type );
126
+ if ( s1[i].type == T_END ) return;
127
+ if ( s1[i].tag != 0 && s2[i].tag != 0 ) CuAssertStrEquals( tc, s1[i].tag, s2[i].tag );
128
+ switch ( s1[i].type ) {
129
+ case T_STR:
130
+ CuAssertStrEquals( tc, s1[i].key, s2[i].key );
131
+ break;
132
+ case T_SEQ:
133
+ case T_MAP:
134
+ CuStreamCompareX( tc, s1[i].value, s2[i].value );
135
+ break;
136
+ }
137
+ i++;
138
+ }
139
+ }
140
+
141
+ void CuStreamCompare( CuTest* tc, char *yaml, struct test_node *stream ) {
142
+ int doc_ct = 0;
143
+ struct test_node *ystream = S_ALLOC_N( struct test_node, doc_ct + 1 );
144
+ CuString *msg;
145
+
146
+ /* Set up parser */
147
+ SyckParser *parser = syck_new_parser();
148
+ syck_parser_str_auto( parser, yaml, NULL );
149
+ syck_parser_handler( parser, syck_copy_handler );
150
+ syck_parser_error_handler( parser, NULL );
151
+ syck_parser_implicit_typing( parser, 1 );
152
+ syck_parser_taguri_expansion( parser, 1 );
153
+
154
+ /* Parse all streams */
155
+ while ( 1 )
156
+ {
157
+ struct test_node *ydoc;
158
+ SYMID oid = syck_parse( parser );
159
+ if ( parser->eof == 1 ) break;
160
+
161
+ /* Add document to stream */
162
+ syck_lookup_sym( parser, oid, (char **)&ydoc );
163
+ ystream[doc_ct] = ydoc[0];
164
+ doc_ct++;
165
+ S_REALLOC_N( ystream, struct test_node, doc_ct + 1 );
166
+ }
167
+ ystream[doc_ct] = end_node;
168
+
169
+ /* Traverse the struct and the symbol table side-by-side */
170
+ /* DEBUG: y( stream, 0 ); y( ystream, 0 ); */
171
+ CuStreamCompareX( tc, stream, ystream );
172
+
173
+ /* Free the node tables and the parser */
174
+ S_FREE( ystream );
175
+ if ( parser->syms != NULL )
176
+ st_foreach( parser->syms, syck_free_copies, 0 );
177
+ syck_free_parser( parser );
178
+ }
179
+
180
+ /*
181
+ * Setup for testing N->Y->N.
182
+ */
183
+ void
184
+ test_output_handler( emitter, str, len )
185
+ SyckEmitter *emitter;
186
+ char *str;
187
+ long len;
188
+ {
189
+ CuString *dest = (CuString *)emitter->bonus;
190
+ CuStringAppendLen( dest, str, len );
191
+ }
192
+
193
+ SYMID
194
+ build_symbol_table( SyckEmitter *emitter, struct test_node *node ) {
195
+ switch ( node->type ) {
196
+ case T_SEQ:
197
+ case T_MAP:
198
+ {
199
+ int i = 0;
200
+ while ( node->value[i].type != T_END ) {
201
+ SYMID id = build_symbol_table( emitter, &node->value[i] );
202
+ i++;
203
+ }
204
+ }
205
+ return syck_emitter_mark_node( emitter, (st_data_t)node );
206
+
207
+ case T_STR:
208
+ return 0;
209
+ }
210
+ }
211
+
212
+ void
213
+ test_emitter_handler( SyckEmitter *emitter, st_data_t data ) {
214
+ struct test_node *node = (struct test_node *)data;
215
+ switch ( node->type ) {
216
+ case T_STR:
217
+ syck_emit_scalar( emitter, node->tag, scalar_none, 0, 0, 0, node->key, strlen( node->key ) );
218
+ break;
219
+ case T_SEQ:
220
+ {
221
+ int i = 0;
222
+ syck_emit_seq( emitter, node->tag, seq_none );
223
+ while ( node->value[i].type != T_END ) {
224
+ syck_emit_item( emitter, (st_data_t)&node->value[i] );
225
+ i++;
226
+ }
227
+ syck_emit_end( emitter );
228
+ }
229
+ break;
230
+ case T_MAP:
231
+ {
232
+ int i = 0;
233
+ syck_emit_map( emitter, node->tag, map_none );
234
+ while ( node->value[i].type != T_END ) {
235
+ syck_emit_item( emitter, (st_data_t)&node->value[i] );
236
+ i++;
237
+ }
238
+ syck_emit_end( emitter );
239
+ }
240
+ break;
241
+ }
242
+ }
243
+
244
+ void CuRoundTrip( CuTest* tc, struct test_node *stream ) {
245
+ int i = 0;
246
+ CuString *cs = CuStringNew();
247
+ SyckEmitter *emitter = syck_new_emitter();
248
+
249
+ /* Calculate anchors and tags */
250
+ build_symbol_table( emitter, stream );
251
+
252
+ /* Build the stream */
253
+ syck_output_handler( emitter, test_output_handler );
254
+ syck_emitter_handler( emitter, test_emitter_handler );
255
+ emitter->bonus = cs;
256
+ while ( stream[i].type != T_END )
257
+ {
258
+ syck_emit( emitter, (st_data_t)&stream[i] );
259
+ syck_emitter_flush( emitter, 0 );
260
+ i++;
261
+ }
262
+
263
+ /* Reload the stream and compare */
264
+ /* printf( "-- output for %s --\n%s\n--- end of output --\n", tc->name, cs->buffer ); */
265
+ CuStreamCompare( tc, cs->buffer, stream );
266
+ CuStringFree( cs );
267
+
268
+ syck_free_emitter( emitter );
269
+ }
270
+
271
+ /*
272
+ * ACTUAL TESTS FOR THE YAML TESTING SUITE BEGIN HERE
273
+ * (EVERYTHING PREVIOUS WAS SET UP FOR THE TESTS)
274
+ */
275
+
276
+ % syck_tests.each do |yt|
277
+ /*
278
+ * Example <%= yt['spec'] %>: <%= yt['test'] %>
279
+ */
280
+ void
281
+ <%= yt['func'] %>( CuTest *tc )
282
+ {
283
+ <%= yt['syck'] %>
284
+
285
+ CuStreamCompare( tc,
286
+
287
+ /* YAML document */
288
+ <%= yt['yaml'].gsub( /\\/, '\\\\\\\\' ).gsub( '"', '\"' ).gsub( /^(.*)$/, '"\1\n"' ) %>
289
+ ,
290
+
291
+ /* C structure of validations */
292
+ stream
293
+ );
294
+
295
+ CuRoundTrip( tc, stream );
296
+ }
297
+ % end
298
+
299
+ CuSuite *
300
+ SyckGetSuite()
301
+ {
302
+ CuSuite *suite = CuSuiteNew();
303
+ % syck_tests.each do |yt|
304
+ SUITE_ADD_TEST( suite, <%= yt['func'] %> );
305
+ % end
306
+ return suite;
307
+ }
308
+
309
+ int main(void)
310
+ {
311
+ CuString *output = CuStringNew();
312
+ CuSuite* suite = SyckGetSuite();
313
+ int count;
314
+
315
+ CuSuiteRun(suite);
316
+ CuSuiteSummary(suite, output);
317
+ CuSuiteDetails(suite, output);
318
+
319
+ printf("%s\n", output->buffer);
320
+ count = suite->failCount;
321
+
322
+ CuStringFree( output );
323
+ CuSuiteFree( suite );
324
+
325
+ return count;
326
+ }
@@ -0,0 +1,44 @@
1
+ #
2
+ # YTS.c.rb
3
+ #
4
+ # $Author: why $
5
+ # $Date: 2005/01/02 04:33:40 $
6
+ #
7
+ # Copyright (C) 2004 why the lucky stiff
8
+ #
9
+ # This Ruby script generates the YTS suite for the
10
+ # Syck base lib. Basically, it searches ext/ruby/yts/ for
11
+ # tests with a 'syck' entry.
12
+ #
13
+ # To regenerate things yourself:
14
+ #
15
+ # ruby YTS.c.rb > YTS.c
16
+ #
17
+ # Oh and your Ruby must have YAML installed.
18
+ #
19
+ require 'erb'
20
+ require 'yaml'
21
+
22
+ # Find the Syck directory.
23
+ yts_dir = "ext/ruby/yts/"
24
+ syck_dir = ""
25
+ while File.expand_path( syck_dir ) != "/"
26
+ break if File.directory?( syck_dir + yts_dir )
27
+ syck_dir << "../"
28
+ end
29
+ yts_dir = syck_dir + yts_dir
30
+ abort "No YTS directory found" unless File.directory?( yts_dir )
31
+
32
+ # Load the YTS
33
+ syck_tests = []
34
+ YAML::load( File.open( yts_dir + "index.yml" ) ).each do |yst|
35
+ ct = 0
36
+ YAML.each_document( File.open( yts_dir + yst + ".yml" ) ) do |ydoc|
37
+ ydoc['group'] = yst
38
+ ydoc['func'] = "#{ ydoc['group'] }_#{ ct }"
39
+ syck_tests << ydoc if ydoc['syck']
40
+ ct += 1
41
+ end
42
+ end
43
+
44
+ puts ERB.new( File.read( syck_dir + "tests/YTS.c.erb" ), 0, "%<>" ).result
@@ -0,0 +1,68 @@
1
+ require File.dirname(__FILE__) + '/abstract_unit'
2
+
3
+ class TestAvailability < Test::Unit::TestCase
4
+ def setup
5
+ @avail = Mkrf::Availability.new(:includes => File.join(File.dirname(__FILE__), 'fixtures'))
6
+ end
7
+
8
+ def test_has_library_should_return_true_when_lib_already_loaded
9
+ @avail = Mkrf::Availability.new(:loaded_libs => ['sample_library'])
10
+ assert @avail.has_library?('sample_library')
11
+ end
12
+
13
+ def test_has_library_should_fail_on_bogus_lib
14
+ assert !@avail.has_library?('bogus_library')
15
+ end
16
+
17
+ def test_can_link
18
+ @avail.send(:with_headers, 'stdio.h') do
19
+ assert @avail.can_link?(@avail.send(:simple_reference, "printf"))
20
+ end
21
+ end
22
+
23
+ def test_create_source
24
+ assert !File.exist?(Mkrf::Availability::TEMP_SOURCE_FILE)
25
+
26
+ @avail.send(:create_source, "puts 'Hello World!'")
27
+
28
+ assert File.exist?(Mkrf::Availability::TEMP_SOURCE_FILE)
29
+
30
+ source = File.open(Mkrf::Availability::TEMP_SOURCE_FILE).read
31
+ assert_equal "puts 'Hello World!'", source
32
+ ensure
33
+ FileUtils.rm_f Mkrf::Availability::TEMP_SOURCE_FILE
34
+ end
35
+
36
+ def test_has_header_should_fail_on_bogus_header
37
+ assert !@avail.has_header?('some_fake_header.h')
38
+ end
39
+
40
+ def test_has_header_should_work_with_basic_headers
41
+ assert @avail.has_header?('stdmkrf.h')
42
+ end
43
+
44
+ def test_has_header_should_check_many_paths
45
+ assert !@avail.has_header?('header_down_a_directory.h')
46
+ assert @avail.has_header?('header_down_a_directory.h', File.join(File.dirname(__FILE__), 'fixtures', 'down_a_directory'))
47
+ end
48
+
49
+ def test_include_header
50
+ assert @avail.has_header?('stdmkrf.h')
51
+ assert !@avail.headers.include?('stdmkrf.h')
52
+ @avail.include_header('stdmkrf.h')
53
+ assert @avail.headers.include?('stdmkrf.h')
54
+ end
55
+
56
+ # This should really use a trivial lib compiled in fixtures..
57
+ def test_include_library
58
+ assert @avail.has_library?('z')
59
+ assert !@avail.loaded_libs.include?('z')
60
+ @avail.include_library('z')
61
+ assert @avail.loaded_libs.include?('z')
62
+ end
63
+
64
+ def test_method_missing_should_go_down_chain_when_not_catching_stackable_attributes
65
+ assert_raises(NoMethodError) { @avail.not_a_stackable_attribute }
66
+ assert_raises(NoMethodError) { @avail.with_not_a_stackable_attribute }
67
+ end
68
+ end
@@ -0,0 +1,74 @@
1
+ require File.dirname(__FILE__) + '/abstract_unit'
2
+
3
+ class TestGenerator < Test::Unit::TestCase
4
+ SAMPLES_DIR = File.dirname(__FILE__) + '/sample_files'
5
+
6
+ SAMPLE_LIBS = {
7
+ :libtrivial => '/libtrivial/libtrivial_so.bundle',
8
+ :syck => '/syck-0.55/ext/ruby/ext/syck/syck.bundle',
9
+ :libxml => '/libxml-ruby-0.3.8/ext/xml/libxml_so.bundle'
10
+ }
11
+
12
+ # Set to true for full command line output
13
+ @@debug = false
14
+
15
+ def setup
16
+ silence_command_line do
17
+ system('rake test:samples:clean')
18
+ end
19
+ end
20
+
21
+ def test_that_trivial_lib_compiles
22
+ assert !File.exist?(SAMPLES_DIR + SAMPLE_LIBS[:libtrivial])
23
+ silence_command_line do
24
+ system('rake test:samples:trivial')
25
+ end
26
+ assert File.exist?(SAMPLES_DIR + SAMPLE_LIBS[:libtrivial])
27
+ end
28
+
29
+ def test_that_syck_compiles
30
+ assert !File.exist?(SAMPLES_DIR + SAMPLE_LIBS[:syck])
31
+ silence_command_line do
32
+ system('rake test:samples:syck')
33
+ end
34
+ assert File.exist?(SAMPLES_DIR + SAMPLE_LIBS[:syck])
35
+ end
36
+
37
+ def test_that_libxml_compiles
38
+ assert !File.exist?(SAMPLES_DIR + SAMPLE_LIBS[:libxml])
39
+ silence_command_line do
40
+ system('rake test:samples:libxml')
41
+ end
42
+ assert File.exist?(SAMPLES_DIR + SAMPLE_LIBS[:libxml])
43
+ end
44
+
45
+ private
46
+
47
+ def silence_command_line
48
+ yield and return if @@debug
49
+ silence_stream(STDERR) do
50
+ silence_stream(STDOUT) do
51
+ yield
52
+ end
53
+ end
54
+ end
55
+
56
+ # silence_stream taken from Rails ActiveSupport reporting.rb
57
+
58
+ # Silences any stream for the duration of the block.
59
+ #
60
+ # silence_stream(STDOUT) do
61
+ # puts 'This will never be seen'
62
+ # end
63
+ #
64
+ # puts 'But this will'
65
+ def silence_stream(stream)
66
+ old_stream = stream.dup
67
+ stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
68
+ stream.sync = true
69
+ yield
70
+ ensure
71
+ stream.reopen(old_stream)
72
+ end
73
+
74
+ end