ciat 0.4.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/History.txt +96 -0
  2. data/README.rdoc +135 -0
  3. data/Rakefile +40 -0
  4. data/ciat.gemspec +53 -0
  5. data/lib/ciat.rb +22 -0
  6. data/lib/ciat/cargo.rb +55 -0
  7. data/lib/ciat/compilers/java.rb +54 -0
  8. data/lib/ciat/crate.rb +58 -0
  9. data/lib/ciat/differs/html_differ.rb +20 -0
  10. data/lib/ciat/erb_helpers.rb +83 -0
  11. data/lib/ciat/executors/java.rb +36 -0
  12. data/lib/ciat/executors/parrot.rb +51 -0
  13. data/lib/ciat/feedback/composite.rb +20 -0
  14. data/lib/ciat/feedback/feedback_counter.rb +45 -0
  15. data/lib/ciat/feedback/html_feedback.rb +40 -0
  16. data/lib/ciat/feedback/return_status.rb +23 -0
  17. data/lib/ciat/feedback/standard_output.rb +29 -0
  18. data/lib/ciat/processors/basic_processing.rb +64 -0
  19. data/lib/ciat/processors/compilation_interpreter.rb +18 -0
  20. data/lib/ciat/processors/compiler.rb +18 -0
  21. data/lib/ciat/processors/copy.rb +37 -0
  22. data/lib/ciat/processors/interpreter.rb +18 -0
  23. data/lib/ciat/rake_task.rb +56 -0
  24. data/lib/ciat/suite.rb +112 -0
  25. data/lib/ciat/test.rb +41 -0
  26. data/lib/ciat/test_element.rb +44 -0
  27. data/lib/ciat/traffic_light.rb +39 -0
  28. data/lib/ciat/version.rb +7 -0
  29. data/lib/data/ciat.css +40 -0
  30. data/lib/data/elements.yml +30 -0
  31. data/lib/data/prototype.js +4228 -0
  32. data/lib/templates/detail_row.html.erb +9 -0
  33. data/lib/templates/detail_row/elements.html.erb +3 -0
  34. data/lib/templates/elements/diff.html.erb +7 -0
  35. data/lib/templates/elements/plain.html.erb +8 -0
  36. data/lib/templates/group_header.html.erb +7 -0
  37. data/lib/templates/report.html.erb +38 -0
  38. data/lib/templates/summary_row.html.erb +12 -0
  39. data/lib/templates/test_numbers.html.erb +12 -0
  40. metadata +99 -0
data/History.txt ADDED
@@ -0,0 +1,96 @@
1
+ == 0.4.8 2009-
2
+ * 1 minor feature
3
+ * Library paths can be specified for parrot executor.
4
+
5
+ == 0.4.7 2009-09-22
6
+ * 3 major features
7
+ * File names appear as title attributes for tests and elements in the
8
+ HTML report.
9
+ * Folders containing tests are grouped in the HTML report, and each
10
+ group has a header consisting of the folder's path.
11
+ * The CIAT::RakeTask class makes defining a rake task a bit cleaner.
12
+
13
+ == 0.4.1 2009-04-29
14
+ * 1 major feature (bug fix?)
15
+ * If a test errors or fails, the Suite task will fail. This sets
16
+ the command-line status appropriately.
17
+
18
+ == 0.4.0 2009-04-20
19
+ * 2 major features
20
+ * All processors now need to read from a file and output to standard output
21
+ and standard error.
22
+ * All processors now handle command-line arguments.
23
+
24
+ == 0.3.4 2009-04-05
25
+ * 1 minor feature
26
+ * Command-line feedback reports number of failures and errors.
27
+
28
+ == 0.3.3 2009-04-01
29
+ * 1 minor bug fix
30
+ * Fixed file redirection for Java executor since sh doesn't support &>.
31
+
32
+ == 0.3.2 2009-02-16
33
+ * 1 minor enhancement
34
+ * Some line number information in diffs.
35
+ * 1 minor bug fix
36
+ * in-Java interpreter uses diff output for failures.
37
+
38
+ == 0.3.1 2009-02-16
39
+ * 1 major bug fix
40
+ * ACTUALLY added in-Java interpreter executor (missed file in gemspec).
41
+
42
+ == 0.3.0 2009-02-15
43
+ * 1 major enhancement:
44
+ * Added in-Java interpreter executor.
45
+
46
+ == 0.2.0 2008-10-26
47
+
48
+ * 3 major enhancements:
49
+ * Elements of a test files are now labeled for greater flexibility; error
50
+ checking is done on the elements (missing, unused, etc.).
51
+ * A test file can specify optional elements for a processor. Parrot
52
+ executor uses "command line" for command-line arguments; it provides
53
+ a default if not specified.
54
+ * Formatting improvements to the HTML report.
55
+ * 1 minor enhancement:
56
+ * Java compiler redirects standard error to a file.
57
+
58
+ == 0.1.1 2008-08-16
59
+
60
+ * 1 major bug fix
61
+ * If executor is not run (while compilation fails), its traffic light is
62
+ unset; the standard output feedback now handles this case.
63
+
64
+ == 0.1.0 2008-08-14
65
+
66
+ * 2 major enhancements:
67
+ * Generates a very useful HTML report, complete with side-by-side diffs.
68
+ * Immediate feedback while tests are running ("."s, "F"s, and "E"s).
69
+
70
+ == 0.0.4 2008-08-08
71
+
72
+ * 2 major enhancements:
73
+ * Flexible way to specified test files (including recursive search).
74
+ * Executor triggered only if compilation phase is green.
75
+ * minor
76
+ * Internal renamings and restructuring.
77
+
78
+ == 0.0.3 2008-08-02
79
+
80
+ * 2 major enhancements:
81
+ * Major refactoring of internals
82
+ * Feedback mechanisms (for simple status reports, not failure/success yet) added
83
+ * 1 modification:
84
+ * Expecting .ciat as file extension of CIAT test files.
85
+
86
+ == 0.0.2 2008-07-28
87
+
88
+ * 1 major enhancement:
89
+ * Actual RubyDocs!
90
+
91
+ == 0.0.1 2008-07-28
92
+
93
+ * 1 major enhancement:
94
+ * Initial release
95
+ * Runs tests over all *.txt files.
96
+ * Slight abstraction for compiler and executor.
data/README.rdoc ADDED
@@ -0,0 +1,135 @@
1
+ = CIAT (Compiler and Interpreter Acceptance Tester)
2
+
3
+ == DESCRIPTION:
4
+
5
+ CIAT (pronounced "dog") provides a system for writing high-level acceptance
6
+ tests for compilers and interpreters. Each acceptance test is entered into a
7
+ single file, and that file identifies the elements of a test.
8
+
9
+
10
+ == SYNOPSIS:
11
+
12
+ Suppose you have a compiler written in Java that compiles a language named
13
+ Hobbes. Your compiler targets the Parrot Virtual Machine. So you want to
14
+ provide <em>source code</em> which is <em>compiled with a Java program</em>
15
+ and that result is <em>interpreted by Parrot</em>.
16
+
17
+ === Input File
18
+
19
+ Input files should be named with a <code>.ciat</code> extension and saved in a
20
+ <code>ciat</code> folder.
21
+
22
+ A sample input file (<code>simpleinteger5.ciat</code>) for the scenario
23
+ described above might look like this:
24
+
25
+ Compiles a simple integer.
26
+ ==== source
27
+ 5
28
+ ==== compilation
29
+ .sub main
30
+ print 5
31
+ print "\n"
32
+ .end
33
+ ==== execution
34
+ 5
35
+
36
+ This file specifies <em>four</em> elements: description, <b>source</b>,
37
+ <b>compilation</b>, and <b>execution</b>. The description is always the first
38
+ element, always unlabeled, and used prominently in the HTML report. All of the
39
+ other elements are dependent on the processors that you use.
40
+
41
+ In this example, we're using a "Java compiler" (a compiler <em>written in</em>
42
+ Java) and a "Parrot executor". CIAT's "Java compiler" runs your compiler over
43
+ the <b>source</b>, and that output is compared to the <b>compilation</b>
44
+ element. Then the "Parrot executor" is executed with the <em>generated</em>
45
+ compilation, and that output is compared to the <b>execution</b> element.
46
+
47
+ If any processor fails, either due to an error while running or a failure
48
+ during checking the output, the remaining processors are not executed.
49
+
50
+ Some processors will use optional elements in a test file. For example, the "Parrot executor" knows about command-line arguments:
51
+
52
+ Compiles a simple integer and ignores the command-line arguments.
53
+ ==== source
54
+ 5
55
+ ==== compilation
56
+ .sub main
57
+ print 5
58
+ print "\n"
59
+ .end
60
+ ==== command line
61
+ 89 pqp
62
+ ==== execution
63
+ 5
64
+
65
+ When the "Parrot executor" is run on the compilation, it'll also pass in <code>89 pqp</code> as command-line arguments.
66
+
67
+ === The Rakefile
68
+
69
+ This sample +Rakefile+ will pull everything together:
70
+
71
+ require 'ciat'
72
+ require 'ciat/compilers/java'
73
+ require 'ciat/executors/parrot'
74
+
75
+ def compiler
76
+ classpath = Dir.glob('../lib/*.jar').join(':') + ":../bin"
77
+ CIAT::Compilers::Java.new(classpath, 'org.norecess.hobbes.drivers.PIRCompiler')
78
+ end
79
+
80
+ def executor
81
+ CIAT::Executors::Parrot.new
82
+ end
83
+
84
+ CIAT::RakeTask.new do |t|
85
+ t.processors << compiler
86
+ t.processors << executor
87
+ end
88
+
89
+ This rakefile will find all of the <code>.ciat</code> files inside a +ciat+
90
+ directory, each one representing a test. Each test will be executed, and the
91
+ results are put into a folder named +temp+, including the HTML report
92
+ <code>report.html</code>. All of these settings can be tweaked; see the
93
+ documentation for CIAT::RakeTask for more information.
94
+
95
+
96
+ == REQUIREMENTS:
97
+
98
+ * Pronounce "CIAT" as "dog". (See this funny video[http://www.youtube.com/watch?v=tyQvjKqXA0Y].)
99
+ * Must have +diff+ executable.
100
+ * You have to provide your own target-code executors (e.g., +parrot+ for the
101
+ Parrot Virtual Machine, +spim+ for MIPS emulation, etc.)
102
+
103
+
104
+ == INSTALL:
105
+
106
+ * Install +diff+.
107
+ * Install Ruby and Ruby Gems.
108
+ * <code>sudo gem sources -a http</code><code>://gems.github.com</code> (only needed once)
109
+ * <code>sudo gem install jdfrens-ciat</code>
110
+
111
+
112
+ == LICENSE:
113
+
114
+ (The MIT License)
115
+
116
+ Copyright (c) 2008 Jeremy D. Frens
117
+
118
+ Permission is hereby granted, free of charge, to any person obtaining
119
+ a copy of this software and associated documentation files (the
120
+ 'Software'), to deal in the Software without restriction, including
121
+ without limitation the rights to use, copy, modify, merge, publish,
122
+ distribute, sublicense, and/or sell copies of the Software, and to
123
+ permit persons to whom the Software is furnished to do so, subject to
124
+ the following conditions:
125
+
126
+ The above copyright notice and this permission notice shall be
127
+ included in all copies or substantial portions of the Software.
128
+
129
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
130
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
131
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
132
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
133
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
134
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
135
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,40 @@
1
+ require 'rake'
2
+ require 'rake/clean'
3
+ require 'rake/rdoctask'
4
+ require 'spec/rake/spectask'
5
+
6
+ task :default => :specs
7
+
8
+ desc "Run all examples"
9
+ Spec::Rake::SpecTask.new(:specs) do |t|
10
+ t.spec_opts = ['--options', "spec/spec.opts"]
11
+ t.spec_files = FileList['spec/**/*_spec.rb']
12
+ end
13
+
14
+ desc "Run all examples with rcov"
15
+ Spec::Rake::SpecTask.new(:specs_with_rcov) do |t|
16
+ t.spec_opts = ['--options', "spec/spec.opts"]
17
+ t.spec_files = FileList['spec/**/*_spec.rb']
18
+ t.rcov = true
19
+ t.rcov_opts = ['--exclude', 'spec']
20
+ end
21
+
22
+ desc "Generate documentation for CIAT"
23
+ Rake::RDocTask.new(:doc) do |t|
24
+ t.rdoc_dir = 'doc'
25
+ t.title = "CIAT"
26
+ t.options << '--line-numbers' << '--inline-source'
27
+ t.options << '--charset' << 'utf-8'
28
+ t.rdoc_files.include('README.rdoc')
29
+ t.rdoc_files.include('History.txt')
30
+ t.rdoc_files.include('lib/**/*.rb')
31
+ end
32
+
33
+ desc "Make and install gem"
34
+ task :gem => [:specs_with_rcov] do
35
+ system "sudo gem uninstall ciat"
36
+ system "rm *.gem"
37
+ system "gem build ciat.gemspec"
38
+ system "sudo gem install ciat*.gem"
39
+ end
40
+ CLOBBER << FileList['*.gem']
data/ciat.gemspec ADDED
@@ -0,0 +1,53 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "ciat"
3
+ s.version = "0.4.8"
4
+ s.summary = "Acceptance tester for compilers and interpreters"
5
+ s.email = "jdfrens@gmail.com"
6
+ s.homepage = "http://github.com/jdfrens/ciat"
7
+ s.description = "CIAT (pronounced \"dog\") is a library of Ruby and rake code to make writing acceptance tests for compilers and interpreters easier (despite their implementation, source, and target languages)."
8
+ s.has_rdoc = true
9
+ s.authors = ["Jeremy D. Frens", "Mark Van Holstyn"]
10
+ s.files =
11
+ ["History.txt", "README.rdoc", "Rakefile", "ciat.gemspec",
12
+ "lib/ciat/version.rb",
13
+ "lib/ciat.rb",
14
+ "lib/ciat/rake_task.rb",
15
+ "lib/ciat/cargo.rb",
16
+ "lib/ciat/crate.rb",
17
+ "lib/ciat/suite.rb",
18
+ "lib/ciat/test.rb",
19
+ "lib/ciat/erb_helpers.rb",
20
+ "lib/ciat/test_element.rb",
21
+ "lib/ciat/traffic_light.rb",
22
+ "lib/ciat/processors/copy.rb",
23
+ "lib/ciat/processors/basic_processing.rb",
24
+ "lib/ciat/processors/compiler.rb",
25
+ "lib/ciat/processors/interpreter.rb",
26
+ "lib/ciat/processors/compilation_interpreter.rb",
27
+ "lib/ciat/compilers/java.rb",
28
+ "lib/ciat/executors/java.rb",
29
+ "lib/ciat/executors/parrot.rb",
30
+ "lib/ciat/differs/html_differ.rb",
31
+ "lib/ciat/feedback/standard_output.rb",
32
+ "lib/ciat/feedback/html_feedback.rb",
33
+ "lib/ciat/feedback/feedback_counter.rb",
34
+ "lib/ciat/feedback/composite.rb",
35
+ "lib/ciat/feedback/return_status.rb",
36
+ "lib/data/ciat.css",
37
+ "lib/data/prototype.js",
38
+ "lib/data/elements.yml",
39
+ "lib/templates/report.html.erb",
40
+ "lib/templates/group_header.html.erb",
41
+ "lib/templates/summary_row.html.erb",
42
+ "lib/templates/test_numbers.html.erb",
43
+ "lib/templates/detail_row.html.erb",
44
+ "lib/templates/detail_row/elements.html.erb",
45
+ "lib/templates/elements/diff.html.erb",
46
+ "lib/templates/elements/plain.html.erb",
47
+ ]
48
+ s.extra_rdoc_files = ["README.rdoc", "History.txt"]
49
+ s.rdoc_options <<
50
+ '--title' << 'CIAT -- Compiler and Interpreter Acceptance Tester' <<
51
+ '--main' << 'README.txt' <<
52
+ '--line-numbers'
53
+ end
data/lib/ciat.rb ADDED
@@ -0,0 +1,22 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ # Loads in the basic files needed to use CIAT. Compilers and Executors have
5
+ # to be required separately. CIAT::Suite is the class you really want to look
6
+ # at.
7
+ module CIAT; end
8
+
9
+ require 'ciat/rake_task'
10
+ require 'ciat/traffic_light'
11
+ require 'ciat/suite'
12
+ require 'ciat/test'
13
+ require 'ciat/test_element'
14
+ require 'ciat/cargo'
15
+ require 'ciat/crate'
16
+ require 'ciat/feedback/standard_output'
17
+ require 'ciat/feedback/html_feedback'
18
+ require 'ciat/differs/html_differ'
19
+ require 'ciat/processors/basic_processing'
20
+ require 'ciat/processors/compiler'
21
+ require 'ciat/processors/interpreter'
22
+ require 'ciat/processors/compilation_interpreter'
data/lib/ciat/cargo.rb ADDED
@@ -0,0 +1,55 @@
1
+ class CIAT::Cargo #:nodoc:all
2
+ OUTPUT_FOLDER = "temp"
3
+ REPORT_FILENAME = "report.html"
4
+
5
+ attr_reader :output_folder
6
+ attr_reader :crates
7
+ attr_reader :report_filename
8
+
9
+ def initialize(options={})
10
+ @output_folder = options[:output_folder] || OUTPUT_FOLDER
11
+ if options[:files]
12
+ filenames = options[:files]
13
+ else
14
+ folder = options[:folder] || "ciat"
15
+ pattern = options[:pattern] || "*.ciat"
16
+ filenames = Dir[File.join(folder, "**", pattern)]
17
+ end
18
+ @crates = filenames.map { |filename| CIAT::Crate.new(filename, @output_folder) }
19
+ @report_filename = File.join(@output_folder, options[:report_filename] || REPORT_FILENAME)
20
+ end
21
+
22
+ def size
23
+ crates.size
24
+ end
25
+
26
+ def copy_suite_data
27
+ FileUtils.mkdir_p(output_folder)
28
+ FileUtils.cp(File.join(File.dirname(__FILE__), "..", "data", "ciat.css"), output_folder)
29
+ FileUtils.cp(File.join(File.dirname(__FILE__), "..", "data", "prototype.js"), output_folder)
30
+ end
31
+
32
+ # TODO: get rid of this in favor of the class method
33
+ def write_file(filename, content)
34
+ FileUtils.mkdir_p(File.dirname(filename))
35
+ File.open(filename, "w") do |file|
36
+ file.write content
37
+ end
38
+ end
39
+
40
+ # TODO: get rid of this in favor of the class method
41
+ def read_file(filename)
42
+ File.read(filename)
43
+ end
44
+
45
+ def self.write_file(filename, content)
46
+ FileUtils.mkdir_p(File.dirname(filename))
47
+ File.open(filename, "w") do |file|
48
+ file.write content
49
+ end
50
+ end
51
+
52
+ def self.read_file(filename)
53
+ File.read(filename)
54
+ end
55
+ end
@@ -0,0 +1,54 @@
1
+ module CIAT
2
+ module Compilers
3
+ # Implements a processor written in Java.
4
+ #
5
+ # It requires <code>source</code> and <code>compilation</code> elements.
6
+ # * <code>source</code> is used as source to the Java compiler.
7
+ # * <code>compilation</code> is used for comparsion.
8
+ #
9
+ # == Best Practices
10
+ #
11
+ # Suppose you use Eclipse to develop your compiler or interpreter, and you
12
+ # have this folder structure:
13
+ # * +bin+ stores your compiled classes (under test)
14
+ # * +lib+ contains support JAR files
15
+ # * +acceptance+ is a root folder for your CIAT tests with your +Rakefile+
16
+ # You may find this classpath useful:
17
+ # Dir.glob('../lib/*.jar').join(':') + ":../bin"
18
+ class Java
19
+ include CIAT::Processors::BasicProcessing
20
+ include CIAT::Differs::HtmlDiffer
21
+
22
+ # The traffic light to indicate the success or failure of the processor.
23
+ attr :light, true
24
+ attr_reader :processor_kind
25
+
26
+ # Constructs a "Java compiler" object. +classpath+ is the complete
27
+ # classpath to execute the compiler. +compiler_class+ is the fully
28
+ # qualified name of the class that executes your compiler; this driver
29
+ # should take two command-line arguments: the name of the source file
30
+ # and the name of the generated target-code file.
31
+ #
32
+ # Possible options:
33
+ # * <code>description</code> specifies a descriptive name for your
34
+ # compiler; used in the HTML report.
35
+ def initialize(classpath, compiler_class, options={})
36
+ @processor_kind = options[:processor_kind] || CIAT::Processors::Compiler.new
37
+ @classpath = classpath
38
+ @compiler_class = compiler_class
39
+ @descriptions = {}
40
+ @description = options[:description] || "compiler (implemented in Java)"
41
+ @light = options[:light] || TrafficLight.new
42
+ end
43
+
44
+ # Return a description of the processor.
45
+ def describe
46
+ @description
47
+ end
48
+
49
+ def executable
50
+ "java -cp '#{@classpath}' #{@compiler_class}"
51
+ end
52
+ end
53
+ end
54
+ end