[patch] 7.3: use xxd instead of gzip in test 11

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[patch] 7.3: use xxd instead of gzip in test 11

Ralf Schandl-3
Hi,

test11 uses gzip to test the autocmds FileReadPre/Post and
FileWritePre/Post. Gzip might not be available on all platforms, so I
switched to xxd to do the tests.

Attached patch is test11 using xxd instead of gzip.

- Ralf

--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

diff -r f5bd6753cdc4 src/testdir/test11.in
--- a/src/testdir/test11.in Fri May 28 22:06:46 2010 +0200
+++ b/src/testdir/test11.in Sat May 29 13:12:51 2010 +0200
@@ -1,28 +1,29 @@
 Tests for autocommands:
-- FileWritePre writing a compressed file
-- FileReadPost reading a compressed file
+- FileWritePre writing as hexdump (using xxd)
+- FileReadPost reading from hexdump (using xxd -r)
 - BufNewFile reading a file template
-- BufReadPre decompressing the file to be read
+- BufReadPre un-hexdump the file to be read
 - FilterReadPre substituting characters in the temp file
 - FilterReadPost substituting characters after filtering
-- FileReadPre set options for decompression
-- FileReadPost decompress the file
+- FileReadPre un-hexdump file before read
+- FileReadPost un-hexdump file after read
 
-Note: This test will fail if "gzip" is not available.
-$GZIP is made empty, "-v" would cause trouble.
-Use a FileChangedShell autocommand to avoid a prompt for "Xtestfile.gz" being
+Use a FileChangedShell autocommand to avoid a prompt for "Xtestfile.hd" being
 modified outside of Vim (noticed on Solaris).
 
 STARTTEST
 :so small.vim
-:let $GZIP = ""
 :au FileChangedShell * echo "caught FileChangedShell"
 :set bin
-:au FileWritePre    *.gz   '[,']!gzip
-:au FileWritePost   *.gz   undo
-:/^start of testfile/,/^end of testfile/w! Xtestfile.gz
-:au FileReadPost    *.gz   '[,']!gzip -d
-:$r Xtestfile.gz                " Read and decompress the testfile
+:au FileWritePre    *.hd   '[,']!xxd
+:au FileWritePost   *.hd   undo
+:/^start of testfile/,/^end of testfile/w! Xtestfile.hd
+:$r Xtestfile.hd                " Read hexdump and keep one line
+:/^0000010:/,$d
+:/^0000000:/s/\r$//             " remove CR from xxd (if any)
+:/^0000000:/s/ \x[0-9a-f ]*/ -- /     " remove hex codes (ascii/ebcdic-problem)
+:au FileReadPost    *.hd   '[,']!xxd -r
+:$r Xtestfile.hd                " Read hexdump and un-xxd
 :?startstart?,$w! test.out      " Write contents of this file
 :au BufNewFile      *.c    read Xtest.c
 :/^start of test.c/+1,/^end of test.c/-1w! Xtest.c
@@ -32,11 +33,11 @@
 :w>>test.out                    " Append it to the output file
 :au! FileAppendPre
 :" setup autocommands to decompress before reading and re-compress afterwards
-:au BufReadPre      *.gz   exe '!gzip -d ' . shellescape(expand("<afile>"))
-:au BufReadPre      *.gz   call rename(expand("<afile>:r"), expand("<afile>"))
-:au BufReadPost     *.gz   call rename(expand("<afile>"), expand("<afile>:r"))
-:au BufReadPost     *.gz   exe '!gzip ' . shellescape(expand("<afile>:r"))
-:e! Xtestfile.gz                " Edit compressed file
+:au BufReadPre      *.hd   exe '!xxd -r ' . shellescape(expand("<afile>")) . '>' . expand("<afile>:r")
+:au BufReadPre      *.hd   call rename(expand("<afile>:r"), expand("<afile>"))
+:au BufReadPost     *.hd   call rename(expand("<afile>"), expand("<afile>:r"))
+:au BufReadPost     *.hd   exe '!xxd ' . shellescape(expand("<afile>:r")) . '>' . expand("<afile>")
+:e! Xtestfile.hd                " Edit compressed file
 :w>>test.out                    " Append it to the output file
 :set shelltemp                  " need temp files here
 :au FilterReadPre   *.out  call rename(expand("<afile>"), expand("<afile>") . ".t")
@@ -44,14 +45,14 @@
 :au FilterReadPre   *.out  exe '!rm ' . shellescape(expand("<afile>")) . '.t'
 :au FilterReadPost  *.out  '[,']s/x/X/g
 :e! test.out                    " Edit the output file
-:23,$!cat
-:23,$s/\r$//                 " remove CR for when sed adds them
-:au! FileReadPre    *.gz   exe '!gzip -d ' . shellescape(expand("<afile>"))
-:au  FileReadPre    *.gz   call rename(expand("<afile>:r"), expand("<afile>"))
-:au! FileReadPost   *.gz   '[,']s/l/L/
-:$r Xtestfile.gz             " Read compressed file
+:24,$!cat
+:24,$s/\r$//                 " remove CR for when sed adds them
+:au! FileReadPre    *.hd   exe '!xxd -r ' . shellescape(expand("<afile>")) . '>' . expand("<afile>:r")
+:au  FileReadPre    *.hd   call rename(expand("<afile>:r"), expand("<afile>"))
+:au! FileReadPost   *.hd   '[,']s/l/L/
+:$r Xtestfile.hd             " Read compressed file
 :w                           " write it, after filtering
-:au!             " remove all autocommands
+:au!
 :e               " Edit test.out again
 :set nobin ff&   " use the default fileformat for writing
 :w
diff -r f5bd6753cdc4 src/testdir/test11.ok
--- a/src/testdir/test11.ok Fri May 28 22:06:46 2010 +0200
+++ b/src/testdir/test11.ok Sat May 29 13:12:51 2010 +0200
@@ -16,6 +16,7 @@
  * Here is a new .c file
  */
 end of test.c
+0000000: -- start of testfil
 start of testfile
 line 2 Abcdefghijklmnopqrstuvwxyz
 line 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Reply | Threaded
Open this post in threaded view
|

Re: [patch] 7.3: use xxd instead of gzip in test 11

Bram Moolenaar

Ralf Schandl wrote:

> test11 uses gzip to test the autocmds FileReadPre/Post and
> FileWritePre/Post. Gzip might not be available on all platforms, so I
> switched to xxd to do the tests.
>
> Attached patch is test11 using xxd instead of gzip.

I suspect many systems won't have "xxd" installed when building/testing
Vim, before installing.  That could be fixed by using a path for xxd.
But what path?  It would have to be passed in from the Makefile.
That's not going to make it simpler...

--
"A clear conscience is usually the sign of a bad memory."
                             -- Steven Wright

 /// Bram Moolenaar -- [hidden email] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\        download, build and distribute -- http://www.A-A-P.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|

Re: [patch] 7.3: use xxd instead of gzip in test 11

Ralf Schandl-3

Bram Moolenaar wrote:

> Ralf Schandl wrote:
>
>> test11 uses gzip to test the autocmds FileReadPre/Post and
>> FileWritePre/Post. Gzip might not be available on all platforms, so I
>> switched to xxd to do the tests.
>>
>> Attached patch is test11 using xxd instead of gzip.
>
> I suspect many systems won't have "xxd" installed when building/testing
> Vim, before installing.  That could be fixed by using a path for xxd.
> But what path?  It would have to be passed in from the Makefile.
> That's not going to make it simpler...
>

Hmm -- possible solution:

STARTTEST
:if(has("win16") || has("win32") || has("win64"))
:let XXD="..\xxd\xxd"
:else
:let XXD="../xxd/xxd"
:endif
...
:exe("au FileWritePre    *.hd   '[,']!" . XXD )


I don't know if this is worth it ...

- Ralf

--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|

Re: [patch] 7.3: use xxd instead of gzip in test 11

Tony Mechelynck
In reply to this post by Bram Moolenaar
On 29/05/10 15:13, Bram Moolenaar wrote:

>
> Ralf Schandl wrote:
>
>> test11 uses gzip to test the autocmds FileReadPre/Post and
>> FileWritePre/Post. Gzip might not be available on all platforms, so I
>> switched to xxd to do the tests.
>>
>> Attached patch is test11 using xxd instead of gzip.
>
> I suspect many systems won't have "xxd" installed when building/testing
> Vim, before installing.  That could be fixed by using a path for xxd.
> But what path?  It would have to be passed in from the Makefile.
> That's not going to make it simpler...
>

The tests should be run after compiling Vim, of course, and a full
compile builds xxd/xxd in addition to Vim. So (assuming the testdir to
be the current directory) there should be an executable named ../xxd/xxd
in most cases.

Since "xxd --version" is a valid command, we could try that for any
possible locations of the executable, starting at ../xxd/xxd relative to
the testdir, and then use the first one which returns a zero exit status
($? on Unix or ERRORLEVEL on Windows).

Best regards,
Tony.
--
The chief danger in life is that you may take too may precautions.
                -- Alfred Adler

--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|

Re: [patch] 7.3: use xxd instead of gzip in test 11

Ralf Schandl-3


Tony Mechelynck wrote:

> On 29/05/10 15:13, Bram Moolenaar wrote:
>>
>> Ralf Schandl wrote:
>>
>>> test11 uses gzip to test the autocmds FileReadPre/Post and
>>> FileWritePre/Post. Gzip might not be available on all platforms, so I
>>> switched to xxd to do the tests.
>>>
>>> Attached patch is test11 using xxd instead of gzip.
>>
>> I suspect many systems won't have "xxd" installed when building/testing
>> Vim, before installing.  That could be fixed by using a path for xxd.
>> But what path?  It would have to be passed in from the Makefile.
>> That's not going to make it simpler...
>>
>
> The tests should be run after compiling Vim, of course, and a full
> compile builds xxd/xxd in addition to Vim. So (assuming the testdir to
> be the current directory) there should be an executable named ../xxd/xxd
> in most cases.
>
> Since "xxd --version" is a valid command, we could try that for any
> possible locations of the executable, starting at ../xxd/xxd relative to
> the testdir, and then use the first one which returns a zero exit status
> ($? on Unix or ERRORLEVEL on Windows).
>
> Best regards,
> Tony.

See my mail from yesterday 17:54. This shows how it would work for win
and unix using ..\xxd\xxd and ../xxd/xxd. I don't know the path
separators for all the other OSes supported by vim. Is there support in
VimL for this? I haven't found it.

If we want this test to be really OS-independent, we would also have to
replace sed and rm in the test.

If this is wanted, I'll again invest some time in this.

- Ralf

--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php