diff --git a/lib/assets_server.rb b/lib/assets_server.rb index ec0b456..0a2edfb 100644 --- a/lib/assets_server.rb +++ b/lib/assets_server.rb @@ -4,9 +4,12 @@ class Mumukit::Server::App < Sinatra::Base register Sinatra::CrossOrigin + configure do + enable :cross_origin + end + def self.get_asset(route, path, type) get "/assets/#{route}" do - cross_origin send_file File.expand_path("bower_components/#{path}"), { type: type } end end diff --git a/lib/checker.rb b/lib/checker.rb index 05674e3..2ab752e 100644 --- a/lib/checker.rb +++ b/lib/checker.rb @@ -11,14 +11,18 @@ def check_final_board(output, expected) result = output[:result] assert_not_boom status, result - actual = result[:finalBoard][:table][:gbb] + + expected_board = result[:extraBoard] + actual_board = result[:finalBoard] + boards_match = board_json(expected_board).eql? board_json(actual_board) + headers_match = expected_board[:head].eql?(actual_board[:head]) || !@options[:check_head_position] fail_with status: :check_final_board_failed_different_boards, result: { initial: result[:initialBoard], - expected: result[:extraBoard], - actual: result[:finalBoard] - } if clean(actual) != clean(expected) + expected: expected_board, + actual: actual_board + } unless boards_match && headers_match end def check_error(output, expected) @@ -77,11 +81,8 @@ def fail_with(error) fail error.to_json end - def clean(gbb) - clean_gbb = gbb.gsub /\r|\n| Azul 0| Negro 0| Rojo 0| Verde 0/, '' - decapitated_gbb = clean_gbb.gsub /head \d+ \d+/, '' - - @options[:check_head_position] ? clean_gbb : decapitated_gbb + def board_json(board) + board[:table][:json] end def convert_known_reason_code(code) diff --git a/lib/gobstones/batch_parser.rb b/lib/gobstones/batch_parser.rb index 668c9ed..29d129c 100644 --- a/lib/gobstones/batch_parser.rb +++ b/lib/gobstones/batch_parser.rb @@ -45,7 +45,15 @@ def parse_options(test) struct(key: :show_final_board, default: true), struct(key: :check_head_position, default: false), struct(key: :subject, default: nil) - ].map { |it| [it.key, test[it.key] || it.default] }.to_h + ].map { |it| [ + it.key, + if test[it.key].nil? + it.default + else + test[it.key] + end + ] + }.to_h end def preconditions diff --git a/spec/metatest_spec.rb b/spec/metatest_spec.rb index 56ecc3a..d048e2b 100644 --- a/spec/metatest_spec.rb +++ b/spec/metatest_spec.rb @@ -10,32 +10,13 @@ end let(:dummy_view_board) do { head: { x: 0, y: 0 }, width: 3, height: 3, table: { - json: [] + json: [[{}, {}, {}], [{}, {}, {}], [{}, {}, {}]] } } end + let(:dummy_gbb) do + 'GBB/1.0\r\nsize 1 1\r\nhead 0 0\r\n' + end let(:exit_status) { 29 } - let(:compilation_board) { - [ - { - status: "passed", - result: { - extraBoard: dummy_view_board, - initialBoard: dummy_view_board, - finalBoard: { - head: { x: 0, y: 1 }, - width: 3, - height: 3, - table: { - gbb: "GBB/1.0\r\nsize 3 3\r\nhead 1 0\r\n", - json: [] - }, - returnValue: exit_status - }, - } - } - ] - } - let(:compilation_boom) do [ { @@ -62,48 +43,79 @@ ] end + def board_with_stones(headX, headY, cell10 = {}) + { + head: { x: headX, y: headY }, + width: 3, + height: 3, + table: { + gbb: dummy_gbb, + json: [ + [{}, {}, {}], + [{}, {}, {}], + [{ black: 1, green: 1 }, cell10, {}] + ] + }, + returnValue: exit_status + } + end + + def compilation_board(expected_board = dummy_view_board) + [ + { + status: "passed", + result: { + extraBoard: expected_board, + initialBoard: dummy_view_board, + finalBoard: board_with_stones(0, 1) + } + } + ] + end + describe 'final_board postcondition' do - context 'when the program returns a final board' do + let(:examples) { + [{ + id: 0, + postconditions: { + final_board: dummy_gbb + } + }] + } - let(:compilation) { compilation_board } + context 'when the program returns a final board' do context 'when passes with check_head_position=true' do - let(:examples) { - [{ - id: 0, - postconditions: { - final_board: "GBB/1.0\r\nsize 3 3\r\nhead 1 0\r\n" - } - }] + let(:compilation) { + compilation_board board_with_stones 0, 1 } it { expect(result[0][0]).to include :passed } end context 'when passes with check_head_position=false' do + let(:compilation) { + compilation_board board_with_stones 5, 5 + } + let(:options) { { show_initial_board: false, check_head_position: false } } - let(:examples) { - [{ - id: 0, - postconditions: { - final_board: "GBB/1.0\r\nsize 3 3\r\nhead 5 5\r\n" - } - }] + it { expect(result[0][0]).to include :passed } + end + + context 'when fails by different boards (header)' do + let(:compilation) { + compilation_board board_with_stones 2, 2 } - it { expect(result[0][0]).to include :passed } + it { expect(result[0][0]).to include :failed } + it { expect(result[0][0][2]).to include "Expected final board" } end - context 'when fails by different boards' do - let(:examples) { - [{ - id: 0, - postconditions: { - final_board: "GBB/1.0\r\nsize 3 3\r\nhead 2 2\r\n" - } - }] + context 'when fails by different boards (stones)' do + let(:compilation) { + compilation_board board_with_stones 0, 1, { blue: 9 } } it { expect(result[0][0]).to include :failed } @@ -113,23 +125,10 @@ end context 'when the program does boom' do - let(:compilation) { compilation_boom } - context 'when fails because the program did boom' do - let(:examples) { - [{ - id: 0, - postconditions: { - final_board: "GBB/1.0\r\nsize 3 3\r\nhead 1 0\r\n" - } - }] - } - - it { expect(result[0][0]).to include :failed } - it { expect(result[0][0][2]).to include "The program did BOOM." } - end - + it { expect(result[0][0]).to include :failed } + it { expect(result[0][0][2]).to include "The program did BOOM." } end end @@ -153,7 +152,6 @@ end context 'when the program does boom' do - let(:compilation) { compilation_boom } context 'with the same reason as expected' do @@ -190,7 +188,6 @@ } context 'when the program returns a final board' do - let(:compilation) { compilation_board } context 'when passes with equal value' do