forked from xtreme-cam/ResourceImagesUsed
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ios_tests.rb
52 lines (37 loc) · 1.5 KB
/
ios_tests.rb
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
require 'test/unit'
class ImagesUsedTest < Test::Unit::TestCase
def run_script(directory,args="")
`./images_used.rb -v #{args} #{directory} > out.txt`
output = File.open("out.txt","r").readlines
result = {}
get_section = Proc.new{ |section_text,output| output.drop_while{ |x| !(x.include?(section_text)) }.drop(2).take_while{ |x| !(x.include?("-------")) }.select{|x| x.strip != ""}.map{|x| x.strip } }
result[:not_used] = get_section.call("Resources not used:",output)
result[:used] = get_section.call("Resources used",output)
result[:duplicates] = get_section.call("Duplicate Resources:",output)
result[:image_files] = get_section.call("Resources:",output)
result[:code_files] = get_section.call("Code Files:",output)
`rm out.txt`
return result
end
def test_without_comments
output = run_script("./Test1")
assert(output[:used].include?("1.png"))
assert(output[:used].include?("2.png"))
assert(output[:used].include?("3.png"))
assert(output[:not_used].empty?)
assert(output[:used].count == 3)
end
def test_with_comments
output = run_script("./Test1","-c")
assert(output[:not_used].include?("1.png"))
assert(output[:used].include?("2.png"))
assert(output[:used].include?("3.png"))
assert(output[:not_used].count == 1)
assert(output[:used].count == 2)
end
def test_for_duplicates
output = run_script("./Test2")
assert(output[:duplicates].count == 1)
assert(output[:duplicates].include?("2.png"))
end
end