From 4152cfd1ea6b2591e4aed5c89279b7f865c37a9a Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Sun, 30 Jun 2013 15:23:00 -0400 Subject: [PATCH] create rspec environment for build tests --- .gitignore | 1 + .rspec | 2 ++ Rakefile | 10 ++++++++++ build_tests/simple/build.rb | 3 +++ build_tests/simple/simple.c | 6 ++++++ rscons.gemspec | 9 +++++++++ spec/build_tests_spec.rb | 30 ++++++++++++++++++++++++++++++ 7 files changed, 61 insertions(+) create mode 100644 .rspec create mode 100644 build_tests/simple/build.rb create mode 100644 build_tests/simple/simple.c create mode 100644 spec/build_tests_spec.rb diff --git a/.gitignore b/.gitignore index d87d4be..27bdad0 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ spec/reports test/tmp test/version_tmp tmp +build_tests_run diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..83e16f8 --- /dev/null +++ b/.rspec @@ -0,0 +1,2 @@ +--color +--require spec_helper diff --git a/Rakefile b/Rakefile index b7e9ed5..6e909d5 100644 --- a/Rakefile +++ b/Rakefile @@ -1,5 +1,15 @@ +require "bundler" +begin + Bundler.setup(:default, :development) +rescue Bundler::BundlerError => e + raise LoadError.new("Unable to setup Bundler; you might need to `bundle install`: #{e.message}") +end + require "bundler/gem_tasks" require "rspec/core/rake_task" +require "rake/clean" + +CLEAN.include 'build_tests_run' RSpec::Core::RakeTask.new(:spec) diff --git a/build_tests/simple/build.rb b/build_tests/simple/build.rb new file mode 100644 index 0000000..9775f9a --- /dev/null +++ b/build_tests/simple/build.rb @@ -0,0 +1,3 @@ +Rscons::Environment.new do |env| + env.Program('simple', Dir['*.c']) +end diff --git a/build_tests/simple/simple.c b/build_tests/simple/simple.c new file mode 100644 index 0000000..ee61f1f --- /dev/null +++ b/build_tests/simple/simple.c @@ -0,0 +1,6 @@ +#include + +int main(int argc, char *argv[]) +{ + printf("This is a simple C program\n"); +} diff --git a/rscons.gemspec b/rscons.gemspec index bd3f95a..5a82548 100644 --- a/rscons.gemspec +++ b/rscons.gemspec @@ -16,4 +16,13 @@ Gem::Specification.new do |gem| gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) } gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) gem.require_paths = ["lib"] + + gem.add_development_dependency "rspec-core" + gem.add_development_dependency "rspec-mocks" + gem.add_development_dependency "rspec-expectations" + gem.add_development_dependency "rspec" + gem.add_development_dependency "rake" + gem.add_development_dependency "simplecov" + gem.add_development_dependency "json" + gem.add_development_dependency 'rdoc' end diff --git a/spec/build_tests_spec.rb b/spec/build_tests_spec.rb new file mode 100644 index 0000000..e23973d --- /dev/null +++ b/spec/build_tests_spec.rb @@ -0,0 +1,30 @@ +require 'fileutils' + +describe Rscons do + before(:all) do + FileUtils.rm_rf('build_tests_run') + FileUtils.cp_r('build_tests', 'build_tests_run') + @owd = Dir.pwd + end + + after(:each) do + Dir.chdir(@owd) + end + + def test_dir(build_test_directory) + Dir.chdir("build_tests_run/#{build_test_directory}") + if File.exists?('build.rb') + system('ruby build.rb') + end + end + + ########################################################################### + # Tests + ########################################################################### + + it 'builds a C program with one source file' do + test_dir('simple') + File.exists?('simple.o').should be_true + `./simple`.should == "This is a simple C program\n" + end +end