PageRenderTime 63ms CodeModel.GetById 36ms RepoModel.GetById 0ms app.codeStats 0ms

/Rakefile

http://github.com/eahanson/Expectacular
Rakefile | 100 lines | 85 code | 15 blank | 0 comment | 4 complexity | 3650d3f8b26ea78b4c366224061d4c9e MD5 | raw file
  1. PROJECT_NAME = "Expectacular"
  2. CONFIGURATION = "Release"
  3. SPECS_TARGET_NAME = "Specs"
  4. SDK_DIR = "/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk"
  5. def build_dir(effective_platform_name)
  6. File.join(File.dirname(__FILE__), "build", CONFIGURATION + effective_platform_name)
  7. end
  8. def system_or_exit(cmd, stdout = nil)
  9. puts "Executing #{cmd}"
  10. cmd += " >#{stdout} 2>&1" if stdout
  11. system(cmd) or raise "******** Build failed ********"
  12. end
  13. def output_file(target)
  14. output_dir = ENV['IS_CI_BOX'] ? ENV['CC_BUILD_ARTIFACTS'] : File.join(File.dirname(__FILE__), "build")
  15. output_file = File.join(output_dir, "build_#{target}.output")
  16. puts "Output: #{output_file}"
  17. return output_file
  18. end
  19. desc "Run all specs and uispecs"
  20. task :default => [:specs]
  21. desc "Run on cruisecontrol"
  22. task :cruise do
  23. Rake::Task[:clean].invoke
  24. Rake::Task[:specs].invoke
  25. end
  26. desc "Clean"
  27. task :clean do
  28. stdout = File.join(ENV['CC_BUILD_ARTIFACTS'], "clean.output") if (ENV['IS_CI_BOX'])
  29. system_or_exit(%Q[xcodebuild -project #{PROJECT_NAME}.xcodeproj -alltargets -configuration #{CONFIGURATION} clean], output_file("clean"))
  30. end
  31. desc "Build"
  32. task :build => :gen do
  33. stdout = File.join(ENV['CC_BUILD_ARTIFACTS'], "build_all.output") if (ENV['IS_CI_BOX'])
  34. system_or_exit(%Q[xcodebuild -project #{PROJECT_NAME}.xcodeproj -alltargets -configuration #{CONFIGURATION} build], output_file("build"))
  35. end
  36. desc "Run specs"
  37. task :specs => :build do
  38. build_dir = build_dir("")
  39. ENV["DYLD_FRAMEWORK_PATH"] = build_dir
  40. system_or_exit("cd #{build_dir} && ./#{SPECS_TARGET_NAME}")
  41. puts("\n\n")
  42. end
  43. desc "Generate code"
  44. task :gen do
  45. require 'erb'
  46. @integer_types = [
  47. { :type => "char", :name => "char", :converter => "%c" },
  48. { :type => "int", :name => "int", :converter => "%d" },
  49. { :type => "short", :name => "short", :converter => "%d" },
  50. { :type => "long", :name => "long", :converter => "%d" },
  51. { :type => "long long", :name => "longLong", :converter => "%d" },
  52. { :type => "unsigned char", :name => "unsignedChar", :converter => "%u" },
  53. { :type => "unsigned int", :name => "unsignedInt", :converter => "%u" },
  54. { :type => "unsigned short", :name => "unsignedShort", :converter => "%u" },
  55. { :type => "unsigned long", :name => "unsignedLong", :converter => "%u" },
  56. { :type => "unsigned long long", :name => "unsignedLongLong", :converter => "%u" }
  57. ]
  58. @integer_matchers = [
  59. { :predicate => "return expected == actual;", :matcher => "toEqual", :matcher_description => "to equal" },
  60. { :predicate => "return expected != actual;", :matcher => "toNotEqual", :matcher_description => "to not equal" },
  61. { :predicate => "return expected < actual;", :matcher => "toBeLessThan", :matcher_description => "to be less than" },
  62. { :predicate => "return expected > actual;", :matcher => "toBeGreaterThan", :matcher_description => "to be greater than" },
  63. ]
  64. @non_integer_types = [
  65. { :type => "float", :name => "float", :converter => "%f" },
  66. { :type => "double", :name => "double", :converter => "%f" },
  67. ]
  68. @non_integer_matchers = [
  69. { :predicate => "return ABS(expected - actual) <= tolerance;", :matcher => "toEqual", :matcher_description => "to equal", :tolerance => true },
  70. { :predicate => "return ABS(expected - actual) > tolerance;", :matcher => "toNotEqual", :matcher_description => "to not equal", :tolerance => true },
  71. { :predicate => "return expected < actual;", :matcher => "toBeLessThan", :matcher_description => "to be less than", :tolerance => false },
  72. { :predicate => "return expected > actual;", :matcher => "toBeGreaterThan", :matcher_description => "to be greater than", :tolerance => false }
  73. ]
  74. @header_comment = "THIS FILE IS GENERATED. DO NOT EDIT."
  75. ["m", "h"].each do |extension|
  76. output_file = "Classes/Expect.#{extension}"
  77. puts "Generating #{output_file}"
  78. File.open(output_file, 'w') do |f|
  79. rendered = ERB.new(IO.read("Templates/Expect.erb.#{extension}")).result(binding)
  80. rendered.gsub! /^\s+$/, "" # remove whitespace from otherwise-empty lines
  81. rendered.gsub! /\n{3,}/, "\n\n\n" # remove multiple contiguous blank lines
  82. f << rendered
  83. end
  84. end
  85. end