take 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/take/unit/compiler.rb +19 -4
- data/lib/take/unit/generator.rb +63 -9
- data/lib/take/unit.rb +1 -1
- data/lib/take/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f0dd40278e101af1c56a63ba7fd15b6a07f1fbd5
|
4
|
+
data.tar.gz: 6e584d10586014e16b539ef49025407810a8e856
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eff9b00d672abf0748ea3023a85b431c0ee95cda810ad0a6c78131dfbb6441681d9a22cd900ca1b05e49077c0c217b71b7a039e48d41d827670c9007710f4105
|
7
|
+
data.tar.gz: eee7c6b5424714509702d47a832f7db9f976ac829918aa5fc15f9297e73ba2d3821f9eca5c5a5767f244dd356a0741e0a253576dce51023f1f30655ca8a802e9
|
data/lib/take/unit/compiler.rb
CHANGED
@@ -15,12 +15,15 @@ module Take
|
|
15
15
|
|
16
16
|
def compile
|
17
17
|
@parent ||= begin
|
18
|
-
@parent = AST::Parent.new(name: @file.
|
19
|
-
gsub(/\..*\z/, "")
|
18
|
+
@parent = AST::Parent.new(name: File.basename(@file).
|
19
|
+
gsub(/\..*\z/, ""))
|
20
20
|
while peek do
|
21
|
-
|
21
|
+
part = predict(:group => :group, :prefix => :prefix)
|
22
|
+
@parent.children << part if part
|
22
23
|
end
|
23
24
|
|
25
|
+
add_parent_prefix
|
26
|
+
|
24
27
|
@parent.source = sourcify([0, 0])
|
25
28
|
@parent
|
26
29
|
end
|
@@ -45,7 +48,6 @@ module Take
|
|
45
48
|
:test => :test,
|
46
49
|
:before => :before,
|
47
50
|
:after => :after,
|
48
|
-
:prefix => :prefix,
|
49
51
|
:macro => :macro
|
50
52
|
end
|
51
53
|
|
@@ -114,6 +116,19 @@ module Take
|
|
114
116
|
hash.merge(file: @file)
|
115
117
|
end
|
116
118
|
|
119
|
+
def add_parent_prefix
|
120
|
+
prefix = AST::Prefix.new(name: "_generated_prefix")
|
121
|
+
|
122
|
+
prefix.children << AST::Block.new(body: <<-DOC)
|
123
|
+
|
124
|
+
#define __FILE \"#{@file}\"
|
125
|
+
#include \"utest.h\"
|
126
|
+
static size_t tests = 0;
|
127
|
+
static size_t failed = 0;
|
128
|
+
DOC
|
129
|
+
@parent.children << prefix
|
130
|
+
end
|
131
|
+
|
117
132
|
end
|
118
133
|
end
|
119
134
|
end
|
data/lib/take/unit/generator.rb
CHANGED
@@ -6,6 +6,7 @@ module Take
|
|
6
6
|
@parent = parent
|
7
7
|
@groups = [@parent]
|
8
8
|
@options = options
|
9
|
+
@group_functions = []
|
9
10
|
end
|
10
11
|
|
11
12
|
def generate
|
@@ -48,26 +49,56 @@ module Take
|
|
48
49
|
group.children.select(&:test?).
|
49
50
|
each { |child| walk(child) }
|
50
51
|
|
51
|
-
@
|
52
|
-
|
53
|
-
|
52
|
+
@group_functions << "group_#{group_name}"
|
53
|
+
|
54
|
+
@output << <<-CODE
|
55
|
+
// group #{group_name}
|
56
|
+
void group_#{group_name}()
|
57
|
+
{
|
58
|
+
|
59
|
+
output(TEXT_COLOR_MAGENTA "\\tSET \\"" TEXT_COLOR_BOLD_MAGENTA
|
60
|
+
"#{group_name}" TEXT_COLOR_MAGENTA "\\":\\n");
|
61
|
+
CODE
|
54
62
|
@output << group.children.select(&:test?).
|
55
63
|
map { |child| " test_#{group_name(child)}();" }.
|
56
64
|
join("\n")
|
57
65
|
@output << "\n"
|
58
|
-
afters.each { |child| walk(child) }
|
59
66
|
@output << "}\n\n"
|
60
67
|
@groups.pop
|
61
68
|
end
|
62
69
|
|
63
70
|
def walk_test(node)
|
64
|
-
@output <<
|
71
|
+
@output << <<-CODE
|
72
|
+
void test_#{group_name(node)}()
|
73
|
+
{
|
74
|
+
tests++;
|
75
|
+
int test_success = 1;
|
76
|
+
output(TEXT_COLOR_MAGENTA "\\t\\tTEST \\"" TEXT_COLOR_BOLD_MAGENTA
|
77
|
+
"#{node.name}" TEXT_COLOR_MAGENTA "\\": ");
|
78
|
+
|
79
|
+
CODE
|
80
|
+
befores.each { |child| walk(child) }
|
65
81
|
node.children.select(&:block?).each { |child| walk(child) }
|
66
|
-
|
82
|
+
afters.each { |child| walk(child) }
|
83
|
+
@output << <<-CODE
|
84
|
+
|
85
|
+
if(test_success)
|
86
|
+
{
|
87
|
+
#ifdef VERBOSE
|
88
|
+
output("\\n\\t\\t\\t" TEXT_COLOR_GREEN "OK\\n");
|
89
|
+
#else
|
90
|
+
output(TEXT_COLOR_BOLD_GREEN "OK\\n");
|
91
|
+
#endif
|
92
|
+
}
|
93
|
+
}
|
94
|
+
CODE
|
67
95
|
end
|
68
96
|
|
69
97
|
def walk_block(node, indent = 2)
|
70
|
-
|
98
|
+
if node.source
|
99
|
+
@output << "#line #{node.source.line + 2}" \
|
100
|
+
" \"#{node.source.file}\""
|
101
|
+
end
|
71
102
|
lines = node.body.each_line
|
72
103
|
deindent = if scan = node.body.scan(/^[ \t]*(?=\S)/).min
|
73
104
|
scan.size
|
@@ -76,7 +107,8 @@ module Take
|
|
76
107
|
end
|
77
108
|
|
78
109
|
body = lines.map { |l| l.gsub(/^[ \t]{#{deindent}}/, "") }.
|
79
|
-
map { |l| (" " * indent) << l }.join("").rstrip.
|
110
|
+
map { |l| (" " * indent) << l }.join("").rstrip.
|
111
|
+
gsub(/^[ \t]+$/, "")
|
80
112
|
|
81
113
|
@output << body << "\n"
|
82
114
|
reset
|
@@ -85,6 +117,28 @@ module Take
|
|
85
117
|
def walk_parent(node)
|
86
118
|
node.children.select(&:prefix?).each { |child| walk(child) }
|
87
119
|
node.children.reject(&:prefix?).each { |child| walk(child) }
|
120
|
+
@output << <<-CODE
|
121
|
+
int main()
|
122
|
+
{
|
123
|
+
output(TEXT_COLOR_MAGENTA "FILE \\"" TEXT_COLOR_BOLD_MAGENTA
|
124
|
+
__FILE TEXT_COLOR_MAGENTA "\\":\\n");
|
125
|
+
|
126
|
+
CODE
|
127
|
+
|
128
|
+
@group_functions.each { |func| @output << " #{func}();\n" }
|
129
|
+
|
130
|
+
@output << <<-CODE
|
131
|
+
output2("\\n\\t" TEXT_COLOR_MAGENTA "RESULT:\\n\\t\\t"
|
132
|
+
"PASSED: " TEXT_COLOR_BOLD_MAGENTA "%zu"
|
133
|
+
TEXT_COLOR_MAGENTA "\\n\\t\\tFAILED: "
|
134
|
+
TEXT_COLOR_BOLD_MAGENTA "%zu" TEXT_COLOR_MAGENTA
|
135
|
+
"\\n", tests - failed, failed);
|
136
|
+
|
137
|
+
return TEST_RETURN;
|
138
|
+
}
|
139
|
+
|
140
|
+
CODE
|
141
|
+
|
88
142
|
end
|
89
143
|
|
90
144
|
def walk_node(node)
|
@@ -116,7 +170,7 @@ module Take
|
|
116
170
|
end
|
117
171
|
|
118
172
|
def reset
|
119
|
-
@output << "#line \"#{@parent.name}.c\"
|
173
|
+
@output << "#line #{line} \"#{@parent.name}.c\"\n"
|
120
174
|
end
|
121
175
|
|
122
176
|
def befores
|
data/lib/take/unit.rb
CHANGED
@@ -15,7 +15,7 @@ module Take
|
|
15
15
|
compiler = Compiler.new(file.path, scanner.scan)
|
16
16
|
generator = Generator.new(compiler.compile,
|
17
17
|
directory: File.dirname(file.path)).tap(&:generate)
|
18
|
-
generator.write_file(file.path.gsub(/\..*\z/, ".c")
|
18
|
+
generator.write_file(file.path.gsub(/\..*\z/, ".c"))
|
19
19
|
end
|
20
20
|
|
21
21
|
end
|
data/lib/take/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: take
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Rodi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|