-
Notifications
You must be signed in to change notification settings - Fork 8
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
Tests for Lua API extension proposed in martanne/vis#675 #12
Open
xomachine
wants to merge
9
commits into
martanne:master
Choose a base branch
from
xomachine:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e3634bd
Improved Lua API testing system
xomachine 544591b
New vis:communicate function test
xomachine 5544aca
Little improvements of the output readability
xomachine c035a50
Added test of stderr output event and writing to the process stdin
xomachine 8a6e51b
Fixes a typo in the word response
xomachine 93e6e18
Changed the vis:communicate event interface
xomachine 818df05
Changed subprocess tests according to new behavior
xomachine 165aab6
Polishes error messages in case of the test failure
xomachine 493758f
Makes tests green again
xomachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
require 'busted.runner'() | ||
|
||
local function hardfail() | ||
-- It is only way to notify about the failure from the QUIT event handler | ||
print('TEST FAILED') | ||
end | ||
|
||
local expected_events = {} | ||
|
||
local failed = false | ||
vis.events.subscribe(vis.events.QUIT, function () | ||
for k, v in pairs(expected_events) do | ||
if v and #v > 0 then | ||
failed = true | ||
print("The following events did not happened for process", k) | ||
for i, vv in pairs(v) do | ||
print(tostring(i)..": ", | ||
vv.etype, " - ("..tostring(vv.expected_code) .. ", " .. tostring(vv.expected_buffer)..")") | ||
end | ||
end | ||
end | ||
if failed then hardfail() end | ||
end) | ||
|
||
vis.events.subscribe(vis.events.PROCESS_RESPONSE, function (name, et, ec, eb) | ||
if expected_events[name] and #(expected_events[name]) > 0 then | ||
local current_event = table.remove(expected_events[name], 1) | ||
if ec ~= current_event.expected_code or eb ~= current_event.expected_buffer or et ~= current_event.etype then | ||
print("Event assert failed for process:", name) | ||
print("Got event type:", "("..type(et)..")", et) | ||
print("Expected:", "("..type(current_event.etype)..")", current_event.etype) | ||
print("Got event code:", "(", type(ec), ")", ec) | ||
print("Expected:", "("..type(current_event.expected_code)..")", | ||
current_event.expected_code) | ||
print("Got event buffer:", "(", type(eb), ")", eb) | ||
print("Expected:", "("..type(current_event.expected_buffer)..")", | ||
current_event.expected_buffer) | ||
if #(expected_events[name]) > 0 then | ||
print("Remaining expected events to be fired by process", name) | ||
for i, k in pairs(expected_events[name]) do | ||
print(tostring(i)..": ", | ||
k.etype, " - ("..tostring(k.expected_code) .. ", " .. tostring(k.expected_buffer)..")") | ||
end | ||
end | ||
hardfail() | ||
end | ||
end | ||
end) | ||
|
||
local function event_assert(name, eventtype, expected_code, expected_buffer) | ||
if not expected_events[name] then expected_events[name] = {} end | ||
table.insert(expected_events[name], { | ||
etype = eventtype, | ||
expected_code = expected_code, | ||
expected_buffer = expected_buffer | ||
}) | ||
end | ||
|
||
describe("vis.communicate", function () | ||
it("process creation", function () | ||
event_assert("starttest", "STDOUT", nil, "testanswer\n") | ||
event_assert("starttest", "EXIT", 0, nil) | ||
vis:communicate("starttest", "echo testanswer") | ||
end) | ||
it("process termination", function() | ||
event_assert("termtest", "SIGNAL", 15, nil) | ||
local handle = vis:communicate("termtest", "sleep 1s") | ||
handle:close() | ||
end) | ||
it("process input/stderr", function() | ||
event_assert("inputtest", "STDERR", nil, "testdata\n") | ||
event_assert("inputtest", "EXIT", 0, nil) | ||
local handle = vis:communicate("inputtest", "read n; echo $n 1>&2") | ||
handle:write("testdata\n") | ||
handle:flush() | ||
-- do not close handle because it is being closed automaticaly | ||
-- when process quits | ||
end) | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did this ever work? Shouldn't the assert be
event_assert("termtest", "EXIT", 143, nil)
? I'm not sure there is a reliable way to catch aSIGNAL
event.