GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: Build with Rake: a rake extension to a more complete build system
Homepage: http://github.com
Clone URL: git://github.com/be9/brake.git
Проверка на возвращаемое значение oneliner.
oleg dashevskii (author)
Fri Dec 14 00:55:44 -0800 2007
commit  91cc64f25a2a3b46e1deafd72dfcdd1776cbb3b2
tree    087d6c029124de1d1fd3ff0fdafa308987781709
parent  1d7c48999e6ac6df83b393ad293a1b21d56cb68a
...
1
 
...
1
2
0
@@ -1 +1,2 @@
0
 *.swp
0
+.cache.yaml
...
2
3
4
 
 
5
6
7
...
32
33
34
35
 
36
37
38
 
 
39
40
41
42
 
 
 
43
44
 
 
45
46
 
 
 
 
 
 
 
47
48
49
...
2
3
4
5
6
7
8
9
...
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
0
@@ -2,6 +2,8 @@ require 'logging'
0
 
0
 module Brake
0
   module Checks
0
+ class CheckException < Exception; end
0
+
0
     include Brake::Logging
0
     
0
     def find_program(program_name, paths = [])
0
@@ -32,18 +34,25 @@ module Brake
0
     end
0
 
0
     def try_compile_and_run(name, source_code, ext, compiler)
0
- provide_temp_directory
0
+ provide_temp_directory
0
 
0
- source = "./tmp/try_#{name}_#{$$}.#{ext}"
0
- target = "./tmp/try_#{name}_#{$$}"
0
+ source = "./tmp/try_#{name}_#{$$}.#{ext}"
0
+ target = "./tmp/try_#{name}_#{$$}"
0
 
0
- File.open(source, "w") do |f|
0
- f.write(source_code)
0
- end
0
+ File.open(source, "w") do |f|
0
+ f.write(source_code)
0
+ end
0
 
0
- compiler.oneliner(source, target)
0
+ raise CheckException, "Compiler returned an error" unless compiler.oneliner(source, target)
0
+ raise CheckException, "Compiler stated success, but no target was found" unless File.exists? target
0
 
0
- File.unlink(source)
0
+ rescue CheckException
0
+ return false
0
+ else
0
+ return true
0
+ ensure
0
+ File.unlink(source) if File.exists? source
0
+ File.unlink(target) if File.exists? target
0
     end
0
 
0
     private
...
21
22
23
24
25
26
27
28
 
 
29
 
 
30
31
32
...
21
22
23
 
 
 
 
 
24
25
26
27
28
29
30
31
0
@@ -21,12 +21,11 @@ module Brake
0
         raise GccException, "Compiler didn't produce a working program"
0
           unless try_compile_and_run("int main() { return 0; }\n", "c", self)
0
 
0
- rescue => e
0
- log e.message, :fatal
0
-
0
- return false
0
- end
0
+ rescue => e
0
+ log e.message, :fatal
0
 
0
+ false
0
+ else
0
         true
0
       end
0
     end
...
74
75
76
77
 
78
79
80
81
82
 
83
84
85
...
100
101
102
 
103
104
105
106
107
108
 
109
110
111
...
118
119
120
 
 
 
 
 
 
 
 
 
 
 
 
121
...
74
75
76
 
77
78
79
80
81
 
82
83
84
85
...
100
101
102
103
104
105
106
107
108
 
109
110
111
112
...
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
0
@@ -74,12 +74,12 @@ describe "try_compile_and_run" do
0
   end
0
   
0
   it "should set proper extension for source" do
0
- @compiler.should_receive(:oneliner).with(/\.c$/, an_instance_of(String))
0
+ @compiler.should_receive(:oneliner).with(/\.c$/, an_instance_of(String)).once.and_return(true)
0
     
0
     try_compile_and_run('name', '', 'c', @compiler)
0
     
0
     compiler2 = mock('compiler')
0
- compiler2.should_receive(:oneliner).with(/\.qqq$/, an_instance_of(String))
0
+ compiler2.should_receive(:oneliner).with(/\.qqq$/, an_instance_of(String)).once.and_return(true)
0
     
0
     try_compile_and_run('name', '', 'qqq', compiler2)
0
   end
0
@@ -100,12 +100,13 @@ describe "try_compile_and_run" do
0
     SOURCE_CODE = "/* some code */\nint main() { return 0; }\n"
0
     @compiler.should_receive(:oneliner) do |source, target|
0
       IO.read(source).should == SOURCE_CODE
0
+ true
0
     end
0
 
0
     try_compile_and_run('name', SOURCE_CODE, 'c', @compiler)
0
   end
0
 
0
- it "should remove generated source code upon return" do
0
+ it "should remove generated files upon return" do
0
     @compiler.should_receive(:oneliner) do |source, target|
0
       @source = source
0
       @target = target
0
@@ -118,4 +119,16 @@ describe "try_compile_and_run" do
0
     File.exists?(@source).should_not == true
0
     File.exists?(@target).should_not == true
0
   end
0
+
0
+ it "should return false if compiler failed" do
0
+ @compiler.should_receive(:oneliner).once.and_return(false)
0
+
0
+ try_compile_and_run('name', '', 'c', @compiler).should == false
0
+ end
0
+
0
+ it "should return false if compiler succeeded, but no target found" do
0
+ @compiler.should_receive(:oneliner).once.and_return(true)
0
+
0
+ try_compile_and_run('name', '', 'c', @compiler).should == false
0
+ end
0
 end

Comments

    No one has commented yet.