irctk

libircclient binding for scripts
git clone https://a3nm.net/git/irctk/
Log | Files | Refs | README

commit 156c7c631ec78059a18b1f9280dbe14ca5223055
parent 21b2de317376a94264cb9b4868b68b7523924dfa
Author: Antoine Amarilli <a3nm@a3nm.net>
Date:   Tue,  7 Aug 2012 23:11:25 +0200

parallelize and document test suite

Diffstat:
README | 10+++++++++-
irctk.c | 2+-
runtest.sh | 10++++++++++
test/1events.sh | 86+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
test/ajoin.sh | 26++++++++++++++++++++++++++
test/all.sh | 9++++++---
test/autojoin.sh | 18------------------
test/change-nick.sh | 19-------------------
test/events.sh | 83-------------------------------------------------------------------------------
test/filterprune.sh | 20--------------------
test/first.sh | 9++++++---
test/fnick.sh | 19+++++++++++++++++++
test/force-nick.sh | 16----------------
test/fprune.sh | 24++++++++++++++++++++++++
test/host.sh | 9++++++---
test/last-posted.sh | 28----------------------------
test/lpost.sh | 34++++++++++++++++++++++++++++++++++
test/nick.sh | 24++++++++++++++++++++++++
test/order1.sh | 30++++++++++++++++++++++++++++++
test/order2.sh | 48++++++++++++++++++++++++++++++++++++++++++++++++
test/order3.sh | 34++++++++++++++++++++++++++++++++++
test/order_1.sh | 27---------------------------
test/order_2.sh | 45---------------------------------------------
test/order_3.sh | 30------------------------------
test/own.sh | 9++++++---
test/password.sh | 9++++++---
test/simple.sh | 9++++++---
test/sync.sh | 21++++++++++++---------
tests.sh | 12------------
tests_parallel.sh | 4++++
tests_sequential.sh | 11+++++++++++
31 files changed, 408 insertions(+), 327 deletions(-)

diff --git a/README b/README @@ -192,7 +192,15 @@ This setting is perfect if you want to reply to messages by users and if your replies are instantaneous. If they are not, consider writing your own logic to route messages according to your needs. -== 7. Caveats == +== 7. Test suite == + +You can run the test suite with ./tests_sequential.sh. This requires a working +IRC server to run on localhost:6667. + +If you have GNU parallel and if your IRC server isn't afraid of many connections +from a single IP, you can run the tests in parallel: ./tests_parallel.sh. + +== 8. Caveats == irctk has not been audited thoroughly for bugs or security vulnerabilities. Be cautious if you intend to connect it to an IRC server with untrusted users. diff --git a/irctk.c b/irctk.c @@ -1257,7 +1257,7 @@ void manage_event (irc_session_t *session, const char *event, const char *origin if (args.force_nick) { die(E_BADNAME, "Invalid nick\n"); } else { - // TODO does not work + // TODO should only be done during startup! info("Invalid nick, reverting to \"irctk\"\n"); strncpy(args.nick, "irctk", MAX_NICK_LEN-1); rsl = irc_cmd_nick(session, "irctk"); diff --git a/runtest.sh b/runtest.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +cd test +if ./$1 +then + echo "$1: passed" +else + echo "$1: FAILED" +fi + diff --git a/test/1events.sh b/test/1events.sh @@ -0,0 +1,86 @@ +#!/bin/bash + +trap 'kill $(jobs -p)' EXIT + +mkdir -p events +cd events + +cat >tosay <<EOF +/join #events_test2 +[#events_test1] /nick eventsop2 +/mode +n +/mode -n +/part +[#events_test1,#events_test2] /topic mytopic +[#events_test2] /invite eventsc +[#events_test2] /kick eventsc kickarg +/say hello +/ /hello2 +/quit quitarg +EOF +cat > ref_message <<EOF +[#events_test1] -!- eventsm has joined #events_test1 +[#events_test2] -!- eventsm has joined #events_test2 +[#events_test1] -!- eventsc has joined #events_test1 +[#events_test2] -!- eventsc has joined #events_test2 +[#events_test1] -!- eventsn has joined #events_test1 +[#events_test2] -!- eventsn has joined #events_test2 +[#events_test1] -!- eventsu has joined #events_test1 +[#events_test2] -!- eventsu has joined #events_test2 +[#events_test1] <eventsu> /join #events_wrong +[] -!- eventsop is now known as eventsop2 +[#events_test1] -!- eventsop2 mode +n on #events_test1 +[#events_test1] -!- eventsop2 mode -n on #events_test1 +[#events_test1] -!- eventsop2 has left #events_test1 (eventsop2) +[#events_test2] -!- eventsop2 changed the topic of #events_test2 to mytopic +[#events_test2] -!- eventsc was kicked from #events_test2 by eventsop2 (kickarg) +[#events_test2] <eventsop2> hello +[#events_test2] <eventsop2> /hello2 +[] -!- eventsop2 has quit ("quitarg") +EOF +cat > ref_command <<EOF +[#events_test1] <eventsc> /join #events_test1 +[#events_test2] <eventsc> /join #events_test2 +[#events_test1] <eventsn> /join #events_test1 +[#events_test2] <eventsn> /join #events_test2 +[#events_test1] <eventsu> /join #events_test1 +[#events_test2] <eventsu> /join #events_test2 +[#events_test1] <eventsu> / /join #events_wrong +[] <eventsop> /nick eventsop2 +[#events_test1] <eventsop2> /mode +n #events_test1 +[#events_test1] <eventsop2> /mode -n #events_test1 +[#events_test1] <eventsop2> /part #events_test1 +[#events_test2] <eventsop2> /topic mytopic +[#events_test2] <eventsop2> /kick eventsc kickarg +EOF +cat > ref_nothing <<EOF +[#events_test1] <eventsu> /join #events_wrong +[#events_test2] <eventsop2> hello +[#events_test2] <eventsop2> /hello2 +EOF + +(sleep 6; cat tosay) | + ../../irctk -p eventsop@localhost \#events_test1 \#events_test2 2>/dev/null > /dev/null& +PID=$! +sleep 1 +tail -f /dev/null | ../../irctk -m eventsm@localhost \#events_test1 \#events_test2 > heard_message & +PID1=$! +sleep 1 +tail -f /dev/null | ../../irctk -c eventsc@localhost \#events_test1 \#events_test2 > heard_command & +PID2=$! +sleep 1 +tail -f /dev/null | ../../irctk -n eventsn@localhost \#events_test1 \#events_test2 > heard_nothing & +PID3=$! +sleep 2 +(echo '/join #events_wrong'; tail -f /dev/null) | + ../../irctk -E0 eventsu@localhost \#events_test1 \#events_test2 > /dev/null & +PID4=$! +wait $PID +sleep 3 +kill $PID1 $PID2 $PID3 +sleep 0.3 +kill $PID4 + +diff ref_message heard_message && diff ref_command heard_command \ + && diff ref_nothing heard_nothing + diff --git a/test/ajoin.sh b/test/ajoin.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +trap 'kill $(jobs -p)' EXIT + +mkdir -p ajoin +cd ajoin + +seq 3 | sed 's/.*/[#ajoin_test] <ajoino&> &/' > ref +(echo '/mode +n'; tail -f /dev/null) | + ../../irctk ajoini@localhost \#ajoin_test > heard & +PID=$! +sleep 1 +echo 1 | + ../../irctk -J ajoino1@localhost \#ajoin_test \#ajoin_testb +sleep 1 +echo '[#ajoin_test] 2' | + ../../irctk ajoino2@localhost \#ajoin_testb +sleep 1 +echo 3 | + ../../irctk -l ajoino3@localhost \#ajoin_testb \#ajoin_test +sleep 1 +echo '[#ajoin_test] 4' | + ../../irctk -J ajoino4@localhost \#ajoin_testb 2>/dev/null +sleep 1 +kill $PID +diff ref heard diff --git a/test/all.sh b/test/all.sh @@ -2,11 +2,14 @@ trap 'kill $(jobs -p)' EXIT -seq 3 | sed 's/^.*/[#testa] <out> &\n[#testb] <out> &/' > ref -cat fifo | ../irctk in@localhost \#testa \#testb > heard & +mkdir -p all +cd all + +seq 3 | sed 's/^.*/[#all_testa] <allout> &\n[#all_testb] <allout> &/' > ref +tail -f /dev/null | ../../irctk allin@localhost \#all_testa \#all_testb > heard & PID=$! sleep 1 -seq 3 | ../irctk out@localhost -l \#testa \#testb +seq 3 | ../../irctk allout@localhost -l \#all_testa \#all_testb sleep 1 kill $PID diff ref heard diff --git a/test/autojoin.sh b/test/autojoin.sh @@ -1,18 +0,0 @@ -#!/bin/bash - -trap 'kill $(jobs -p)' EXIT - -seq 3 | sed 's/.*/[#test] <out&> &/' > ref -(echo '/mode +n'; cat fifo) | ../irctk in@localhost \#test > heard & -PID=$! -sleep 1 -echo 1 | ../irctk -J out1@localhost \#test \#testb -sleep 1 -echo '[#test] 2' | ../irctk out2@localhost \#testb -sleep 1 -echo 3 | ../irctk -l out3@localhost \#testb \#test -sleep 1 -echo '[#test] 4' | ../irctk -J out4@localhost \#testb 2>/dev/null -sleep 1 -kill $PID -diff ref heard diff --git a/test/change-nick.sh b/test/change-nick.sh @@ -1,19 +0,0 @@ -#!/bin/bash - -trap 'kill $(jobs -p)' EXIT - -seq 3 | sed 's/^/[#testb] <in__> /' > ref -cat fifo1 | ../irctk in@localhost \#testb > heard1 & -PID1=$! -sleep 1 -cat fifo2 | ../irctk in@localhost > heard2 2>error2 & -PID2=$! -sleep 1 -cat fifo3| ../irctk out@localhost \#test > heard3 2>error3 & -PID3=$! -sleep 1 -seq 3 | ../irctk -o in@localhost \#testb > heard4 2>error4 -sleep 1 -kill $PID1 $PID2 $PID3 -diff ref heard1 && diff ref heard4 && grep -q taken error2 \ - && grep -q taken error4 diff --git a/test/events.sh b/test/events.sh @@ -1,83 +0,0 @@ -#!/bin/bash - -trap 'kill $(jobs -p)' EXIT - -cat >tosay <<EOF -/join #test2 -[#test1] /nick op2 -/mode +n -/mode -n -/part -[#test1,#test2] /topic mytopic -[#test2] /invite command -[#test2] /kick command kickarg -/say hello -/ /hello2 -/quit quitarg -EOF -cat > ref_message <<EOF -[#test1] -!- message has joined #test1 -[#test2] -!- message has joined #test2 -[#test1] -!- command has joined #test1 -[#test2] -!- command has joined #test2 -[#test1] -!- nothing has joined #test1 -[#test2] -!- nothing has joined #test2 -[#test1] -!- useless has joined #test1 -[#test2] -!- useless has joined #test2 -[#test1] <useless> /join #wrong -[] -!- op is now known as op2 -[#test1] -!- op2 mode +n on #test1 -[#test1] -!- op2 mode -n on #test1 -[#test1] -!- op2 has left #test1 (op2) -[#test2] -!- op2 changed the topic of #test2 to mytopic -[#test2] -!- command was kicked from #test2 by op2 (kickarg) -[#test2] <op2> hello -[#test2] <op2> /hello2 -[] -!- op2 has quit ("quitarg") -EOF -cat > ref_command <<EOF -[#test1] <command> /join #test1 -[#test2] <command> /join #test2 -[#test1] <nothing> /join #test1 -[#test2] <nothing> /join #test2 -[#test1] <useless> /join #test1 -[#test2] <useless> /join #test2 -[#test1] <useless> / /join #wrong -[] <op> /nick op2 -[#test1] <op2> /mode +n #test1 -[#test1] <op2> /mode -n #test1 -[#test1] <op2> /part #test1 -[#test2] <op2> /topic mytopic -[#test2] <op2> /kick command kickarg -EOF -cat > ref_nothing <<EOF -[#test1] <useless> /join #wrong -[#test2] <op2> hello -[#test2] <op2> /hello2 -EOF - -(sleep 5; cat tosay) | - ../irctk -p op@localhost \#test1 \#test2 2>/dev/null > /dev/null& -sleep 1 -PID=$! -cat fifo1 | ../irctk -m message@localhost \#test1 \#test2 > heard_message & -PID1=$! -sleep 0.3 -cat fifo2 | ../irctk -c command@localhost \#test1 \#test2 > heard_command & -PID2=$! -sleep 0.3 -cat fifo3 | ../irctk -n nothing@localhost \#test1 \#test2 > heard_nothing & -PID3=$! -sleep 0.3 -(echo '/join #wrong'; tail -f /dev/null) | - ../irctk -E0 useless@localhost \#test1 \#test2 > /dev/null & -PID4=$! -wait $PID -sleep 1 -kill $PID1 $PID2 $PID3 -sleep 0.3 -kill $PID4 - -diff ref_message heard_message && diff ref_command heard_command \ - && diff ref_nothing heard_nothing - diff --git a/test/filterprune.sh b/test/filterprune.sh @@ -1,20 +0,0 @@ -#!/bin/bash - -trap 'kill $(jobs -p)' EXIT - -seq 3 | sed 's/^/good/' > ref -cat fifo | ../irctk -F in@localhost \#test > heard & -PID=$! -sleep 1 -cat > input <<EOF -blah - in:good1 - in2: bleh -in good2 -i nblah - in, good3 -EOF -../irctk out@localhost \#test < input -sleep 1 -kill $PID -diff ref heard diff --git a/test/first.sh b/test/first.sh @@ -2,11 +2,14 @@ trap 'kill $(jobs -p)' EXIT -seq 3 | sed 's/^/[#testa] <out> /' > ref -cat fifo | ../irctk in@localhost \#testa \#testb > heard & +mkdir -p first +cd first + +seq 3 | sed 's/^/[#first_testa] <firsto> /' > ref +tail -f /dev/null | ../../irctk firsti@localhost \#first_testa \#first_testb > heard & PID=$! sleep 1 -seq 3 | ../irctk out@localhost -0 \#testa \#testb +seq 3 | ../../irctk firsto@localhost -0 \#first_testa \#first_testb sleep 1 kill $PID diff ref heard diff --git a/test/fnick.sh b/test/fnick.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +trap 'kill $(jobs -p)' EXIT + +mkdir -p fnick +cd fnick + +seq 3 | sed 's/^/[#fnick_test] <fnicko> /' > ref +tail -f /dev/null | ../../irctk fnicki@localhost \#fnick_test > heard & +PID=$! +sleep 1 +if ../../irctk -N fnicki@localhost \#fnick_test 2>error >/dev/null +then + echo fail + exit 1 +fi +sleep 1 +kill $PID +grep "in use" error > /dev/null diff --git a/test/force-nick.sh b/test/force-nick.sh @@ -1,16 +0,0 @@ -#!/bin/bash - -trap 'kill $(jobs -p)' EXIT - -seq 3 | sed 's/^/[#test] <out> /' > ref -cat fifo | ../irctk in@localhost \#test > heard & -PID=$! -sleep 1 -if ../irctk -N in@localhost \#test 2>error >/dev/null -then - echo fail - exit 1 -fi -sleep 1 -kill $PID -grep "in use" error > /dev/null diff --git a/test/fprune.sh b/test/fprune.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +trap 'kill $(jobs -p)' EXIT + +mkdir -p fprune +cd fprune +mkfifo fifo 2> /dev/null + +seq 3 | sed 's/^/good/' > ref +cat fifo | ../../irctk -F fprunei@localhost \#fprune_test > heard & +PID=$! +sleep 1 +cat > input <<EOF +blah + fprunei:good1 + fprunei2: bleh +fprunei good2 +fprune_i nblah + fprunei, good3 +EOF +../../irctk fpruneo@localhost \#fprune_test < input +sleep 1 +kill $PID +diff ref heard diff --git a/test/host.sh b/test/host.sh @@ -2,11 +2,14 @@ trap 'kill $(jobs -p)' EXIT -seq 3 | sed 's/^/[#test] <out!~username@localhost> /' > ref -cat fifo | ../irctk -w in@localhost \#test > heard & +mkdir -p host +cd host + +seq 3 | sed 's/^/[#host_test] <hosto!~username@localhost> /' > ref +tail -f /dev/null | ../../irctk -w hosti@localhost \#host_test > heard & PID=$! sleep 1 -seq 3 | ../irctk -U "username" -o out@localhost \#test > /dev/null +seq 3 | ../../irctk -U "username" -o hosto@localhost \#host_test > /dev/null sleep 1 kill $PID diff ref heard diff --git a/test/last-posted.sh b/test/last-posted.sh @@ -1,28 +0,0 @@ -#!/bin/bash - -trap 'kill $(jobs -p)' EXIT - -cat > say <<EOF -[#testa] 1 -[#testa] 2 -[#testb] 3 -[#testb] 4 -[#testc] 5 -[#testa] 6 -[#testa] 7 -EOF -cat say | sed 's/]/] <out>/' > ref -cat fifo | ../irctk in@localhost \#testa \#testb \#testc > heard & -PID=$! -sleep 1 -awk '{if ($1 == l) {print $2} else {print $0}} {l = $1}' say | tee said | - ../irctk out@localhost -p \#testa \#testb \#testc -sleep 1 -kill $PID -for chan in testa testb testc -do - if diff <(grep $chan ref) <(grep $chan heard) - then - exec diff <(grep $chan ref) <(grep $chan heard) - fi -done diff --git a/test/lpost.sh b/test/lpost.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +trap 'kill $(jobs -p)' EXIT + +mkdir -p lpost +cd lpost + +cat > say <<EOF +[#lpost_testa] 1 +[#lpost_testa] 2 +[#lpost_testb] 3 +[#lpost_testb] 4 +[#lpost_testc] 5 +[#lpost_testa] 6 +[#lpost_testa] 7 +EOF +cat say | sed 's/]/] <lposto>/' > ref +tail -f /dev/null | + ../../irctk lposti@localhost \#lpost_testa \#lpost_testb \ + \#lpost_testc > heard & +PID=$! +sleep 1 +awk '{if ($1 == l) {print $2} else {print $0}} {l = $1}' say | tee said | + ../../irctk lposto@localhost -p \#lpost_testa \#lpost_testb \ + \#lpost_testc +sleep 1 +kill $PID +for chan in testa testb testc +do + if diff <(grep lpost_$chan ref) <(grep lpost_$chan heard) + then + exec diff <(grep lpost_$chan ref) <(grep lpost_$chan heard) + fi +done diff --git a/test/nick.sh b/test/nick.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +trap 'kill $(jobs -p)' EXIT + +mkdir -p nick +cd nick +mkfifo fifo{1,2,3} 2>/dev/null + +seq 3 | sed 's/^/[#nick_testb] <nickin__> /' > ref +cat fifo1 | ../../irctk nickin@localhost \#nick_testb > heard1 & +PID1=$! +sleep 1 +cat fifo2 | ../../irctk nickin@localhost > heard2 2>error2 & +PID2=$! +sleep 1 +cat fifo3| ../../irctk nickout@localhost \#nick_test > heard3 2>error3 & +PID3=$! +sleep 1 +seq 3 | ../../irctk -o nickin@localhost \#nick_testb > heard4 2>error4 +sleep 1 +kill $PID1 $PID2 $PID3 +diff ref heard1 && diff ref heard4 \ + && grep -q taken error2 \ + && grep -q taken error4 diff --git a/test/order1.sh b/test/order1.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +trap 'kill $(jobs -p)' EXIT + +mkdir -p order1 +cd order1 + +cat >tosay <<EOF +[#order1_test2] a +[#order1_test2] b +[#order1_test1,#order1_test2] c +EOF +cat > ref_message <<EOF +[#order1_test2] <order1o> a +[#order1_test2] <order1o> b +EOF + +(sleep 5; cat tosay) | + ../../irctk order1o@localhost \#order1_test1 \#order1_test2 2>/dev/null > /dev/null& +sleep 1 +PID=$! +tail -f /dev/null | ../../irctk order1m@localhost \#order1_test2 \#order1_test2 > heard_message & +PID1=$! +sleep 0.3 +wait $PID +sleep 1 +kill $PID1 + +diff ref_message <(head -2 heard_message) + diff --git a/test/order2.sh b/test/order2.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +trap 'kill $(jobs -p)' EXIT + +mkdir -p order2 +cd order2 + +cat >tosay <<EOF +[#order2_test1] a +[#order2_test1] b +[#order2_test1,#order2_test2] c +[#order2_test2,#order2_test1] d +[#order2_test1] e +[#order2_test2] e +[#order2_test2] f +[#order2_test1] f +[#order2_test1] g +[#order2_test3] a +[#order2_test1,#order2_test3] h +[#order2_test1] i +[#order2_test2] g +[#order2_test2] h +[#order2_test2] i +[#order2_test2] j +[#order2_test3] i +[#order2_test1,#order2_test2,#order2_test3] k +[#order2_test1] l +[#order2_test3,#order2_test2] l +[#order2_test1,#order2_test2,#order2_test3] m +EOF + +(sleep 4; cat tosay | + ../../irctk -I 15 order2o@localhost \#order2_test1 \#order2_test2 \#order2_test3 2>/dev/null \ + > /dev/null) & +sleep 1 +PID=$! +tail -f /dev/null | + ../../irctk order2m@localhost \#order2_test1 \#order2_test2 \#order2_test3 > heard_message & +PID1=$! +sleep 0.3 +wait $PID +sleep 1 +kill $PID1 + +diff <(sed 's/^[^,]*,[^,]*$/&\n&/' tosay | + sed 's/^[^,]*,[^,]*,[^,]*$/&\n&\n&/' | + cut -f2 -d' ' | sort) <(cut -f3 -d' ' heard_message) + diff --git a/test/order3.sh b/test/order3.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +trap 'kill $(jobs -p)' EXIT + +mkdir -p order3 +cd order3 + +cat >tosay <<EOF +[#order3_test1] a +[#order3_test1] b +[#order3_test1,#order3_test2] c +[#order3_test2,#order3_test1] d +[#order3_test1] e +[#order3_test2] e +[#order3_test3] a +EOF + +(sleep 4; cat tosay | +../../irctk -I 3 order3o@localhost \#order3_test1 \#order3_test2 \#order3_test3 > /dev/null)& +sleep 1 +PID=$! +tail -f /dev/null | + ../../irctk order3m@localhost \#order3_test1 \#order3_test2 \ + \#order3_test3 > heard_message & +PID1=$! +sleep 0.3 +wait $PID +sleep 1 +kill $PID1 + +diff <(sed 's/^[^,]*,[^,]*$/&\n&/' tosay | + sed 's/^[^,]*,[^,]*,[^,]*$/&\n&\n&/' | + cut -f2 -d' ' | sort) <(cut -f3 -d' ' heard_message) + diff --git a/test/order_1.sh b/test/order_1.sh @@ -1,27 +0,0 @@ -#!/bin/bash - -trap 'kill $(jobs -p)' EXIT - -cat >tosay <<EOF -[#test2] a -[#test2] b -[#test1,#test2] c -EOF -cat > ref_message <<EOF -[#test2] <op> a -[#test2] <op> b -EOF - -(sleep 5; cat tosay) | - ../irctk op@localhost \#test1 \#test2 2>/dev/null > /dev/null& -sleep 1 -PID=$! -cat fifo1 | ../irctk message@localhost \#test1 \#test2 > heard_message & -PID1=$! -sleep 0.3 -wait $PID -sleep 1 -kill $PID1 - -diff ref_message <(head -2 heard_message) - diff --git a/test/order_2.sh b/test/order_2.sh @@ -1,45 +0,0 @@ -#!/bin/bash - -trap 'kill $(jobs -p)' EXIT - -cat >tosay <<EOF -[#test1] a -[#test1] b -[#test1,#test2] c -[#test2,#test1] d -[#test1] e -[#test2] e -[#test2] f -[#test1] f -[#test1] g -[#test3] a -[#test1,#test3] h -[#test1] i -[#test2] g -[#test2] h -[#test2] i -[#test2] j -[#test3] i -[#test1,#test2,#test3] k -[#test1] l -[#test3,#test2] l -[#test1,#test2,#test3] m -EOF - -(sleep 4; cat tosay | - ../irctk -I 15 op@localhost \#test1 \#test2 \#test3 2>/dev/null \ - > /dev/null) & -sleep 1 -PID=$! -cat fifo1 | - ../irctk message@localhost \#test1 \#test2 \#test3 > heard_message & -PID1=$! -sleep 0.3 -wait $PID -sleep 1 -kill $PID1 - -diff <(sed 's/^[^,]*,[^,]*$/&\n&/' tosay | - sed 's/^[^,]*,[^,]*,[^,]*$/&\n&\n&/' | - cut -f2 -d' ' | sort) <(cut -f3 -d' ' heard_message) - diff --git a/test/order_3.sh b/test/order_3.sh @@ -1,30 +0,0 @@ -#!/bin/bash - -trap 'kill $(jobs -p)' EXIT - -cat >tosay <<EOF -[#test1] a -[#test1] b -[#test1,#test2] c -[#test2,#test1] d -[#test1] e -[#test2] e -[#test3] a -EOF - -(sleep 4; cat tosay | -../irctk -I 3 op@localhost \#test1 \#test2 \#test3 > /dev/null)& -sleep 1 -PID=$! -cat fifo1 | - ../irctk message@localhost \#test1 \#test2 \#test3 > heard_message & -PID1=$! -sleep 0.3 -wait $PID -sleep 1 -kill $PID1 - -diff <(sed 's/^[^,]*,[^,]*$/&\n&/' tosay | - sed 's/^[^,]*,[^,]*,[^,]*$/&\n&\n&/' | - cut -f2 -d' ' | sort) <(cut -f3 -d' ' heard_message) - diff --git a/test/own.sh b/test/own.sh @@ -2,11 +2,14 @@ trap 'kill $(jobs -p)' EXIT -seq 3 | sed 's/^/[#test] <out> /' > ref -cat fifo | ../irctk in@localhost \#test > heard & +mkdir -p own +cd own + +seq 3 | sed 's/^/[#own_test] <owno> /' > ref +tail -f /dev/null | ../../irctk owni@localhost \#own_test > heard & PID=$! sleep 1 -seq 3 | ../irctk -o out@localhost \#test > heard2 +seq 3 | ../../irctk -o owno@localhost \#own_test > heard2 sleep 1 kill $PID diff ref heard && diff ref heard2 diff --git a/test/password.sh b/test/password.sh @@ -2,12 +2,15 @@ trap 'kill $(jobs -p)' EXIT +mkdir -p password +cd password + (echo -e "/mode +n\n/mode +k hunter2"; tail -f /dev/null) | - ../irctk op@localhost \#test:useless > heard & + ../../irctk passwordo@localhost \#password_test:useless > heard & PID=$! sleep 2 -echo ok | ../irctk ok@localhost \#test:hunter2 2>/dev/null >/dev/null -echo ko | ../irctk ko@localhost \#test:hunter3 2>/dev/null >/dev/null +echo ok | ../../irctk passwordy@localhost \#password_test:hunter2 2>/dev/null >/dev/null +echo ko | ../../irctk passwordn@localhost \#password_test:hunter3 2>/dev/null >/dev/null sleep 2 kill $PID grep "ok" heard > /dev/null && grep -v "ko" heard > /dev/null diff --git a/test/simple.sh b/test/simple.sh @@ -2,11 +2,14 @@ trap 'kill $(jobs -p)' EXIT -seq 3 | sed 's/^/[#test] <out> /' > ref -cat fifo | ../irctk in@localhost \#test > heard & +mkdir -p simple +cd simple + +seq 3 | sed 's/^/[#simple_test] <simpleo> /' > ref +tail -f /dev/null | ../../irctk simplei@localhost \#simple_test > heard & PID=$! sleep 1 -seq 3 | ../irctk out@localhost \#test +seq 3 | ../../irctk simpleo@localhost \#simple_test sleep 1 kill $PID diff ref heard diff --git a/test/sync.sh b/test/sync.sh @@ -2,27 +2,30 @@ trap 'kill $(jobs -p)' EXIT +mkdir -p sync +cd sync + cat >tosay <<EOF -/join #test2 -[#test1] /nick op2 +/join #sync_test2 +[#sync_test1] /nick syncop2 /mode +n /mode -n /part -[#test1,#test2] /topic mytopic -[#test2] /invite command -[#test2] /kick command kickarg +[#sync_test1,#sync_test2] /topic mytopic +[#sync_test2] /invite syncc +[#sync_test2] /kick syncc kickarg /say hello / /hello2 /quit quitarg EOF -(sleep 3; cat tosay) | ../irctk -p op@localhost \#test1 \#test2 2>/dev/null & +(sleep 3; cat tosay) | ../irctk -p syncop@localhost \#sync_test1 \#sync_test2 2>/dev/null & sleep 1 PID=$! -cat fifo1 | ../irctk -m message@localhost \#test1 \#test2 > heard_message & +tail -f /dev/null | ../../irctk -m syncm@localhost \#sync_test1 \#sync_test2 > heard_message & PID1=$! -cat fifo2 | ../irctk -c command@localhost \#test1 \#test2 > heard_command & +tail -f /dev/null | ../../irctk -c syncc@localhost \#sync_test1 \#sync_test2 > heard_command & PID2=$! -cat fifo3 | ../irctk -n nothing@localhost \#test1 \#test2 > heard_nothing & +tail -f /dev/null | ../../irctk -n syncn@localhost \#sync_test1 \#sync_test2 > heard_nothing & PID3=$! wait $PID sleep 1 diff --git a/tests.sh b/tests.sh @@ -1,12 +0,0 @@ -#!/bin/bash - -cd test -# create fifos, ignore error if they already exist -mkfifo fifo fifo1 fifo2 fifo3 2> /dev/null -for t in *.sh -do - echo -n "$t... " - ./$t || { echo "FAILED!"; exit 1; } - echo "passed." -done - diff --git a/tests_parallel.sh b/tests_parallel.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +ls test/*.sh | cut -d/ -f2 | parallel ./runtest.sh + diff --git a/tests_sequential.sh b/tests_sequential.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +cd test +for t in *.sh +do + echo -n "$t... " + #./$t || { echo "FAILED!"; exit 1; } + ./$t || echo "FAILED!" + echo "passed." +done +