source 'http://rubygems.org'
gem 'rscons'
gem 'rake'
+gem 'rspec'
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
DEPENDENCIES
rake
rscons
+ rspec
+require "rspec"
+require "rspec/core/rake_task"
require './build-system/setup'
def windows?
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
#------------------------------------------------------------------------------
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
/* 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
void parser_error(parser_t* p_parser, const char* p_text)
{
+ (void)p_parser;
throw_msg(ParseException, p_text);
}
--- /dev/null
+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
--- /dev/null
+
+module TestUtils
+def self.exec_cmd(cmd, input)
+ out, err, status = Open3.capture3(*cmd, :stdin_data => input)
+end
+end
+