Skip to content
This repository was archived by the owner on Oct 14, 2020. It is now read-only.

[Elixir] Fix LF issue #417

Merged
merged 1 commit into from
Jun 15, 2017
Merged
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
12 changes: 6 additions & 6 deletions frameworks/elixir/cw_formatter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ defmodule CWFormatter do
end

def handle_event({:suite_finished, run_us, load_us}, _config) do
IO.puts "<COMPLETEDIN::>" <> format_time(run_us, load_us)
IO.puts "\n<COMPLETEDIN::>" <> format_time(run_us, load_us)
:remove_handler
end

def handle_event({:test_started, %ExUnit.Test{} = test}, config) do
test_name = trace_test_name(test) |> nl_to_lf()
IO.puts "<IT::>#{test_name}"
IO.puts "\n<IT::>#{test_name}"
{:ok, config}
end

def handle_event({:test_finished, %ExUnit.Test{state: nil}}, config) do
IO.puts "<PASSED::>Test Passed"
IO.puts "\n<PASSED::>Test Passed"
{:ok, %{config | tests_counter: config.tests_counter + 1}}
end

Expand All @@ -49,14 +49,14 @@ defmodule CWFormatter do
end

def handle_event({:test_finished, %ExUnit.Test{state: {:invalid, _}} = test}, config) do
IO.puts "<ERROR::>" <> trace_test_result(test)
IO.puts "\n<ERROR::>" <> trace_test_result(test)

{:ok, %{config | tests_counter: config.tests_counter + 1,
invalids_counter: config.invalids_counter + 1}}
end

def handle_event({:test_finished, %ExUnit.Test{state: {:failed, failed}} = test}, config) do
IO.write "<FAILED::>" <> trace_test_result(test) <> @lf
IO.write "\n<FAILED::>" <> trace_test_result(test) <> @lf

formatted = format_test_failure(test, failed, config.failures_counter + 1,
config.width, fn _type, msg -> msg end)
Expand All @@ -67,7 +67,7 @@ defmodule CWFormatter do
end

def handle_event({:case_started, %ExUnit.TestCase{name: name}}, config) do
IO.puts "<DESCRIBE::>" <> inspect(name)
IO.puts "\n<DESCRIBE::>" <> inspect(name)

{:ok, config}
end
Expand Down
2 changes: 1 addition & 1 deletion frameworks/elixir/cw_runner.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ defmodule CWRunner do
|> case do
:ok -> :ok
{:error, message} ->
IO.puts "<ERROR::>" <> message
IO.puts "\n<ERROR::>" <> message
end
end

Expand Down
219 changes: 192 additions & 27 deletions test/runners/elixir_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,76 +6,211 @@ describe('elixir runner', function() {
runner.assertCodeExamples('elixir');

it('handles basic code evaluation', function(done) {
runner.run({language: 'elixir', code: 'IO.puts "This was real. And it was me. I had lived that life, and I had died that death. I was staring at the very end of me. ― Hilary Duff, Elixir (2010)"'}, function(buffer) {
runner.run({
language: 'elixir',
code: 'IO.puts "This was real. And it was me. I had lived that life, and I had died that death. I was staring at the very end of me. ― Hilary Duff, Elixir (2010)"'
}, function(buffer) {
expect(buffer.stdout).to.contain('This was real');
done();
});
});

describe('ex_unit', function() {
it('handles a simple test unit defininition', function(done) {
runner.run({language: 'elixir', code: 'defmodule AEqual1 do\n def a, do: 1\nend', fixture: 'defmodule TestAEqual1 do\nuse ExUnit.Case\nimport AEqual1, only: [a: 0]\ntest "a is equal 1" do\nassert a() == 1\nend\nend', testFramework: 'ex_unit'}, function(buffer) {
expect(buffer.stdout).to.contain('<DESCRIBE::>TestAEqual1');
expect(buffer.stdout).to.contain('<IT::>a is equal 1\n<PASSED::>Test Passed\n');
runner.run({
language: 'elixir',
code: 'defmodule AEqual1 do\n def a, do: 1\nend',
fixture: [
'defmodule TestAEqual1 do',
' use ExUnit.Case',
' import AEqual1, only: [a: 0]',
' test "a is equal 1" do',
' assert a() == 1',
' end',
'end',
].join('\n'),
testFramework: 'ex_unit'
}, function(buffer) {
expect(buffer.stdout).to.contain('\n<DESCRIBE::>TestAEqual1');
expect(buffer.stdout).to.contain('\n<IT::>a is equal 1\n\n<PASSED::>Test Passed\n');
expect(buffer.stdout).to.match(/<COMPLETEDIN::>Finished in [0-9.]+ seconds \([0-9.]+s on load, [0-9.]+s on tests\)/);
done();
});
});

it('handles test unit with a couple of defininitions', function(done) {
runner.run({language: 'elixir', code: 'defmodule YesNo do\n def yes, do: "yes"\n def no, do: "no"\nend', fixture: 'defmodule TestYesNo do\nuse ExUnit.Case\ntest ".yes is yes" do\nassert YesNo.yes == "yes"\nend\ntest ".no is no" do\nassert YesNo.no == "no"\nend\nend', testFramework: 'ex_unit'}, function(buffer) {
expect(buffer.stdout).to.contain('<DESCRIBE::>TestYesNo');
expect(buffer.stdout).to.contain('<IT::>.yes is yes\n<PASSED::>Test Passed\n');
expect(buffer.stdout).to.contain('<IT::>.no is no\n<PASSED::>Test Passed\n');
runner.run({
language: 'elixir',
code: [
'defmodule YesNo do',
' def yes, do: "yes"',
' def no, do: "no"',
'end',
].join('\n'),
fixture: [
'defmodule TestYesNo do',
' use ExUnit.Case',
' test ".yes is yes" do',
' assert YesNo.yes == "yes"',
' end',
' test ".no is no" do',
' assert YesNo.no == "no"',
' end',
'end',
].join('\n'),
testFramework: 'ex_unit'
}, function(buffer) {
expect(buffer.stdout).to.contain('\n<DESCRIBE::>TestYesNo');
expect(buffer.stdout).to.contain('\n<IT::>.yes is yes\n\n<PASSED::>Test Passed\n');
expect(buffer.stdout).to.contain('\n<IT::>.no is no\n\n<PASSED::>Test Passed\n');
expect(buffer.stdout).to.match(/<COMPLETEDIN::>Finished in [0-9.]+ seconds \([0-9.]+s on load, [0-9.]+s on tests\)/);
done();
});
});
it('handles test which does not pass', function(done) {
runner.run({language: 'elixir', code: 'defmodule NotPass do\n def can_i_enter?, do: :no\nend', fixture: 'defmodule TestNotPass do\nuse ExUnit.Case\ntest "passes if works" do\nassert NotPass.can_i_enter? == :yes\nend\nend', testFramework: 'ex_unit'}, function(buffer) {
expect(buffer.stdout).to.contain('<DESCRIBE::>TestNotPass');
expect(buffer.stdout).to.contain('<IT::>passes if works\n<FAILED::>passes if works');
runner.run({
language: 'elixir',
code: [
'defmodule NotPass do',
' def can_i_enter?, do: :no',
'end',
].join('\n'),
fixture: [
'defmodule TestNotPass do',
' use ExUnit.Case',
' test "passes if works" do',
' assert NotPass.can_i_enter? == :yes',
' end',
'end',
].join('\n'),
testFramework: 'ex_unit'
}, function(buffer) {
expect(buffer.stdout).to.contain('\n<DESCRIBE::>TestNotPass');
expect(buffer.stdout).to.contain('\n<IT::>passes if works\n\n<FAILED::>passes if works');
expect(buffer.stdout).to.match(/<COMPLETEDIN::>Finished in [0-9.]+ seconds \([0-9.]+s on load, [0-9.]+s on tests\)/);
done();
});
});
it('handles test unit with pass and not-pass tests', function(done) {
runner.run({language: 'elixir', code: 'defmodule YesBrokenNo do\n def yes, do: "yes"\n def no, do: "yes"\nend', fixture: 'defmodule TestYesBrokenNo do\nuse ExUnit.Case\ntest ".yes is yes" do\nassert YesBrokenNo.yes == "yes"\nend\ntest ".no is no" do\nassert YesBrokenNo.no == "no"\nend\nend', testFramework: 'ex_unit'}, function(buffer) {
expect(buffer.stdout).to.contain('<DESCRIBE::>TestYesBrokenNo');
expect(buffer.stdout).to.contain('<IT::>.yes is yes\n<PASSED::>Test Passed\n');
expect(buffer.stdout).to.contain('<IT::>.no is no\n<FAILED::>.no is no');
runner.run({
language: 'elixir',
code: [
'defmodule YesBrokenNo do',
' def yes, do: "yes"',
' def no, do: "yes"',
'end',
].join('\n'),
fixture: [
'defmodule TestYesBrokenNo do',
' use ExUnit.Case',
' test ".yes is yes" do',
' assert YesBrokenNo.yes == "yes"',
' end',
' test ".no is no" do',
' assert YesBrokenNo.no == "no"',
' end',
'end',
].join('\n'),
testFramework: 'ex_unit'
}, function(buffer) {
expect(buffer.stdout).to.contain('\n<DESCRIBE::>TestYesBrokenNo');
expect(buffer.stdout).to.contain('\n<IT::>.yes is yes\n\n<PASSED::>Test Passed\n');
expect(buffer.stdout).to.contain('\n<IT::>.no is no\n\n<FAILED::>.no is no');
expect(buffer.stdout).to.match(/<COMPLETEDIN::>Finished in [0-9.]+ seconds \([0-9.]+s on load, [0-9.]+s on tests\)/);
done();
});
});

describe('compilation errors', function() {
it('catches compilation error of the code module', function(done) {
runner.run({language: 'elixir', code: 'defodule BrokenModule do\n def broken, do: true\nend', fixture: 'defmodule TestBrokenModule do\nend', testFramework: 'ex_unit'}, function(buffer) {
runner.run({
language: 'elixir',
code: [
'defodule BrokenModule do',
' def broken, do: true',
'end',
].join('\n'),
fixture: [
'defmodule TestBrokenModule do',
'end',
].join('\n'),
testFramework: 'ex_unit'
}, function(buffer) {
console.log(buffer);
expect(buffer.stdout).to.contain('<ERROR::>solution:1: undefined function defodule/2\n');
expect(buffer.stdout).to.contain('\n<ERROR::>solution:1: undefined function defodule/2\n');
done();
});
});
it('catches compilation error of the fixture module', function(done) {
runner.run({language: 'elixir', code: 'defmodule BrokenFixture do\n def broken, do: true\nend', fixture: 'defmodule TestBrokenFixture do\n -> hanging_arrow \n end', testFramework: 'ex_unit'}, function(buffer) {
expect(buffer.stdout).to.contain('<ERROR::>fixture:2: unhandled operator ->');
runner.run({
language: 'elixir',
code: [
'defmodule BrokenFixture do',
' def broken, do: true',
'end',
].join('\n'),
fixture: [
'defmodule TestBrokenFixture do',
' -> hanging_arrow ',
'end',
].join('\n'),
testFramework: 'ex_unit'
}, function(buffer) {
expect(buffer.stdout).to.contain('\n<ERROR::>fixture:2: unhandled operator ->');
done();
});
});
});

describe('runtime errors', function() {
it('catches runtime error of the code module', function(done) {
runner.run({language: 'elixir', code: 'defmodule RuntimeIssue do\n def make_issue do\n 5 = 8\nend\nend', fixture: 'defmodule TestRuntimeIssue do\nuse ExUnit.Case\ntest "have runtime issue" do\n RuntimeIssue.make_issue \nend\nend', testFramework: 'ex_unit'}, function(buffer) {
expect(buffer.stdout).to.contain('<DESCRIBE::>TestRuntimeIssue');
expect(buffer.stdout).to.contain('<IT::>have runtime issue\n<FAILED::>have runtime issue');
runner.run({
language: 'elixir',
code: [
'defmodule RuntimeIssue do',
' def make_issue do',
' 5 = 8',
' end',
'end',
].join('\n'),
fixture: [
'defmodule TestRuntimeIssue do',
' use ExUnit.Case',
' test "have runtime issue" do',
' RuntimeIssue.make_issue',
' end',
'end',
].join('\n'),
testFramework: 'ex_unit'
}, function(buffer) {
expect(buffer.stdout).to.contain('\n<DESCRIBE::>TestRuntimeIssue');
expect(buffer.stdout).to.contain('\n<IT::>have runtime issue\n\n<FAILED::>have runtime issue');
done();
});
});

it('catches runtime error of the fixture module', function(done) {
runner.run({language: 'elixir', code: 'defmodule FixtureIssue do\n def no_issue do\n :no_issue\nend\nend', fixture: 'defmodule TestFixtureIssue do\nuse ExUnit.Case\ntest "have fixture issue" do\n ModuleNotExist.call_it() \nend\nend', testFramework: 'ex_unit'}, function(buffer) {
expect(buffer.stdout).to.contain('<DESCRIBE::>TestFixtureIssue');
expect(buffer.stdout).to.contain('<IT::>have fixture issue\n<FAILED::>have fixture issue');
runner.run({
language: 'elixir',
code: [
'defmodule FixtureIssue do',
' def no_issue do',
' :no_issue',
' end',
'end',
].join('\n'),
fixture: [
'defmodule TestFixtureIssue do',
' use ExUnit.Case',
' test "have fixture issue" do',
' ModuleNotExist.call_it()',
' end',
'end',
].join('\n'),
testFramework: 'ex_unit'
}, function(buffer) {
expect(buffer.stdout).to.contain('\n<DESCRIBE::>TestFixtureIssue');
expect(buffer.stdout).to.contain('\n<IT::>have fixture issue\n\n<FAILED::>have fixture issue');
done();
});
});
Expand All @@ -85,18 +220,48 @@ describe('elixir runner', function() {
// Due to ExUnit.start, it can add COMPLETEDIN:: at the end.
// That's why we match with .contain and not .equal
it('handles correctly empty fixture', function(done) {
runner.run({language: 'elixir', code: 'IO.puts "Hello"', fixture: '', testFramework: 'ex_unit'}, function(buffer) {
runner.run({
language: 'elixir',
code: 'IO.puts "Hello"',
fixture: '',
testFramework: 'ex_unit'
}, function(buffer) {
expect(buffer.stdout).to.contain('Hello\n');
done();
});
});
it('handles correctly fixture with just comments', function(done) {
runner.run({language: 'elixir', code: 'IO.puts "Hello comment"', fixture: '# this is comment', testFramework: 'ex_unit'}, function(buffer) {
runner.run({
language: 'elixir',
code: 'IO.puts "Hello comment"',
fixture: '# this is comment',
testFramework: 'ex_unit'
}, function(buffer) {
expect(buffer.stdout).to.contain('Hello comment\n');
done();
});
});
});

it('should have output format command on independent line', function(done) {
runner.run({
language: 'elixir',
testFramework: 'ex_unit',
code: '#',
fixture: [
'defmodule Tests do',
' use ExUnit.Case',
' test "test" do',
' IO.write "foo"',
' assert 1 == 2',
' end',
'end',
].join('\n'),
}, function(buffer) {
expect(buffer.stdout).to.contain('\n<DESCRIBE::>');
done();
});
});
});
});
});