diff --git a/Makefile b/Makefile index b1873ff..f54501d 100644 --- a/Makefile +++ b/Makefile @@ -13,3 +13,7 @@ install: .PHONY: uninstall uninstall: ./waf uninstall + +.PHONY: test +test: + @(cd tests; rspec) diff --git a/tests/Gemfile b/tests/Gemfile new file mode 100644 index 0000000..6b7f7ca --- /dev/null +++ b/tests/Gemfile @@ -0,0 +1 @@ +gem "rspec" diff --git a/tests/Gemfile.lock b/tests/Gemfile.lock new file mode 100644 index 0000000..b5023a7 --- /dev/null +++ b/tests/Gemfile.lock @@ -0,0 +1,25 @@ +GEM + specs: + diff-lcs (1.3) + rspec (3.6.0) + rspec-core (~> 3.6.0) + rspec-expectations (~> 3.6.0) + rspec-mocks (~> 3.6.0) + rspec-core (3.6.0) + rspec-support (~> 3.6.0) + rspec-expectations (3.6.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.6.0) + rspec-mocks (3.6.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.6.0) + rspec-support (3.6.0) + +PLATFORMS + ruby + +DEPENDENCIES + rspec + +BUNDLED WITH + 1.16.1 diff --git a/tests/spec/main_spec.rb b/tests/spec/main_spec.rb new file mode 100644 index 0000000..7223553 --- /dev/null +++ b/tests/spec/main_spec.rb @@ -0,0 +1,23 @@ +require "fileutils" +require "open3" + +describe "cxlc" do + def run_test(test_name) + stdout, stderr, status = Open3.capture3("../build/cxlc", "#{test_name}.cxl") + expect(status).to eq(0) + stdout, stderr, status = Open3.capture3("gcc", "-o", test_name, "#{test_name}.c") + if status != 0 + $stderr.write(stderr) + end + expect(status).to eq(0) + stdout, stderr, status = Open3.capture3("./#{test_name}") + expect(stdout).to eq(File.read("#{test_name}.x")) + end + + Dir["*.cxl"].sort.each do |test| + test_basename = File.basename(test, ".cxl") + it "passes test #{test_basename}" do + run_test(test_basename) + end + end +end diff --git a/tests/t001.cxl b/tests/t001.cxl new file mode 100644 index 0000000..12151d2 --- /dev/null +++ b/tests/t001.cxl @@ -0,0 +1,6 @@ +#include + +int main(int argc, char * argv[]) +{ + printf("Working\n"); +} diff --git a/tests/t001.x b/tests/t001.x new file mode 100644 index 0000000..a717cf2 --- /dev/null +++ b/tests/t001.x @@ -0,0 +1 @@ +Working