From f6f360b9dcfe3f0bc10add17fdf56c5de0c94e30 Mon Sep 17 00:00:00 2001 From: Axel Kittenberger Date: Wed, 4 Jan 2017 12:32:10 +0100 Subject: [PATCH] fixing test --- tests/exclude-rsyncssh.lua | 119 ++++++++++++++++++++----------------- 1 file changed, 66 insertions(+), 53 deletions(-) diff --git a/tests/exclude-rsyncssh.lua b/tests/exclude-rsyncssh.lua index e49cd68..e1c6b1c 100755 --- a/tests/exclude-rsyncssh.lua +++ b/tests/exclude-rsyncssh.lua @@ -37,64 +37,77 @@ sync { }]]); -- writes all files -local function writefiles() - posix.mkdir(srcdir .. 'd'); - writefile(srcdir .. 'erf', 'erf'); - writefile(srcdir .. 'eaf', 'erf'); - writefile(srcdir .. 'erd', 'erd'); - writefile(srcdir .. 'ead', 'ead'); - writefile(srcdir .. 'd/erf', 'erf'); - writefile(srcdir .. 'd/eaf', 'erf'); - writefile(srcdir .. 'd/erd', 'erd'); - writefile(srcdir .. 'd/ead', 'ead'); +local function writefiles +( ) + posix.mkdir( srcdir .. 'd' ) + writefile( srcdir .. 'erf', 'erf' ) + writefile( srcdir .. 'eaf', 'erf' ) + writefile( srcdir .. 'erd', 'erd' ) + writefile( srcdir .. 'ead', 'ead' ) + writefile( srcdir .. 'd/erf', 'erf' ) + writefile( srcdir .. 'd/eaf', 'erf' ) + writefile( srcdir .. 'd/erd', 'erd' ) + writefile( srcdir .. 'd/ead', 'ead' ) end -- test if the filename exists, fails if this is different to expect -local function testfile(filename, expect) - local stat, err = posix.stat(filename) - if stat and not expect then - cwriteln('failure: ',filename,' should be excluded'); - os.exit(1); +local function testfile +( + filename, + expect +) + local stat, err = posix.stat( filename ) + + if stat and not expect + then + cwriteln( 'failure: ',filename,' should be excluded' ); + os.exit( 1 ); end - if not stat and expect then - cwriteln('failure: ',filename,' should not be excluded'); - os.exit(1); + + if not stat and expect + then + cwriteln( 'failure: ',filename,' should not be excluded' ); + os.exit( 1 ); end end -- test all files -local function testfiles() - testfile( trgdir .. 'erf', false ); - testfile( trgdir .. 'eaf', false ); - testfile( trgdir .. 'erd', true ); - testfile( trgdir .. 'ead', true ); - testfile( trgdir .. 'd/erf', false ); - testfile( trgdir .. 'd/eaf', true ); - testfile( trgdir .. 'd/erd', true ); - testfile( trgdir .. 'd/ead', true ); +local function testfiles +( ) + testfile( trgdir .. 'erf', false ) + testfile( trgdir .. 'eaf', false ) + testfile( trgdir .. 'erd', true ) + testfile( trgdir .. 'ead', true ) + testfile( trgdir .. 'd/erf', false ) + testfile( trgdir .. 'd/eaf', true ) + testfile( trgdir .. 'd/erd', true ) + testfile( trgdir .. 'd/ead', true ) end -cwriteln('testing startup excludes'); -writefiles(); -cwriteln('starting Lsyncd'); -local pid = spawn('./lsyncd', cfgfile, unpack(log)); -cwriteln('waiting for Lsyncd to start'); -posix.sleep(10) -cwriteln('testing excludes after startup'); -testfiles(); -cwriteln('ok, removing sources'); -if srcdir:sub(1,4) ~= '/tmp' then +cwriteln( 'testing startup excludes' ) +writefiles( ) +cwriteln( 'starting Lsyncd' ) +local pid = spawn( './lsyncd', cfgfile, unpack( log ) ) +cwriteln( 'waiting for Lsyncd to start' ) +posix.sleep( 10 ) +cwriteln( 'testing excludes after startup' ) +testfiles( ) +cwriteln( 'ok, removing sources' ) + +if srcdir:sub(1,4) ~= '/tmp' +then -- just to make sure before rm -rf - cwriteln('exist before drama, srcdir is "', srcdir, '"'); - os.exit(1); + cwriteln('exit before drama, srcdir is "', srcdir, '"') + + os.exit( 1 ) end -os.execute( 'rm -rf ' .. srcdir .. '/*' ); -cwriteln( 'waiting for Lsyncd to remove destination' ); -posix.sleep( 5 ); +os.execute( 'rm -rf ' .. srcdir .. '/*' ) +cwriteln( 'waiting for Lsyncd to remove destination' ) +posix.sleep( 5 ) -_, result, code = os.execute('diff -urN '..srcdir..' '..trgdir) ~= 0 +_, result, code = os.execute( 'diff -urN '..srcdir..' '..trgdir ) if result ~= 'exit' or code ~= 0 then @@ -102,17 +115,17 @@ then os.exit( 1 ); end -cwriteln( 'writing files after startup' ); -writefiles( ); -cwriteln( 'waiting for Lsyncd to transmit changes' ); -posix.sleep( 15 ); -testfiles( ); +cwriteln( 'writing files after startup' ) +writefiles( ) +cwriteln( 'waiting for Lsyncd to transmit changes' ) +posix.sleep( 15 ) +testfiles( ) -cwriteln( 'killing started Lsyncd' ); -posix.kill( pid ); -local _, exitmsg, lexitcode = posix.wait( lpid ); -cwriteln( 'Exitcode of Lsyncd = ', exitmsg, ' ', lexitcode ); -posix.sleep( 1 ); +cwriteln( 'killing started Lsyncd' ) +posix.kill( pid ) +local _, exitmsg, lexitcode = posix.wait( lpid ) +cwriteln( 'Exitcode of Lsyncd = ', exitmsg, ' ', lexitcode ) +posix.sleep( 1 ) if lexitcode == 143 then