-
Notifications
You must be signed in to change notification settings - Fork 65
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
WIP Protocol testrunner #264
Open
prawnsalad
wants to merge
6
commits into
master
Choose a base branch
from
protocol_testrunner
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
6 commits
Select commit
Hold shift + click to select a range
9524fe7
[WIP] Working implementation
prawnsalad f6f0df7
Cleaner file structure; Separate script files
prawnsalad aa3251e
Run protocol tests under jest
prawnsalad 866b2c6
Correct line number reporting
prawnsalad 7cacacd
TestRunner READWAIT command
prawnsalad cad8efa
TestRunner RESET command
prawnsalad 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
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,93 @@ | ||
// Parse 'key=val key="val" key="val val2" "key name"=val' into an object | ||
module.exports = function kvParse(inp) { | ||
let data = {}; | ||
let pos = 0; | ||
let escapeChar = '\\'; | ||
|
||
while (pos < inp.length) { | ||
let key = ''; | ||
let val = ''; | ||
|
||
key = readToken(); | ||
ffwd(); | ||
if (inp[pos] === '=') { | ||
skip(); | ||
val = readToken({isValue: true}); | ||
} else { | ||
ffwd(); | ||
val = true; | ||
} | ||
|
||
data[key] = val; | ||
} | ||
|
||
return data; | ||
|
||
// Fast forward past whitespace | ||
function ffwd() { | ||
while (inp[pos] === ' ' && pos < inp.length) { | ||
pos++; | ||
} | ||
} | ||
|
||
// Skip the current position | ||
function skip() { | ||
pos++; | ||
} | ||
|
||
// Read a block of characters. Quoted allows spaces | ||
function readToken(opts={isValue:false}) { | ||
let inQuote = false; | ||
let buffer = ''; | ||
|
||
ffwd(); | ||
do { | ||
let cur = inp[pos]; | ||
if (!cur) { | ||
break; | ||
} | ||
|
||
// Opening quote | ||
if (!inQuote && isQuote(cur)) { | ||
inQuote = true; | ||
continue; | ||
} | ||
|
||
// Escaped closing quote = not a closing quote | ||
if (inQuote && isQuote(cur) && isEscaped()) { | ||
buffer += cur; | ||
continue; | ||
} | ||
|
||
// Closing quote | ||
if (inQuote && isQuote(cur)) { | ||
inQuote = false; | ||
skip(); | ||
break; | ||
} | ||
|
||
if (!opts.isValue) { | ||
if (!inQuote && (cur === ' ' || cur === '=')) { | ||
break; | ||
} | ||
} else { | ||
// Values allow = characters | ||
if (!inQuote && cur === ' ') { | ||
break; | ||
} | ||
} | ||
|
||
buffer += cur; | ||
} while(++pos < inp.length) | ||
|
||
return buffer; | ||
} | ||
|
||
function isQuote(char) { | ||
return char === '"'; | ||
} | ||
|
||
function isEscaped() { | ||
return inp[pos-1] === escapeChar; | ||
} | ||
} |
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,9 @@ | ||
'use strict'; | ||
/* globals describe, it */ | ||
const TestProtocol = require('../test_protocol/'); | ||
|
||
describe('protocol test runners', async function() { | ||
it('should run all protocol test scripts', async function() { | ||
await TestProtocol() | ||
}); | ||
}); |
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,88 @@ | ||
const fs = require('fs'); | ||
const TestRunner = require('./testrunner'); | ||
const TestRunnerTransport = require('./testrunnertransport'); | ||
const IRC = require('../src/'); | ||
|
||
module.exports = runScripts; | ||
|
||
isMain = require.main === module; | ||
|
||
(async function() { | ||
if (isMain) { | ||
await runScripts(); | ||
} | ||
})(); | ||
|
||
async function runScripts() { | ||
// Run through each test runner script and run it | ||
let scriptsDir = __dirname + '/test_scripts/'; | ||
let scripts = fs.readdirSync(scriptsDir); | ||
for(let i=0; i<scripts.length; i++) { | ||
let scriptContent = fs.readFileSync(scriptsDir + scripts[i], 'utf8'); | ||
await runScript(scriptContent); | ||
} | ||
}; | ||
|
||
async function runScript(script) { | ||
let bot = null; | ||
|
||
const r = new TestRunner(); | ||
r.load(script); | ||
r.onReset = () => { | ||
createNewIrcClient(); | ||
}; | ||
|
||
// Start running the test runner before creating the client to be sure all events are caught | ||
let scriptRun = r.run(); | ||
createNewIrcClient(); | ||
await scriptRun; | ||
if (bot) { | ||
bot.connection.end(); | ||
} | ||
|
||
function createNewIrcClient() { | ||
if (bot) { | ||
bot.connection.end(); | ||
} | ||
|
||
bot = new IRC.Client(); | ||
bot.use(CatchAllMiddleware(r)); | ||
bot.connect({ | ||
transport: createTestRunnerTransport(r), | ||
host: 'irc.example.net', | ||
nick: 'ircfrw_testrunner', | ||
}); | ||
bot.on('registered', function() { | ||
bot.join('#prawnsalad'); | ||
}); | ||
bot.on('join', event => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these events temporary? Should be in the txt files. |
||
if (event.nick === bot.user.nick) { | ||
bot.who(event.channel); | ||
} | ||
}); | ||
|
||
if (isMain) { | ||
//bot.on('debug', l => console.log('[debug]', l)); | ||
bot.on('raw', event => console.log(`[raw ${event.from_server?'s':'c'}]`, event.line)); | ||
} | ||
} | ||
}; | ||
|
||
// Create an irc-framework transport | ||
function createTestRunnerTransport(r) { | ||
return function(...args) { | ||
return new TestRunnerTransport(r, ...args) | ||
}; | ||
} | ||
|
||
// Pass all framework events to TestRunner r | ||
function CatchAllMiddleware(r) { | ||
return function(client, raw_events, parsed_events) { | ||
parsed_events.use(theMiddleware); | ||
}; | ||
|
||
function theMiddleware(command, event, client, next) { | ||
r.addEventFromClient(command, event) | ||
next(); | ||
} | ||
} |
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,10 @@ | ||
# Testing IRC registration without CAP support | ||
|
||
# wait until we get the USER command | ||
READWAIT USER $ $ $ $ | ||
|
||
# register the client with the nick "testbot" | ||
SEND :src 001 testbot something :Welcome home | ||
|
||
# the client should now trigger a "registered" event | ||
EVENT registered nick=testbot |
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,6 @@ | ||
# Testing IRC registration without CAP support | ||
READ CAP LS 302 | ||
READ NICK $nick | ||
READ USER $ $ $ $ | ||
SEND :src 001 $nick something :Welcome home | ||
EVENT registered nick=$nick |
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,20 @@ | ||
# Test script RESET example | ||
|
||
READWAIT USER $ $ $ $ | ||
SEND :src 001 nick1 something :Welcome home | ||
EVENT registered nick=nick1 | ||
|
||
RESET | ||
READWAIT USER $ $ $ $ | ||
SEND :src 001 nick2 something :Welcome home | ||
EVENT registered nick=nick2 | ||
|
||
RESET | ||
READWAIT USER $ $ $ $ | ||
SEND :src 001 nick3 something :Welcome home | ||
EVENT registered nick=nick3 | ||
|
||
RESET | ||
READWAIT USER $ $ $ $ | ||
SEND :src 001 nick4 something :Welcome home | ||
EVENT registered nick=nick4 |
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,11 @@ | ||
# Testing sending WHO after joining a channel | ||
READ CAP LS 302 | ||
READ NICK $nick | ||
READ USER $ $ $ $ | ||
SEND :src 001 $nick something :Welcome home | ||
SEND :src 005 $nick a b c :is supported | ||
READ JOIN $chan | ||
SEND :$nick JOIN $chan | ||
EVENTWAIT join channel="$chan" nick=$nick | ||
READ WHO $1 | ||
EXPECT $1="$chan" |
Oops, something went wrong.
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.
Do we not want to hook it into the tests a little bit better, so each test becomes
it
and gets reported correctly by the test software?