]> git.mdlowis.com Git - proto/sclpl.git/commitdiff
Added test framework for sclpl compiler
authorMichael D. Lowis <mike@mdlowis.com>
Wed, 8 Oct 2014 18:16:48 +0000 (14:16 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Wed, 8 Oct 2014 18:16:48 +0000 (14:16 -0400)
Gemfile
Gemfile.lock
Rakefile
source/sclpl/main.c
source/sclpl/parser.c
spec/lexer_spec.rb [new file with mode: 0644]
spec/parser_spec.rb [new file with mode: 0644]
spec/spec_helper.rb [new file with mode: 0644]

diff --git a/Gemfile b/Gemfile
index c8d6a787d1c26b03744471ca28b12e455327bdb1..278750098ad15f4ed157414dac30340890a8f971 100644 (file)
--- a/Gemfile
+++ b/Gemfile
@@ -1,3 +1,4 @@
 source 'http://rubygems.org'
 gem 'rscons'
 gem 'rake'
+gem 'rspec'
index 7b3953a9124ab51dab310b7579010e1a33cdece2..203d3951015cad34ce8e008952bd16510392e415 100644 (file)
@@ -1,10 +1,23 @@
 GEM
   remote: http://rubygems.org/
   specs:
+    diff-lcs (1.2.5)
     json (1.8.1)
     rake (10.3.2)
     rscons (1.6.0)
       json (~> 1.0)
+    rspec (3.0.0)
+      rspec-core (~> 3.0.0)
+      rspec-expectations (~> 3.0.0)
+      rspec-mocks (~> 3.0.0)
+    rspec-core (3.0.2)
+      rspec-support (~> 3.0.0)
+    rspec-expectations (3.0.2)
+      diff-lcs (>= 1.2.0, < 2.0)
+      rspec-support (~> 3.0.0)
+    rspec-mocks (3.0.2)
+      rspec-support (~> 3.0.0)
+    rspec-support (3.0.2)
 
 PLATFORMS
   ruby
@@ -13,3 +26,4 @@ PLATFORMS
 DEPENDENCIES
   rake
   rscons
+  rspec
index 8562ab326b0e85a413264b90f28b0722ad2fa810..565caa505898b05f183f95cc386609007e4629a7 100644 (file)
--- a/Rakefile
+++ b/Rakefile
@@ -1,3 +1,5 @@
+require "rspec"
+require "rspec/core/rake_task"
 require './build-system/setup'
 
 def windows?
@@ -11,10 +13,16 @@ end
 base_env = BuildEnv.new(echo: :command) do |env|
   env.build_dir('source','build/obj/source')
   env.build_dir('modules','build/obj/modules')
-  env.set_toolset(:clang)
+  env.set_toolset(:gcc)
   env["CFLAGS"] += ['-DLEAK_DETECT_LEVEL=1', '--std=c99', '-Wall', '-Wextra'] #, '-Werror']
   env["CPPPATH"] += ['modules/libopts/source'] + Dir['modules/libcds/source/**/']
-  env["AR"] = 'ar'
+end
+
+test_env = base_env.clone do |env|
+  env.build_dir('source','build/obj/test/source')
+  env.build_dir('modules','build/obj/test/modules')
+  env['CFLAGS'] +=  ['--coverage']
+  env['LDFLAGS'] += ['--coverage']
 end
 
 #------------------------------------------------------------------------------
@@ -84,3 +92,17 @@ end
 desc "Clobber the build directory and all it's contents"
 task(:clobber) { FileUtils.rm_rf('build/') }
 
+#------------------------------------------------------------------------------
+# RSpec Tests for the Compiler
+#------------------------------------------------------------------------------
+# Make the specs depend on the libs
+task :spec => [:libcds, :libopts]
+
+# Build and test the compiler with coverage
+RSpec::Core::RakeTask.new(:spec) do |t,args|
+  t.rspec_opts = ['--format', 'documentation']
+  test_env.Program('build/bin/sclpl-test',
+    FileList['source/sclpl/*.c', 'build/lib/libopts.a', 'build/lib/libcds.a'])
+  base_env.process
+  test_env.process
+end
index 10a77ffece6fd87b98d9bc5dffe4533b6e108f66..5f0a839f662a150840d90ec6ef814719eee83611 100644 (file)
@@ -8,15 +8,15 @@
 
 /* Command Line Options
  *****************************************************************************/
-OptionConfig_T Options_Config[] = {
-    { "tokens",    false, "mode",    "Emit the token output of lexical analysis for the given file"},
-    { "ast",       false, "mode",    "Emit the abstract syntax tree for the given file"},
-    { "repl",      false, "mode",    "Execute the application in a REPL"},
-    { "staticlib", false, "mode",    "Compile the application as a static library"},
-    { "sharedlib", false, "mode",    "Compile the application as a shared library"},
-    { "program",   false, "mode",    "Compile the application as an executable"},
-    { "R",         true,  "include", "Add a path to the list of require paths"},
-    { NULL,        false, NULL,      NULL }
+opts_cfg_t Options_Config[] = {
+    {"tokens",    false, "mode",    "Emit the token output of lexical analysis for the given file"},
+    {"ast",       false, "mode",    "Emit the abstract syntax tree for the given file"},
+    {"repl",      false, "mode",    "Execute the application in a REPL"},
+    {"staticlib", false, "mode",    "Compile the application as a static library"},
+    {"sharedlib", false, "mode",    "Compile the application as a shared library"},
+    {"program",   false, "mode",    "Compile the application as an executable"},
+    {"R",         true,  "include", "Add a path to the list of require paths"},
+    {NULL,        false, NULL,      NULL }
 };
 
 /* Tree Printing
index 87dac055c52ac79d56435654ec39bc78058aae7d..804416f98762ec7c37e44c601465f51dc2cee42f 100644 (file)
@@ -72,6 +72,7 @@ void parser_resume(parser_t* p_parser) {
 
 void parser_error(parser_t* p_parser, const char* p_text)
 {
+    (void)p_parser;
     throw_msg(ParseException, p_text);
 }
 
diff --git a/spec/lexer_spec.rb b/spec/lexer_spec.rb
new file mode 100644 (file)
index 0000000..cd7b4fb
--- /dev/null
@@ -0,0 +1,15 @@
+require 'open3'
+
+def tokens(input)
+  out, err, status = Open3.capture3('./build/bin/sclpl-test', '--tokens', :stdin_data => input)
+  raise "Lexer command returned non-zero status" unless status.success?
+  raise "Lexer produced error messages" unless err == ""
+  out.gsub(/<tok (T_[A-Z]+)>/,'\1').split
+end
+
+describe "lexer" do
+  it "should recognize punctuation" do
+    expect(tokens('[](){};\'",')).to eq(
+      ["T_LBRACK", "T_RBRACK", "T_LPAR", "T_RPAR", "T_VAR", "T_VAR", "T_END"])
+  end
+end
diff --git a/spec/parser_spec.rb b/spec/parser_spec.rb
new file mode 100644 (file)
index 0000000..8b13789
--- /dev/null
@@ -0,0 +1 @@
+
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
new file mode 100644 (file)
index 0000000..ce150c6
--- /dev/null
@@ -0,0 +1,7 @@
+
+module TestUtils
+def self.exec_cmd(cmd, input)
+  out, err, status = Open3.capture3(*cmd, :stdin_data => input)
+end
+end
+