Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature issue mumuki/mumuki platform#306 display inline errors #23

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions lib/feedback_hook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,37 +22,54 @@ def explain_missing_bracket(_, result)

def explain_missing_parameter_type(_, result)
(/#{error} <identifier> expected#{near_regex}/.match result).try do |it|
{near: it[1]}
[
{near: it[1]},
{type: :error, line: it[1]}
]
end
end

def explain_missing_return_statement(_, result)
(/#{error} missing return statement#{near_regex}/.match result).try do |it|
{near: it[1]}
[
{near: it[1]},
{type: :error, line: it[1]}
]
end
end

def explain_cannot_find_symbol(_, result)
(/#{error} cannot find symbol#{near_regex}#{symbol_regex}#{location_regex}/.match result).try do |it|
{near: it[1], symbol: it[2].strip, location: it[3].strip}
[
{near: it[1], symbol: it[2].strip, location: it[3].strip}
]
end
end

def explain_incompatible_types(_, result)
(/#{error} incompatible types: (.*) cannot be converted to (.*)#{near_regex}/.match result).try do |it|
{down: it[1], up: it[2], near: it[3]}
[
{down: it[1], up: it[2], near: it[3]},
{type: :error, line: it[1], down: it[1], up: it[2]}
]
end
end

def explain_unexpected_close_curly(_, result)
(/\(line (.*), .*\):\nunexpected CloseCurly/.match result).try do |it|
{line: it[1]}
[
{line: it[1]},
{type: :error, line: it[1], column: it[2]}
]
end
end

def explain_unexpected_close_paren(_, result)
(/\(line (.*), .*\):\nunexpected CloseParen/.match result).try do |it|
{line: it[1]}
[
{line: it[1]},
{type: :error, line: it[1], column: it[2]}
]
end
end

Expand Down Expand Up @@ -80,7 +97,10 @@ def error

def missing_character(result, character)
(/#{error} '#{character}' expected#{near_regex}/.match result).try do |it|
{near: it[1]}
[
{near: it[1]},
{type: :error, line: it[1]}
]
end
end

Expand Down
8 changes: 4 additions & 4 deletions lib/locales/en.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
en:
missing_semicolon: "Missing ';' near `%{near}`"
missing_parenthesis: "Missing '(' near `%{near}`"
cannot_find_symbol: "Cannot find `%{symbol}` declaration in `%{location}`"
incompatible_types: "Class `%{down}` should be a `%{up}`. Probably an _extends_ or _implements_ is missing near `%{near}`."
missing_bracket: "Missing { near `%{near}`. Maybe you misspelled a class or method declaration."
missing_parameter_type: "Missing parameter type near `%{near}`"
cannot_find_symbol: "Cannot find `%{symbol}` declaration in `%{location}`"
missing_parenthesis: "Missing '(' near `%{near}`"
missing_return_statement: "There is a method that must return something, but doesn't. Check your code again!"
incompatible_types: "Class `%{down}` should be a `%{up}`. Probably an _extends_ or _implements_ is missing near `%{near}`."
missing_semicolon: "Missing ';' near `%{near}`"
unexpected_close_curly: "You have a syntax error. Check if you're missing a `;` or a `{` near line %{line}."
unexpected_close_paren: "You have a syntax error. Check if you're missing a `(` or have an extra `)` near line %{line}. Also make sure all parameters declare their types."
8 changes: 4 additions & 4 deletions lib/locales/es.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
es:
missing_semicolon: "Parece que falta un ';' cerca de `%{near}`"
missing_parenthesis: "Parece que falta un '(' cerca de `%{near}`"
cannot_find_symbol: "No se encontró la definición de `%{symbol}` en `%{location}`"
incompatible_types: "La clase `%{down}` debería ser un `%{up}`. Revisá si no te falta un _extends_ o _implements_ cerca de `%{near}`."
missing_bracket: "Se esperaba una { cerca de `%{near}`. Fijate si tal vez, introdujiste un paréntesis de más o está mal escrita la declaración de clase o método."
missing_parameter_type: "Parece que falta el tipo de un parámetro cerca de `%{near}`"
cannot_find_symbol: "No se encontró la definición de `%{symbol}` en `%{location}`"
missing_parenthesis: "Parece que falta un '(' cerca de `%{near}`"
missing_return_statement: "Hay un método que debería retornar algo, pero no está retornando nada. ¡Revisá bien tu código!"
incompatible_types: "La clase `%{down}` debería ser un `%{up}`. Revisá si no te falta un _extends_ o _implements_ cerca de `%{near}`."
missing_semicolon: "Parece que falta un ';' cerca de `%{near}`"
unexpected_close_curly: "Tenés un error de sintaxis. Fijate si no te falta un `;` o una `{` cerca de la línea %{line}."
unexpected_close_paren: "Tenés un error de sintaxis. Fijate si no te falta un `(` o te sobra un `)` cerca de la línea %{line}. Asegurate también de que todos los parámetros declaren sus tipos."
5 changes: 5 additions & 0 deletions lib/test_hook.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class JavaTestHook < Mumukit::Templates::FileHook
isolated true
structured true, separator: '!!!JAVA-MUMUKI-OUTPUT!!!'
line_number_offset 12

def tempfile_extension
'.java'
Expand All @@ -26,6 +27,10 @@ def post_process_file(file, result, status)
end
end

def masked_tempfile_path
'SubmissionTest.java'
end

def compile_file_content(request)
<<EOF
import java.util.*;
Expand Down
10 changes: 5 additions & 5 deletions spec/feedback_runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class Foo {
}
})}

it {expect(feedback).to include("Hay un método que debería retornar algo, pero no está retornando nada. ¡Revisá bien tu código!")}
it {expect(feedback).to include("* Hay un método que debería retornar algo, pero no está retornando nada. ¡Revisá bien tu código!")}
end
context 'missing return statement' do
let(:request) {req(%q{
Expand Down Expand Up @@ -130,7 +130,7 @@ class Foo {
}
}}

it {expect(feedback).to include('Fijate si no te falta un `;` o una `{` cerca de la línea')}
it {expect(feedback).to include('* Tenés un error de sintaxis. Fijate si no te falta un `;` o una `{` cerca de la línea 5.')}
end

context 'missing parenthesis' do
Expand All @@ -142,7 +142,7 @@ class Foo {
}
}}

it {expect(feedback).to include('Fijate si no te falta un `(` o te sobra un `)` cerca de la línea')}
it {expect(feedback).to include('* Tenés un error de sintaxis. Fijate si no te falta un `(` o te sobra un `)` cerca de la línea 3. Asegurate también de que todos los parámetros declaren sus tipos.')}
end

context 'missing bracket' do
Expand All @@ -154,7 +154,7 @@ class Foo {
}
}}

it {expect(feedback).to include('Fijate si no te falta un `(` o te sobra un `)` cerca de la línea')}
it {expect(feedback).to include('* Tenés un error de sintaxis. Fijate si no te falta un `(` o te sobra un `)` cerca de la línea 3. Asegurate también de que todos los parámetros declaren sus tipos.')}
end

context 'missing parameter type' do
Expand All @@ -165,7 +165,7 @@ class Foo {
}
}}}

it {expect(feedback).to include('Asegurate también de que todos los parámetros declaren sus tipos')}
it {expect(feedback).to include('* Tenés un error de sintaxis. Fijate si no te falta un `(` o te sobra un `)` cerca de la línea 3. Asegurate también de que todos los parámetros declaren sus tipos.')}
end
end

Expand Down