lc3spec 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1f686a8679caa7f3110190bb0ee425e509626c98
4
- data.tar.gz: 53041547c4ec8e20cbd53723f8adbf9619bfd0be
3
+ metadata.gz: 702d428ff4102c7ad87b31a65490bbee2e07af52
4
+ data.tar.gz: a96200247b660e91c42642b8a085bd7609fccf23
5
5
  SHA512:
6
- metadata.gz: fd2f0ab0522bf867e8d9bff04160fb1a685ee06e958b26df5c6dd615bf3278c9fbc7ed46625ccafcb93829d1e377c9445b98e57461b1e20da4e670ac685afcaa
7
- data.tar.gz: 9b2d49b370c77ef7753d84c5ead0bd047c1d7db968468a2f4584e29ceecbf84de4ee65e4b903655fec2ef05c866823a9a9d545dac4ca0dc52e173873878584d7
6
+ metadata.gz: 22cf5b67474d74a44a70ec88c9f87062009963176bce69968311446598ac2bcdecd0331fa3289eb4f6482152ace6bf618ba511161b2109cd4f7e6c272f8a8a7f
7
+ data.tar.gz: 300ce687d57e631811f47c636fcd35492358c306a90afd9df8ac938c7f6b7478eeb97d9cd713a639d2775badc7bace67cead4c68215801ed27d8e4c44bb6138e
data/README.md CHANGED
@@ -2,10 +2,141 @@
2
2
 
3
3
  Testing and grading suite for LC-3 assembly programs
4
4
 
5
+ # Description
6
+
7
+ LC3Spec allows you to write tests for LC-3 assembly programs and run
8
+ them in the lc3sim simulator. LC3Spec handles assembling code and
9
+ creating temporary directories so that you don't have to.
10
+
11
+ LC3Spec executes spec files that each describe a number of tests.
12
+ Each test runs a new instance of lc3sim and allows you to interact
13
+ with it programmatically.
14
+
15
+ Consider the following assembly file, regs.asm, which is supposed to
16
+ set registers R0, R1, R2, R3, and R4 to 0, 1, 2, 3, and 4, respectively:
17
+
18
+ ```
19
+ .ORIG x4000
20
+ AND R0, R0, 0
21
+ ADD R1, R0, 1
22
+ ADD R2, R0, 2
23
+ ADD R3, R0, 3
24
+ HALT
25
+ .END
26
+ ```
27
+
28
+ We can write a spec, spec.rb, to test it:
29
+
30
+ ```ruby
31
+ #!/usr/bin/env ruby
32
+
33
+ require 'lc3spec'
34
+
35
+ test 'Register Expectations' do
36
+ file 'regs'
37
+ set_breakpoint 'TRAP_HALT'
38
+ continue
39
+
40
+ expect_register R0, 0
41
+ expect_register R1, 1
42
+ expect_register R2, 2
43
+ expect_register R3, 3
44
+ expect_register R4, 4
45
+ end
46
+ ```
47
+
48
+ Running with `ruby spec.rb`:
49
+
50
+ ```
51
+ Register Expectations [FAIL]
52
+ Incorrect R4: expected: x0004, actual: x0000
53
+ ```
54
+
55
+ Oops, looks like we forgot to initialize R4. If we go back and add
56
+ `ADD R4, R0, 4` to regs.asm and rerun the spec, we'll see:
57
+
58
+ ```
59
+ Register Expectations [OK]
60
+ ```
61
+
62
+ LC3Spec handles assembling files behind the scenes, a temporary directory
63
+ is created to perform each test and all generated files (.obj, .sym) are
64
+ discarded at the end of each test.
65
+
66
+ ## Configuration
67
+
68
+ Configuration is performed by using `set :option, value`. Configuration
69
+ changes can be enclosed in a `configure do ... end` block:
70
+
71
+ ```ruby
72
+ configure do
73
+ set :output, 'feedback.txt'
74
+ set :keep_score, true
75
+ end
76
+ ```
77
+
78
+ There are currently two supported options:
79
+
80
+ * :output - filename or file to write output to, default is $stdout
81
+ * :keep_score - whether or not to display score for each test. If false,
82
+ only `[OK]` or `[FAIL]` are displayed, if true, a fractional score
83
+ is displayed, e.g., `0/1` or `4/4`
84
+
85
+ An example:
86
+
87
+ ```ruby
88
+ #!/usr/bin/env ruby
89
+
90
+ require 'lc3spec'
91
+
92
+ configure do
93
+ set :output, 'feedback.txt'
94
+ set :keep_score, true
95
+ end
96
+
97
+ test 'this is worth 1 point', 1 do
98
+ # ...
99
+ end
100
+
101
+ test 'this is worth 4 points', 4 do
102
+ # ...
103
+ end
104
+
105
+ test 'this should fail', 2 do
106
+ set_register R4, 'xFACE'
107
+ expect_register R4, 'xCAFE'
108
+ end
109
+
110
+ print_score
111
+ ```
112
+
113
+ The print_score method prints the total score at the end of the file.
114
+ Running the above spec will produce the following output in feedback.txt:
115
+
116
+ ```
117
+ this is worth 1 point 1/1
118
+ this is worth 4 points 4/4
119
+ this should fail 0/2
120
+ Incorrect R4: expected: xCAFE, actual: xFACE
121
+
122
+ Score: 5/7
123
+ ```
124
+
5
125
  # Requirements
6
126
 
7
127
  * [lc3tools for unix](http://highered.mcgraw-hill.com/sites/0072467509/student_view0/lc-3_simulator.html)
8
- * Ruby 2.0 (Does not work with 1.8.7, untested with 1.9.*)
128
+ * Ruby 2.0.0 (Does not work with 1.8.7, untested with 1.9.*)
129
+
130
+ # Install
131
+
132
+ ```
133
+ gem install lc3spec
134
+ ```
135
+
136
+ # TODO
137
+
138
+ * Documentation
139
+ * Tests
9
140
 
10
141
  # Bugs
11
142
 
data/bin/lc3spec ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'lc3spec'
4
+
5
+ if ARGV.empty?
6
+ puts "Usage: lc3spec <spec-file>"
7
+ exit false
8
+ end
9
+
10
+ ARGV.each do |arg|
11
+ if not File.readable? arg
12
+ raise ArgumentError, "Cannot open #{arg} for reading."
13
+ end
14
+ end
15
+
16
+ ARGV.each do |arg|
17
+ load arg
18
+ end
data/lib/lc3spec/base.rb CHANGED
@@ -96,9 +96,13 @@ module LC3Spec
96
96
 
97
97
  def method_missing(method_name, *arguments, &block)
98
98
  if @lc3.respond_to? method_name
99
- @lc3.send(method_name, *arguments, &block)
99
+ res = @lc3.send(method_name, *arguments, &block)
100
100
 
101
- self
101
+ if method_name.to_s =~ /^get_/
102
+ res
103
+ else
104
+ self
105
+ end
102
106
  elsif method_name.to_s =~ /^expect_/
103
107
  LC3Spec::Expectations.send(method_name, @lc3, @reporter, *arguments, &block)
104
108
 
data/lib/lc3spec/dsl.rb CHANGED
@@ -1,11 +1,21 @@
1
1
  module LC3Spec
2
2
  module Dsl
3
- def set(option, value = true)
4
- @options ||= {
5
- :output => $stdout,
6
- :keep_score => false
7
- }
3
+ def self.extended(base)
4
+ base.instance_eval do
5
+ @options ||= {
6
+ :output => $stdout,
7
+ :keep_score => false
8
+ }
9
+
10
+ @possible_points ||= 0
11
+ @earned_points ||= 0
12
+
13
+ @num_tests ||= 0
14
+ @num_passed ||= 0
15
+ end
16
+ end
8
17
 
18
+ def set(option, value = true)
9
19
  if option == :output
10
20
  case value
11
21
  when File
@@ -76,21 +86,15 @@ module LC3Spec
76
86
  end
77
87
 
78
88
  def count_points(result, possible)
79
- @possible_points ||= 0
80
- @earned_points ||= 0
81
-
82
89
  @earned_points += result == :pass ? possible : 0
83
90
  @possible_points += possible
84
91
 
85
- @num_tests ||= 0
86
92
  @num_tests += 1
87
-
88
- @num_passed ||= 0
89
93
  @num_passed += result == :pass ? 1 : 0
90
94
  end
91
95
 
92
96
  def print_score
93
- return if @num_tests.nil? or (@num_tests == 0)
97
+ return if @num_tests == 0
94
98
 
95
99
  output = @options[:output]
96
100
 
data/lib/lc3spec/lc3.rb CHANGED
@@ -41,11 +41,12 @@ class LC3
41
41
  end
42
42
 
43
43
  def get_register(reg)
44
+ reg = reg.to_s.upcase.to_sym # Ruby 1.8 doesn't support Symbol#upcase
44
45
  @registers[reg]
45
46
  end
46
47
 
47
48
  def set_register(reg, val)
48
- reg = reg.upcase # Don't use ! version because it doesn't work for symbols
49
+ reg = reg.to_s.upcase # Don't use ! version because it doesn't work for symbols
49
50
 
50
51
  unless @registers.keys.include? reg.to_sym
51
52
  raise "Invalid register: #{reg.to_s}"
@@ -195,8 +196,12 @@ class LC3
195
196
 
196
197
  # There is no signal that tells the GUI that output is ready...
197
198
  # FIXME: This is a bug waiting to happen
199
+ retries = 10
198
200
  until @output.ready?
199
- sleep(0.01)
201
+ sleep(0.1)
202
+
203
+ retries -= 1
204
+ break if retries <= 0
200
205
  end
201
206
 
202
207
  while @output.ready?
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lc3spec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chun Yang
@@ -12,7 +12,8 @@ date: 2013-02-27 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: DSL for testing LC-3 assembly programs
14
14
  email: x@cyang.info
15
- executables: []
15
+ executables:
16
+ - lc3spec
16
17
  extensions: []
17
18
  extra_rdoc_files: []
18
19
  files:
@@ -26,6 +27,7 @@ files:
26
27
  - lib/lc3spec/lc3.rb
27
28
  - lib/lc3spec/main.rb
28
29
  - lib/lc3spec/reporter.rb
30
+ - bin/lc3spec
29
31
  - LICENSE
30
32
  - README.md
31
33
  homepage: http://github.com/chunyang/lc3spec
@@ -40,7 +42,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
40
42
  requirements:
41
43
  - - '>='
42
44
  - !ruby/object:Gem::Version
43
- version: '0'
45
+ version: 1.9.3
44
46
  required_rubygems_version: !ruby/object:Gem::Requirement
45
47
  requirements:
46
48
  - - '>='
@@ -53,3 +55,4 @@ signing_key:
53
55
  specification_version: 4
54
56
  summary: Testing and grading suite for LC-3 assembly programs
55
57
  test_files: []
58
+ has_rdoc: