annotate src/testdir/test_xxd.vim @ 32936:c517845bd10e v9.0.1776

patch 9.0.1776: No support for stable Python 3 ABI Commit: https://github.com/vim/vim/commit/c13b3d1350b60b94fe87f0761ea31c0e7fb6ebf3 Author: Yee Cheng Chin <ychin.git@gmail.com> Date: Sun Aug 20 21:18:38 2023 +0200 patch 9.0.1776: No support for stable Python 3 ABI Problem: No support for stable Python 3 ABI Solution: Support Python 3 stable ABI Commits: 1) Support Python 3 stable ABI to allow mixed version interoperatbility Vim currently supports embedding Python for use with plugins, and the "dynamic" linking option allows the user to specify a locally installed version of Python by setting `pythonthreedll`. However, one caveat is that the Python 3 libs are not binary compatible across minor versions, and mixing versions can potentially be dangerous (e.g. let's say Vim was linked against the Python 3.10 SDK, but the user sets `pythonthreedll` to a 3.11 lib). Usually, nothing bad happens, but in theory this could lead to crashes, memory corruption, and other unpredictable behaviors. It's also difficult for the user to tell something is wrong because Vim has no way of reporting what Python 3 version Vim was linked with. For Vim installed via a package manager, this usually isn't an issue because all the dependencies would already be figured out. For prebuilt Vim binaries like MacVim (my motivation for working on this), AppImage, and Win32 installer this could potentially be an issue as usually a single binary is distributed. This is more tricky when a new Python version is released, as there's a chicken-and-egg issue with deciding what Python version to build against and hard to keep in sync when a new Python version just drops and we have a mix of users of different Python versions, and a user just blindly upgrading to a new Python could lead to bad interactions with Vim. Python 3 does have a solution for this problem: stable ABI / limited API (see https://docs.python.org/3/c-api/stable.html). The C SDK limits the API to a set of functions that are promised to be stable across versions. This pull request adds an ifdef config that allows us to turn it on when building Vim. Vim binaries built with this option should be safe to freely link with any Python 3 libraies without having the constraint of having to use the same minor version. Note: Python 2 has no such concept and this doesn't change how Python 2 integration works (not that there is going to be a new version of Python 2 that would cause compatibility issues in the future anyway). --- Technical details: ====== The stable ABI can be accessed when we compile with the Python 3 limited API (by defining `Py_LIMITED_API`). The Python 3 code (in `if_python3.c` and `if_py_both.h`) would now handle this and switch to limited API mode. Without it set, Vim will still use the full API as before so this is an opt-in change. The main difference is that `PyType_Object` is now an opaque struct that we can't directly create "static types" out of, and we have to create type objects as "heap types" instead. This is because the struct is not stable and changes from version to version (e.g. 3.8 added a `tp_vectorcall` field to it). I had to change all the types to be allocated on the heap instead with just a pointer to them. Other functions are also simply missing in limited API, or they are introduced too late (e.g. `PyUnicode_AsUTF8AndSize` in 3.10) to it that we need some other ways to do the same thing, so I had to abstract a few things into macros, and sometimes re-implement functions like `PyObject_NEW`. One caveat is that in limited API, `OutputType` (used for replacing `sys.stdout`) no longer inherits from `PyStdPrinter_Type` which I don't think has any real issue other than minor differences in how they convert to a string and missing a couple functions like `mode()` and `fileno()`. Also fixed an existing bug where `tp_basicsize` was set incorrectly for `BufferObject`, `TabListObject, `WinListObject`. Technically, there could be a small performance drop, there is a little more indirection with accessing type objects, and some APIs like `PyUnicode_AsUTF8AndSize` are missing, but in practice I didn't see any difference, and any well-written Python plugin should try to avoid excessing callbacks to the `vim` module in Python anyway. I only tested limited API mode down to Python 3.7, which seemes to compile and work fine. I haven't tried earlier Python versions. 2) Fix PyIter_Check on older Python vers / type##Ptr unused warning For PyIter_Check, older versions exposed them as either macros (used in full API), or a function (for use in limited API). A previous change exposed PyIter_Check to the dynamic build because Python just moved it to function-only in 3.10 anyway. Because of that, just make sure we always grab the function in dynamic builds in earlier versions since that's what Python eventually did anyway. 3) Move Py_LIMITED_API define to configure script Can now use --with-python-stable-abi flag to customize what stable ABI version to target. Can also use an env var to do so as well. 4) Show +python/dyn-stable in :version, and allow has() feature query Not sure if the "/dyn-stable" suffix would break things, or whether we should do it another way. Or just don't show it in version and rely on has() feature checking. 5) Documentation first draft. Still need to implement v:python3_version 6) Fix PyIter_Check build breaks when compiling against Python 3.8 7) Add CI coverage stable ABI on Linux/Windows / make configurable on Windows This adds configurable options for Windows make files (both MinGW and MSVC). CI will also now exercise both traditional full API and stable ABI for Linux and Windows in the matrix for coverage. Also added a "dynamic" option to Linux matrix as a drive-by change to make other scripting languages like Ruby / Perl testable under both static and dynamic builds. 8) Fix inaccuracy in Windows docs Python's own docs are confusing but you don't actually want to use `python3.dll` for the dynamic linkage. 9) Add generated autoconf file 10) Add v:python3_version support This variable indicates the version of Python3 that Vim was built against (PY_VERSION_HEX), and will be useful to check whether the Python library you are loading in dynamically actually fits it. When built with stable ABI, it will be the limited ABI version instead (`Py_LIMITED_API`), which indicates the minimum version of Python 3 the user should have, rather than the exact match. When stable ABI is used, we won't be exposing PY_VERSION_HEX in this var because it just doesn't seem necessary to do so (the whole point of stable ABI is the promise that it will work across versions), and I don't want to confuse the user with too many variables. Also, cleaned up some documentation, and added help tags. 11) Fix Python 3.7 compat issues Fix a couple issues when using limited API < 3.8 - Crash on exit: In Python 3.7, if a heap-allocated type is destroyed before all instances are, it would cause a crash later. This happens when we destroyed `OptionsType` before calling `Py_Finalize` when using the limited API. To make it worse, later versions changed the semantics and now each instance has a strong reference to its own type and the recommendation has changed to have each instance de-ref its own type and have its type in GC traversal. To avoid dealing with these cross-version variations, we just don't free the heap type. They are static types in non-limited-API anyway and are designed to last through the entirety of the app, and we also don't restart the Python runtime and therefore do not need it to have absolutely 0 leaks. See: - https://docs.python.org/3/whatsnew/3.8.html#changes-in-the-c-api - https://docs.python.org/3/whatsnew/3.9.html#changes-in-the-c-api - PyIter_Check: This function is not provided in limited APIs older than 3.8. Previously I was trying to mock it out using manual PyType_GetSlot() but it was brittle and also does not actually work properly for static types (it will generate a Python error). Just return false. It does mean using limited API < 3.8 is not recommended as you lose the functionality to handle iterators, but from playing with plugins I couldn't find it to be an issue. - Fix loading of PyIter_Check so it will be done when limited API < 3.8. Otherwise loading a 3.7 Python lib will fail even if limited API was specified to use it. 12) Make sure to only load `PyUnicode_AsUTF8AndSize` in needed in limited API We don't use this function unless limited API >= 3.10, but we were loading it regardless. Usually it's ok in Unix-like systems where Python just has a single lib that we load from, but in Windows where there is a separate python3.dll this would not work as the symbol would not have been exposed in this more limited DLL file. This makes it much clearer under what condition is this function needed. closes: #12032 Signed-off-by: Christian Brabandt <cb@256bit.org> Co-authored-by: Yee Cheng Chin <ychin.git@gmail.com>
author Christian Brabandt <cb@256bit.org>
date Sun, 20 Aug 2023 21:30:04 +0200
parents 5a1113ece237
children 79b2eb83f2df
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13634
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 " Test for the xxd command
21765
08940efa6b4e patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents: 20784
diff changeset
2
13646
86eb21bb5920 patch 8.0.1695: xxd test not run on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13638
diff changeset
3 if empty($XXD) && executable('..\xxd\xxd.exe')
86eb21bb5920 patch 8.0.1695: xxd test not run on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13638
diff changeset
4 let s:xxd_cmd = '..\xxd\xxd.exe'
86eb21bb5920 patch 8.0.1695: xxd test not run on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13638
diff changeset
5 elseif empty($XXD) || !executable($XXD)
17089
8e9e9124c7a2 patch 8.1.1544: some balloon tests don't run when they can
Bram Moolenaar <Bram@vim.org>
parents: 17049
diff changeset
6 throw 'Skipped: xxd program missing'
13646
86eb21bb5920 patch 8.0.1695: xxd test not run on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13638
diff changeset
7 else
86eb21bb5920 patch 8.0.1695: xxd test not run on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13638
diff changeset
8 let s:xxd_cmd = $XXD
13634
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9 endif
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 13963
diff changeset
11 func PrepareBuffer(lines)
13638
b3068807f5df patch 8.0.1691: xxd test sometimes fails
Christian Brabandt <cb@256bit.org>
parents: 13634
diff changeset
12 new
b3068807f5df patch 8.0.1691: xxd test sometimes fails
Christian Brabandt <cb@256bit.org>
parents: 13634
diff changeset
13 call append(0, a:lines)
13634
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14 $d
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 endfunc
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 13963
diff changeset
17 func s:Mess(counter)
13634
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18 return printf("Failed xxd test %d:", a:counter)
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19 endfunc
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 13963
diff changeset
21 func Test_xxd()
13634
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22 call PrepareBuffer(range(1,30))
13646
86eb21bb5920 patch 8.0.1695: xxd test not run on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13638
diff changeset
23 set ff=unix
15627
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
24 w! XXDfile
13638
b3068807f5df patch 8.0.1691: xxd test sometimes fails
Christian Brabandt <cb@256bit.org>
parents: 13634
diff changeset
25
13634
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26 " Test 1: simple, filter the result through xxd
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
27 let s:test = 1
13646
86eb21bb5920 patch 8.0.1695: xxd test not run on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13638
diff changeset
28 exe '%!' . s:xxd_cmd . ' %'
13634
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 let expected = [
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
30 \ '00000000: 310a 320a 330a 340a 350a 360a 370a 380a 1.2.3.4.5.6.7.8.',
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31 \ '00000010: 390a 3130 0a31 310a 3132 0a31 330a 3134 9.10.11.12.13.14',
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32 \ '00000020: 0a31 350a 3136 0a31 370a 3138 0a31 390a .15.16.17.18.19.',
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33 \ '00000030: 3230 0a32 310a 3232 0a32 330a 3234 0a32 20.21.22.23.24.2',
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34 \ '00000040: 350a 3236 0a32 370a 3238 0a32 390a 3330 5.26.27.28.29.30',
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
35 \ '00000050: 0a .']
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
36 call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
13638
b3068807f5df patch 8.0.1691: xxd test sometimes fails
Christian Brabandt <cb@256bit.org>
parents: 13634
diff changeset
37
13634
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
38 " Test 2: reverse the result
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
39 let s:test += 1
13646
86eb21bb5920 patch 8.0.1695: xxd test not run on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13638
diff changeset
40 exe '%!' . s:xxd_cmd . ' -r'
13634
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
41 call assert_equal(map(range(1,30), {v,c -> string(c)}), getline(1,'$'), s:Mess(s:test))
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
42
15627
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
43 " Test 3: Skip the first 0x30 bytes
13634
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
44 let s:test += 1
15627
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
45 for arg in ['-s 0x30', '-s0x30', '-s+0x30', '-skip 0x030', '-seek 0x30', '-seek +0x30 --']
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
46 exe '%!' . s:xxd_cmd . ' ' . arg . ' %'
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
47 call assert_equal(expected[3:], getline(1,'$'), s:Mess(s:test))
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
48 endfor
13634
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
49
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
50 " Test 4: Skip the first 30 bytes
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
51 let s:test += 1
15627
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
52 for arg in ['-s -0x31', '-s-0x31']
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
53 exe '%!' . s:xxd_cmd . ' ' . arg . ' %'
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
54 call assert_equal(expected[2:], getline(1,'$'), s:Mess(s:test))
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
55 endfor
13634
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
56
15647
f7b88b1d3350 patch 8.1.0831: xxd test fails if man page has dos fileformat
Bram Moolenaar <Bram@vim.org>
parents: 15630
diff changeset
57 " The following tests use the xxd man page.
f7b88b1d3350 patch 8.1.0831: xxd test fails if man page has dos fileformat
Bram Moolenaar <Bram@vim.org>
parents: 15630
diff changeset
58 " For these tests to pass, the fileformat must be "unix".
f7b88b1d3350 patch 8.1.0831: xxd test fails if man page has dos fileformat
Bram Moolenaar <Bram@vim.org>
parents: 15630
diff changeset
59 let man_copy = 'Xxd.1'
f7b88b1d3350 patch 8.1.0831: xxd test fails if man page has dos fileformat
Bram Moolenaar <Bram@vim.org>
parents: 15630
diff changeset
60 let man_page = '../../runtime/doc/xxd.1'
f7b88b1d3350 patch 8.1.0831: xxd test fails if man page has dos fileformat
Bram Moolenaar <Bram@vim.org>
parents: 15630
diff changeset
61 if has('win32') && !filereadable(man_page)
f7b88b1d3350 patch 8.1.0831: xxd test fails if man page has dos fileformat
Bram Moolenaar <Bram@vim.org>
parents: 15630
diff changeset
62 let man_page = '../../doc/xxd.1'
f7b88b1d3350 patch 8.1.0831: xxd test fails if man page has dos fileformat
Bram Moolenaar <Bram@vim.org>
parents: 15630
diff changeset
63 endif
f7b88b1d3350 patch 8.1.0831: xxd test fails if man page has dos fileformat
Bram Moolenaar <Bram@vim.org>
parents: 15630
diff changeset
64 %d
f7b88b1d3350 patch 8.1.0831: xxd test fails if man page has dos fileformat
Bram Moolenaar <Bram@vim.org>
parents: 15630
diff changeset
65 exe '0r ' man_page '| set ff=unix | $d | w' man_copy '| bwipe!' man_copy
f7b88b1d3350 patch 8.1.0831: xxd test fails if man page has dos fileformat
Bram Moolenaar <Bram@vim.org>
parents: 15630
diff changeset
66
13634
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
67 " Test 5: Print 120 bytes as continuous hexdump with 20 octets per line
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
68 let s:test += 1
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
69 %d
15647
f7b88b1d3350 patch 8.1.0831: xxd test fails if man page has dos fileformat
Bram Moolenaar <Bram@vim.org>
parents: 15630
diff changeset
70 exe '0r! ' . s:xxd_cmd . ' -l 120 -ps -c20 ' . man_copy
13634
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
71 $d
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
72 let expected = [
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
73 \ '2e54482058584420312022417567757374203139',
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
74 \ '39362220224d616e75616c207061676520666f72',
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
75 \ '20787864220a2e5c220a2e5c222032317374204d',
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
76 \ '617920313939360a2e5c22204d616e2070616765',
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
77 \ '20617574686f723a0a2e5c2220202020546f6e79',
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
78 \ '204e7567656e74203c746f6e79407363746e7567']
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
79 call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
13638
b3068807f5df patch 8.0.1691: xxd test sometimes fails
Christian Brabandt <cb@256bit.org>
parents: 13634
diff changeset
80
13634
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
81 " Test 6: Print the date from xxd.1
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
82 let s:test += 1
15627
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
83 for arg in ['-l 13', '-l13', '-len 13']
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
84 %d
15647
f7b88b1d3350 patch 8.1.0831: xxd test fails if man page has dos fileformat
Bram Moolenaar <Bram@vim.org>
parents: 15630
diff changeset
85 exe '0r! ' . s:xxd_cmd . ' -s 0x36 ' . arg . ' -cols 13 ' . man_copy
15627
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
86 $d
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
87 call assert_equal('00000036: 3231 7374 204d 6179 2031 3939 36 21st May 1996', getline(1), s:Mess(s:test))
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
88 endfor
13638
b3068807f5df patch 8.0.1691: xxd test sometimes fails
Christian Brabandt <cb@256bit.org>
parents: 13634
diff changeset
89
15647
f7b88b1d3350 patch 8.1.0831: xxd test fails if man page has dos fileformat
Bram Moolenaar <Bram@vim.org>
parents: 15630
diff changeset
90 " Cleanup after tests 5 and 6
f7b88b1d3350 patch 8.1.0831: xxd test fails if man page has dos fileformat
Bram Moolenaar <Bram@vim.org>
parents: 15630
diff changeset
91 call delete(man_copy)
f7b88b1d3350 patch 8.1.0831: xxd test fails if man page has dos fileformat
Bram Moolenaar <Bram@vim.org>
parents: 15630
diff changeset
92
13634
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
93 " Test 7: Print C include
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
94 let s:test += 1
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
95 call writefile(['TESTabcd09'], 'XXDfile')
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
96 %d
13646
86eb21bb5920 patch 8.0.1695: xxd test not run on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13638
diff changeset
97 exe '0r! ' . s:xxd_cmd . ' -i XXDfile'
13634
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
98 $d
16720
9c90cf08cfa8 patch 8.1.1362: code and data in tests can be hard to read
Bram Moolenaar <Bram@vim.org>
parents: 15647
diff changeset
99 let expected =<< trim [CODE]
17172
6990c1160ea5 patch 8.1.1585: :let-heredoc does not trim enough
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
100 unsigned char XXDfile[] = {
6990c1160ea5 patch 8.1.1585: :let-heredoc does not trim enough
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
101 0x54, 0x45, 0x53, 0x54, 0x61, 0x62, 0x63, 0x64, 0x30, 0x39, 0x0a
6990c1160ea5 patch 8.1.1585: :let-heredoc does not trim enough
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
102 };
6990c1160ea5 patch 8.1.1585: :let-heredoc does not trim enough
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
103 unsigned int XXDfile_len = 11;
16720
9c90cf08cfa8 patch 8.1.1362: code and data in tests can be hard to read
Bram Moolenaar <Bram@vim.org>
parents: 15647
diff changeset
104 [CODE]
9c90cf08cfa8 patch 8.1.1362: code and data in tests can be hard to read
Bram Moolenaar <Bram@vim.org>
parents: 15647
diff changeset
105
13634
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
106 call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
13638
b3068807f5df patch 8.0.1691: xxd test sometimes fails
Christian Brabandt <cb@256bit.org>
parents: 13634
diff changeset
107
13634
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
108 " Test 8: Print C include capitalized
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
109 let s:test += 1
15627
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
110 for arg in ['-C', '-capitalize']
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
111 call writefile(['TESTabcd09'], 'XXDfile')
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
112 %d
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
113 exe '0r! ' . s:xxd_cmd . ' -i ' . arg . ' XXDfile'
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
114 $d
16720
9c90cf08cfa8 patch 8.1.1362: code and data in tests can be hard to read
Bram Moolenaar <Bram@vim.org>
parents: 15647
diff changeset
115 let expected =<< trim [CODE]
17172
6990c1160ea5 patch 8.1.1585: :let-heredoc does not trim enough
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
116 unsigned char XXDFILE[] = {
6990c1160ea5 patch 8.1.1585: :let-heredoc does not trim enough
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
117 0x54, 0x45, 0x53, 0x54, 0x61, 0x62, 0x63, 0x64, 0x30, 0x39, 0x0a
6990c1160ea5 patch 8.1.1585: :let-heredoc does not trim enough
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
118 };
6990c1160ea5 patch 8.1.1585: :let-heredoc does not trim enough
Bram Moolenaar <Bram@vim.org>
parents: 17089
diff changeset
119 unsigned int XXDFILE_LEN = 11;
16720
9c90cf08cfa8 patch 8.1.1362: code and data in tests can be hard to read
Bram Moolenaar <Bram@vim.org>
parents: 15647
diff changeset
120 [CODE]
15627
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
121 call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
122 endfor
13638
b3068807f5df patch 8.0.1691: xxd test sometimes fails
Christian Brabandt <cb@256bit.org>
parents: 13634
diff changeset
123
b3068807f5df patch 8.0.1691: xxd test sometimes fails
Christian Brabandt <cb@256bit.org>
parents: 13634
diff changeset
124 " Test 9: Create a file with containing a single 'A'
13634
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
125 let s:test += 1
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
126 call delete('XXDfile')
13638
b3068807f5df patch 8.0.1691: xxd test sometimes fails
Christian Brabandt <cb@256bit.org>
parents: 13634
diff changeset
127 bwipe! XXDfile
13646
86eb21bb5920 patch 8.0.1695: xxd test not run on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13638
diff changeset
128 if has('unix')
86eb21bb5920 patch 8.0.1695: xxd test not run on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13638
diff changeset
129 call system('echo "010000: 41"|' . s:xxd_cmd . ' -r -s -0x10000 > XXDfile')
86eb21bb5920 patch 8.0.1695: xxd test not run on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13638
diff changeset
130 else
86eb21bb5920 patch 8.0.1695: xxd test not run on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13638
diff changeset
131 call writefile(['010000: 41'], 'Xinput')
86eb21bb5920 patch 8.0.1695: xxd test not run on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13638
diff changeset
132 silent exe '!' . s:xxd_cmd . ' -r -s -0x10000 < Xinput > XXDfile'
86eb21bb5920 patch 8.0.1695: xxd test not run on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13638
diff changeset
133 call delete('Xinput')
86eb21bb5920 patch 8.0.1695: xxd test not run on MS-Windows
Christian Brabandt <cb@256bit.org>
parents: 13638
diff changeset
134 endif
13634
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
135 call PrepareBuffer(readfile('XXDfile')[0])
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
136 call assert_equal('A', getline(1), s:Mess(s:test))
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
137 call delete('XXDfile')
15627
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
138
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
139 " Test 10: group with 4 octets
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
140 let s:test += 1
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
141 for arg in ['-g 4', '-group 4', '-g4']
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
142 call writefile(['TESTabcd09'], 'XXDfile')
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
143 %d
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
144 exe '0r! ' . s:xxd_cmd . ' ' . arg . ' XXDfile'
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
145 $d
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
146 let expected = ['00000000: 54455354 61626364 30390a TESTabcd09.']
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
147 call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
148 call delete('XXDfile')
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
149 endfor
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
150
15630
db6cfc44eb65 patch 8.1.0823: not sufficient testing of xxd
Bram Moolenaar <Bram@vim.org>
parents: 15627
diff changeset
151 " Test 11: reverse with CR, hex upper, Postscript style with a TAB
db6cfc44eb65 patch 8.1.0823: not sufficient testing of xxd
Bram Moolenaar <Bram@vim.org>
parents: 15627
diff changeset
152 let s:test += 1
db6cfc44eb65 patch 8.1.0823: not sufficient testing of xxd
Bram Moolenaar <Bram@vim.org>
parents: 15627
diff changeset
153 call writefile([" 54455354\t610B6364 30390A TESTa\0x0bcd09.\r"], 'Xinput')
db6cfc44eb65 patch 8.1.0823: not sufficient testing of xxd
Bram Moolenaar <Bram@vim.org>
parents: 15627
diff changeset
154 silent exe '!' . s:xxd_cmd . ' -r -p < Xinput > XXDfile'
db6cfc44eb65 patch 8.1.0823: not sufficient testing of xxd
Bram Moolenaar <Bram@vim.org>
parents: 15627
diff changeset
155 let blob = readfile('XXDfile', 'B')
db6cfc44eb65 patch 8.1.0823: not sufficient testing of xxd
Bram Moolenaar <Bram@vim.org>
parents: 15627
diff changeset
156 call assert_equal(0z54455354.610B6364.30390A, blob)
db6cfc44eb65 patch 8.1.0823: not sufficient testing of xxd
Bram Moolenaar <Bram@vim.org>
parents: 15627
diff changeset
157 call delete('Xinput')
db6cfc44eb65 patch 8.1.0823: not sufficient testing of xxd
Bram Moolenaar <Bram@vim.org>
parents: 15627
diff changeset
158 call delete('XXDfile')
db6cfc44eb65 patch 8.1.0823: not sufficient testing of xxd
Bram Moolenaar <Bram@vim.org>
parents: 15627
diff changeset
159
db6cfc44eb65 patch 8.1.0823: not sufficient testing of xxd
Bram Moolenaar <Bram@vim.org>
parents: 15627
diff changeset
160 " Test 12: reverse with seek
db6cfc44eb65 patch 8.1.0823: not sufficient testing of xxd
Bram Moolenaar <Bram@vim.org>
parents: 15627
diff changeset
161 let s:test += 1
db6cfc44eb65 patch 8.1.0823: not sufficient testing of xxd
Bram Moolenaar <Bram@vim.org>
parents: 15627
diff changeset
162 call writefile(["00000000: 54455354\t610B6364 30390A TESTa\0x0bcd09.\r"], 'Xinput')
db6cfc44eb65 patch 8.1.0823: not sufficient testing of xxd
Bram Moolenaar <Bram@vim.org>
parents: 15627
diff changeset
163 silent exe '!' . s:xxd_cmd . ' -r -seek 5 < Xinput > XXDfile'
db6cfc44eb65 patch 8.1.0823: not sufficient testing of xxd
Bram Moolenaar <Bram@vim.org>
parents: 15627
diff changeset
164 let blob = readfile('XXDfile', 'B')
db6cfc44eb65 patch 8.1.0823: not sufficient testing of xxd
Bram Moolenaar <Bram@vim.org>
parents: 15627
diff changeset
165 call assert_equal(0z0000000000.54455354.610B6364.30390A, blob)
db6cfc44eb65 patch 8.1.0823: not sufficient testing of xxd
Bram Moolenaar <Bram@vim.org>
parents: 15627
diff changeset
166 call delete('Xinput')
db6cfc44eb65 patch 8.1.0823: not sufficient testing of xxd
Bram Moolenaar <Bram@vim.org>
parents: 15627
diff changeset
167 call delete('XXDfile')
db6cfc44eb65 patch 8.1.0823: not sufficient testing of xxd
Bram Moolenaar <Bram@vim.org>
parents: 15627
diff changeset
168
20601
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
169 " Test 13: simple, decimal offset
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
170 call PrepareBuffer(range(1,30))
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
171 set ff=unix
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
172 w! XXDfile
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
173 let s:test += 1
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
174 exe '%!' . s:xxd_cmd . ' -d %'
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
175 let expected = [
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
176 \ '00000000: 310a 320a 330a 340a 350a 360a 370a 380a 1.2.3.4.5.6.7.8.',
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
177 \ '00000016: 390a 3130 0a31 310a 3132 0a31 330a 3134 9.10.11.12.13.14',
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
178 \ '00000032: 0a31 350a 3136 0a31 370a 3138 0a31 390a .15.16.17.18.19.',
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
179 \ '00000048: 3230 0a32 310a 3232 0a32 330a 3234 0a32 20.21.22.23.24.2',
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
180 \ '00000064: 350a 3236 0a32 370a 3238 0a32 390a 3330 5.26.27.28.29.30',
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
181 \ '00000080: 0a .']
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
182 call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
183
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
184 " Test 14: grouping with -d
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
185 let s:test += 1
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
186 let expected = [
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
187 \ '00000000: 310a320a 330a340a 350a360a 370a380a 1.2.3.4.5.6.7.8.',
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
188 \ '00000016: 390a3130 0a31310a 31320a31 330a3134 9.10.11.12.13.14',
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
189 \ '00000032: 0a31350a 31360a31 370a3138 0a31390a .15.16.17.18.19.',
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
190 \ '00000048: 32300a32 310a3232 0a32330a 32340a32 20.21.22.23.24.2',
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
191 \ '00000064: 350a3236 0a32370a 32380a32 390a3330 5.26.27.28.29.30',
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
192 \ '00000080: 0a .']
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
193 for arg in ['-g 4', '-group 4', '-g4']
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
194 exe '%!' . s:xxd_cmd . ' ' . arg . ' -d %'
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
195 call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
196 endfor
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
197
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
198 " Test 15: cols with decimal offset: -c 21 -d
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
199 let s:test += 1
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
200 let expected = [
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
201 \ '00000000: 310a 320a 330a 340a 350a 360a 370a 380a 390a 3130 0a 1.2.3.4.5.6.7.8.9.10.',
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
202 \ '00000021: 3131 0a31 320a 3133 0a31 340a 3135 0a31 360a 3137 0a 11.12.13.14.15.16.17.',
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
203 \ '00000042: 3138 0a31 390a 3230 0a32 310a 3232 0a32 330a 3234 0a 18.19.20.21.22.23.24.',
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
204 \ '00000063: 3235 0a32 360a 3237 0a32 380a 3239 0a33 300a 25.26.27.28.29.30.']
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
205 exe '%!' . s:xxd_cmd . ' -c 21 -d %'
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
206 call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
75ef263d09d6 patch 8.2.0854: xxd cannot show offset as a decimal number
Bram Moolenaar <Bram@vim.org>
parents: 17172
diff changeset
207
27102
4061623aa316 patch 8.2.4080: not sufficient test coverage for xxd
Bram Moolenaar <Bram@vim.org>
parents: 26254
diff changeset
208 " Test 16: -o -offset
4061623aa316 patch 8.2.4080: not sufficient test coverage for xxd
Bram Moolenaar <Bram@vim.org>
parents: 26254
diff changeset
209 let s:test += 1
4061623aa316 patch 8.2.4080: not sufficient test coverage for xxd
Bram Moolenaar <Bram@vim.org>
parents: 26254
diff changeset
210 let expected = [
4061623aa316 patch 8.2.4080: not sufficient test coverage for xxd
Bram Moolenaar <Bram@vim.org>
parents: 26254
diff changeset
211 \ '0000000f: 310a 320a 330a 340a 350a 360a 370a 380a 1.2.3.4.5.6.7.8.',
4061623aa316 patch 8.2.4080: not sufficient test coverage for xxd
Bram Moolenaar <Bram@vim.org>
parents: 26254
diff changeset
212 \ '0000001f: 390a 3130 0a31 310a 3132 0a31 330a 3134 9.10.11.12.13.14',
4061623aa316 patch 8.2.4080: not sufficient test coverage for xxd
Bram Moolenaar <Bram@vim.org>
parents: 26254
diff changeset
213 \ '0000002f: 0a31 350a 3136 0a31 370a 3138 0a31 390a .15.16.17.18.19.',
4061623aa316 patch 8.2.4080: not sufficient test coverage for xxd
Bram Moolenaar <Bram@vim.org>
parents: 26254
diff changeset
214 \ '0000003f: 3230 0a32 310a 3232 0a32 330a 3234 0a32 20.21.22.23.24.2',
4061623aa316 patch 8.2.4080: not sufficient test coverage for xxd
Bram Moolenaar <Bram@vim.org>
parents: 26254
diff changeset
215 \ '0000004f: 350a 3236 0a32 370a 3238 0a32 390a 3330 5.26.27.28.29.30',
4061623aa316 patch 8.2.4080: not sufficient test coverage for xxd
Bram Moolenaar <Bram@vim.org>
parents: 26254
diff changeset
216 \ '0000005f: 0a .']
4061623aa316 patch 8.2.4080: not sufficient test coverage for xxd
Bram Moolenaar <Bram@vim.org>
parents: 26254
diff changeset
217 for arg in ['-o 15', '-offset 15', '-o15']
4061623aa316 patch 8.2.4080: not sufficient test coverage for xxd
Bram Moolenaar <Bram@vim.org>
parents: 26254
diff changeset
218 exe '%!' . s:xxd_cmd . ' ' . arg . ' %'
4061623aa316 patch 8.2.4080: not sufficient test coverage for xxd
Bram Moolenaar <Bram@vim.org>
parents: 26254
diff changeset
219 call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
4061623aa316 patch 8.2.4080: not sufficient test coverage for xxd
Bram Moolenaar <Bram@vim.org>
parents: 26254
diff changeset
220 endfor
15627
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
221
29330
948c947cb1ed patch 9.0.0008: cannot specify the variable name for "xxd -i"
Bram Moolenaar <Bram@vim.org>
parents: 27118
diff changeset
222 " Test 17: Print C include with custom variable name
948c947cb1ed patch 9.0.0008: cannot specify the variable name for "xxd -i"
Bram Moolenaar <Bram@vim.org>
parents: 27118
diff changeset
223 let s:test += 1
948c947cb1ed patch 9.0.0008: cannot specify the variable name for "xxd -i"
Bram Moolenaar <Bram@vim.org>
parents: 27118
diff changeset
224 call writefile(['TESTabcd09'], 'XXDfile')
948c947cb1ed patch 9.0.0008: cannot specify the variable name for "xxd -i"
Bram Moolenaar <Bram@vim.org>
parents: 27118
diff changeset
225 for arg in ['-nvarName', '-n varName', '-name varName']
948c947cb1ed patch 9.0.0008: cannot specify the variable name for "xxd -i"
Bram Moolenaar <Bram@vim.org>
parents: 27118
diff changeset
226 %d
948c947cb1ed patch 9.0.0008: cannot specify the variable name for "xxd -i"
Bram Moolenaar <Bram@vim.org>
parents: 27118
diff changeset
227 exe '0r! ' . s:xxd_cmd . ' -i ' . arg . ' XXDfile'
948c947cb1ed patch 9.0.0008: cannot specify the variable name for "xxd -i"
Bram Moolenaar <Bram@vim.org>
parents: 27118
diff changeset
228 $d
948c947cb1ed patch 9.0.0008: cannot specify the variable name for "xxd -i"
Bram Moolenaar <Bram@vim.org>
parents: 27118
diff changeset
229 let expected =<< trim [CODE]
948c947cb1ed patch 9.0.0008: cannot specify the variable name for "xxd -i"
Bram Moolenaar <Bram@vim.org>
parents: 27118
diff changeset
230 unsigned char varName[] = {
948c947cb1ed patch 9.0.0008: cannot specify the variable name for "xxd -i"
Bram Moolenaar <Bram@vim.org>
parents: 27118
diff changeset
231 0x54, 0x45, 0x53, 0x54, 0x61, 0x62, 0x63, 0x64, 0x30, 0x39, 0x0a
948c947cb1ed patch 9.0.0008: cannot specify the variable name for "xxd -i"
Bram Moolenaar <Bram@vim.org>
parents: 27118
diff changeset
232 };
948c947cb1ed patch 9.0.0008: cannot specify the variable name for "xxd -i"
Bram Moolenaar <Bram@vim.org>
parents: 27118
diff changeset
233 unsigned int varName_len = 11;
948c947cb1ed patch 9.0.0008: cannot specify the variable name for "xxd -i"
Bram Moolenaar <Bram@vim.org>
parents: 27118
diff changeset
234 [CODE]
31849
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 30869
diff changeset
235
29330
948c947cb1ed patch 9.0.0008: cannot specify the variable name for "xxd -i"
Bram Moolenaar <Bram@vim.org>
parents: 27118
diff changeset
236 call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
948c947cb1ed patch 9.0.0008: cannot specify the variable name for "xxd -i"
Bram Moolenaar <Bram@vim.org>
parents: 27118
diff changeset
237 endfor
948c947cb1ed patch 9.0.0008: cannot specify the variable name for "xxd -i"
Bram Moolenaar <Bram@vim.org>
parents: 27118
diff changeset
238
948c947cb1ed patch 9.0.0008: cannot specify the variable name for "xxd -i"
Bram Moolenaar <Bram@vim.org>
parents: 27118
diff changeset
239 " using "-n name" reading from stdin
948c947cb1ed patch 9.0.0008: cannot specify the variable name for "xxd -i"
Bram Moolenaar <Bram@vim.org>
parents: 27118
diff changeset
240 %d
948c947cb1ed patch 9.0.0008: cannot specify the variable name for "xxd -i"
Bram Moolenaar <Bram@vim.org>
parents: 27118
diff changeset
241 exe '0r! ' . s:xxd_cmd . ' -i < XXDfile -n StdIn'
948c947cb1ed patch 9.0.0008: cannot specify the variable name for "xxd -i"
Bram Moolenaar <Bram@vim.org>
parents: 27118
diff changeset
242 $d
948c947cb1ed patch 9.0.0008: cannot specify the variable name for "xxd -i"
Bram Moolenaar <Bram@vim.org>
parents: 27118
diff changeset
243 let expected =<< trim [CODE]
948c947cb1ed patch 9.0.0008: cannot specify the variable name for "xxd -i"
Bram Moolenaar <Bram@vim.org>
parents: 27118
diff changeset
244 unsigned char StdIn[] = {
948c947cb1ed patch 9.0.0008: cannot specify the variable name for "xxd -i"
Bram Moolenaar <Bram@vim.org>
parents: 27118
diff changeset
245 0x54, 0x45, 0x53, 0x54, 0x61, 0x62, 0x63, 0x64, 0x30, 0x39, 0x0a
948c947cb1ed patch 9.0.0008: cannot specify the variable name for "xxd -i"
Bram Moolenaar <Bram@vim.org>
parents: 27118
diff changeset
246 };
948c947cb1ed patch 9.0.0008: cannot specify the variable name for "xxd -i"
Bram Moolenaar <Bram@vim.org>
parents: 27118
diff changeset
247 unsigned int StdIn_len = 11;
948c947cb1ed patch 9.0.0008: cannot specify the variable name for "xxd -i"
Bram Moolenaar <Bram@vim.org>
parents: 27118
diff changeset
248 [CODE]
948c947cb1ed patch 9.0.0008: cannot specify the variable name for "xxd -i"
Bram Moolenaar <Bram@vim.org>
parents: 27118
diff changeset
249 call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
948c947cb1ed patch 9.0.0008: cannot specify the variable name for "xxd -i"
Bram Moolenaar <Bram@vim.org>
parents: 27118
diff changeset
250
948c947cb1ed patch 9.0.0008: cannot specify the variable name for "xxd -i"
Bram Moolenaar <Bram@vim.org>
parents: 27118
diff changeset
251
948c947cb1ed patch 9.0.0008: cannot specify the variable name for "xxd -i"
Bram Moolenaar <Bram@vim.org>
parents: 27118
diff changeset
252 " Test 18: Print C include: custom variable names can be capitalized
948c947cb1ed patch 9.0.0008: cannot specify the variable name for "xxd -i"
Bram Moolenaar <Bram@vim.org>
parents: 27118
diff changeset
253 let s:test += 1
948c947cb1ed patch 9.0.0008: cannot specify the variable name for "xxd -i"
Bram Moolenaar <Bram@vim.org>
parents: 27118
diff changeset
254 for arg in ['-C', '-capitalize']
948c947cb1ed patch 9.0.0008: cannot specify the variable name for "xxd -i"
Bram Moolenaar <Bram@vim.org>
parents: 27118
diff changeset
255 call writefile(['TESTabcd09'], 'XXDfile')
948c947cb1ed patch 9.0.0008: cannot specify the variable name for "xxd -i"
Bram Moolenaar <Bram@vim.org>
parents: 27118
diff changeset
256 %d
948c947cb1ed patch 9.0.0008: cannot specify the variable name for "xxd -i"
Bram Moolenaar <Bram@vim.org>
parents: 27118
diff changeset
257 exe '0r! ' . s:xxd_cmd . ' -i ' . arg . ' -n varName XXDfile'
948c947cb1ed patch 9.0.0008: cannot specify the variable name for "xxd -i"
Bram Moolenaar <Bram@vim.org>
parents: 27118
diff changeset
258 $d
948c947cb1ed patch 9.0.0008: cannot specify the variable name for "xxd -i"
Bram Moolenaar <Bram@vim.org>
parents: 27118
diff changeset
259 let expected =<< trim [CODE]
948c947cb1ed patch 9.0.0008: cannot specify the variable name for "xxd -i"
Bram Moolenaar <Bram@vim.org>
parents: 27118
diff changeset
260 unsigned char VARNAME[] = {
948c947cb1ed patch 9.0.0008: cannot specify the variable name for "xxd -i"
Bram Moolenaar <Bram@vim.org>
parents: 27118
diff changeset
261 0x54, 0x45, 0x53, 0x54, 0x61, 0x62, 0x63, 0x64, 0x30, 0x39, 0x0a
948c947cb1ed patch 9.0.0008: cannot specify the variable name for "xxd -i"
Bram Moolenaar <Bram@vim.org>
parents: 27118
diff changeset
262 };
948c947cb1ed patch 9.0.0008: cannot specify the variable name for "xxd -i"
Bram Moolenaar <Bram@vim.org>
parents: 27118
diff changeset
263 unsigned int VARNAME_LEN = 11;
948c947cb1ed patch 9.0.0008: cannot specify the variable name for "xxd -i"
Bram Moolenaar <Bram@vim.org>
parents: 27118
diff changeset
264 [CODE]
948c947cb1ed patch 9.0.0008: cannot specify the variable name for "xxd -i"
Bram Moolenaar <Bram@vim.org>
parents: 27118
diff changeset
265 call assert_equal(expected, getline(1,'$'), s:Mess(s:test))
948c947cb1ed patch 9.0.0008: cannot specify the variable name for "xxd -i"
Bram Moolenaar <Bram@vim.org>
parents: 27118
diff changeset
266 endfor
948c947cb1ed patch 9.0.0008: cannot specify the variable name for "xxd -i"
Bram Moolenaar <Bram@vim.org>
parents: 27118
diff changeset
267
948c947cb1ed patch 9.0.0008: cannot specify the variable name for "xxd -i"
Bram Moolenaar <Bram@vim.org>
parents: 27118
diff changeset
268
13634
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
269 %d
20784
d7d6993fc266 patch 8.2.0944: xxd test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 20601
diff changeset
270 bwipe!
d7d6993fc266 patch 8.2.0944: xxd test leaves file behind
Bram Moolenaar <Bram@vim.org>
parents: 20601
diff changeset
271 call delete('XXDfile')
13634
2678e38e1de6 patch 8.0.1689: no tests for xxd
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
272 endfunc
15627
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
273
26036
c8165ec9dcad patch 8.2.3552: xxd revert does not handle end of line correctly
Bram Moolenaar <Bram@vim.org>
parents: 25076
diff changeset
274 func Test_xxd_patch()
26038
542cc55a660b patch 8.2.3553: xxd test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 26036
diff changeset
275 let cmd1 = 'silent !' .. s:xxd_cmd .. ' -r Xxxdin Xxxdfile'
542cc55a660b patch 8.2.3553: xxd test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 26036
diff changeset
276 let cmd2 = 'silent !' .. s:xxd_cmd .. ' -g1 Xxxdfile > Xxxdout'
30869
bff3fa5f4c74 patch 9.0.0769: too many delete() calls in tests
Bram Moolenaar <Bram@vim.org>
parents: 29330
diff changeset
277 call writefile(["2: 41 41", "8: 42 42"], 'Xxxdin', 'D')
bff3fa5f4c74 patch 9.0.0769: too many delete() calls in tests
Bram Moolenaar <Bram@vim.org>
parents: 29330
diff changeset
278 call writefile(['::::::::'], 'Xxxdfile', 'D')
26038
542cc55a660b patch 8.2.3553: xxd test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 26036
diff changeset
279 exe cmd1
542cc55a660b patch 8.2.3553: xxd test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 26036
diff changeset
280 exe cmd2
26036
c8165ec9dcad patch 8.2.3552: xxd revert does not handle end of line correctly
Bram Moolenaar <Bram@vim.org>
parents: 25076
diff changeset
281 call assert_equal(['00000000: 3a 3a 41 41 3a 3a 3a 3a 42 42 ::AA::::BB'], readfile('Xxxdout'))
c8165ec9dcad patch 8.2.3552: xxd revert does not handle end of line correctly
Bram Moolenaar <Bram@vim.org>
parents: 25076
diff changeset
282
c8165ec9dcad patch 8.2.3552: xxd revert does not handle end of line correctly
Bram Moolenaar <Bram@vim.org>
parents: 25076
diff changeset
283 call writefile(["2: 43 43 ", "8: 44 44"], 'Xxxdin')
26038
542cc55a660b patch 8.2.3553: xxd test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 26036
diff changeset
284 exe cmd1
542cc55a660b patch 8.2.3553: xxd test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 26036
diff changeset
285 exe cmd2
26036
c8165ec9dcad patch 8.2.3552: xxd revert does not handle end of line correctly
Bram Moolenaar <Bram@vim.org>
parents: 25076
diff changeset
286 call assert_equal(['00000000: 3a 3a 43 43 3a 3a 3a 3a 44 44 ::CC::::DD'], readfile('Xxxdout'))
c8165ec9dcad patch 8.2.3552: xxd revert does not handle end of line correctly
Bram Moolenaar <Bram@vim.org>
parents: 25076
diff changeset
287
c8165ec9dcad patch 8.2.3552: xxd revert does not handle end of line correctly
Bram Moolenaar <Bram@vim.org>
parents: 25076
diff changeset
288 call writefile(["2: 45 45 ", "8: 46 46"], 'Xxxdin')
26038
542cc55a660b patch 8.2.3553: xxd test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 26036
diff changeset
289 exe cmd1
542cc55a660b patch 8.2.3553: xxd test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 26036
diff changeset
290 exe cmd2
26036
c8165ec9dcad patch 8.2.3552: xxd revert does not handle end of line correctly
Bram Moolenaar <Bram@vim.org>
parents: 25076
diff changeset
291 call assert_equal(['00000000: 3a 3a 45 45 3a 3a 3a 3a 46 46 ::EE::::FF'], readfile('Xxxdout'))
31849
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 30869
diff changeset
292
26036
c8165ec9dcad patch 8.2.3552: xxd revert does not handle end of line correctly
Bram Moolenaar <Bram@vim.org>
parents: 25076
diff changeset
293 call writefile(["2: 41 41", "08: 42 42"], 'Xxxdin')
c8165ec9dcad patch 8.2.3552: xxd revert does not handle end of line correctly
Bram Moolenaar <Bram@vim.org>
parents: 25076
diff changeset
294 call writefile(['::::::::'], 'Xxxdfile')
26038
542cc55a660b patch 8.2.3553: xxd test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 26036
diff changeset
295 exe cmd1
542cc55a660b patch 8.2.3553: xxd test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 26036
diff changeset
296 exe cmd2
26036
c8165ec9dcad patch 8.2.3552: xxd revert does not handle end of line correctly
Bram Moolenaar <Bram@vim.org>
parents: 25076
diff changeset
297 call assert_equal(['00000000: 3a 3a 41 41 3a 3a 3a 3a 42 42 ::AA::::BB'], readfile('Xxxdout'))
c8165ec9dcad patch 8.2.3552: xxd revert does not handle end of line correctly
Bram Moolenaar <Bram@vim.org>
parents: 25076
diff changeset
298
c8165ec9dcad patch 8.2.3552: xxd revert does not handle end of line correctly
Bram Moolenaar <Bram@vim.org>
parents: 25076
diff changeset
299 call writefile(["2: 43 43 ", "09: 44 44"], 'Xxxdin')
26038
542cc55a660b patch 8.2.3553: xxd test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 26036
diff changeset
300 exe cmd1
542cc55a660b patch 8.2.3553: xxd test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 26036
diff changeset
301 exe cmd2
26036
c8165ec9dcad patch 8.2.3552: xxd revert does not handle end of line correctly
Bram Moolenaar <Bram@vim.org>
parents: 25076
diff changeset
302 call assert_equal(['00000000: 3a 3a 43 43 3a 3a 3a 3a 42 44 44 ::CC::::BDD'], readfile('Xxxdout'))
c8165ec9dcad patch 8.2.3552: xxd revert does not handle end of line correctly
Bram Moolenaar <Bram@vim.org>
parents: 25076
diff changeset
303
c8165ec9dcad patch 8.2.3552: xxd revert does not handle end of line correctly
Bram Moolenaar <Bram@vim.org>
parents: 25076
diff changeset
304 call writefile(["2: 45 45 ", "0a: 46 46"], 'Xxxdin')
26038
542cc55a660b patch 8.2.3553: xxd test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 26036
diff changeset
305 exe cmd1
542cc55a660b patch 8.2.3553: xxd test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 26036
diff changeset
306 exe cmd2
26036
c8165ec9dcad patch 8.2.3552: xxd revert does not handle end of line correctly
Bram Moolenaar <Bram@vim.org>
parents: 25076
diff changeset
307 call assert_equal(['00000000: 3a 3a 45 45 3a 3a 3a 3a 42 44 46 46 ::EE::::BDFF'], readfile('Xxxdout'))
31849
dbec60b8c253 patch 9.0.1257: code style is not check in test scripts
Bram Moolenaar <Bram@vim.org>
parents: 30869
diff changeset
308
26036
c8165ec9dcad patch 8.2.3552: xxd revert does not handle end of line correctly
Bram Moolenaar <Bram@vim.org>
parents: 25076
diff changeset
309 call delete('Xxxdout')
c8165ec9dcad patch 8.2.3552: xxd revert does not handle end of line correctly
Bram Moolenaar <Bram@vim.org>
parents: 25076
diff changeset
310 endfunc
c8165ec9dcad patch 8.2.3552: xxd revert does not handle end of line correctly
Bram Moolenaar <Bram@vim.org>
parents: 25076
diff changeset
311
15627
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
312 " Various ways with wrong arguments that trigger the usage output.
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
313 func Test_xxd_usage()
27102
4061623aa316 patch 8.2.4080: not sufficient test coverage for xxd
Bram Moolenaar <Bram@vim.org>
parents: 26254
diff changeset
314 for arg in ['-h', '-c', '-g', '-o', '-s', '-l', '-X', 'one two three']
15627
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
315 new
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
316 exe 'r! ' . s:xxd_cmd . ' ' . arg
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
317 call assert_match("Usage:", join(getline(1, 3)))
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
318 bwipe!
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
319 endfor
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
320 endfunc
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
321
26254
3a13efec0016 patch 8.2.3658: duplicate code in xxd
Bram Moolenaar <Bram@vim.org>
parents: 26038
diff changeset
322 func Test_xxd_ignore_garbage()
3a13efec0016 patch 8.2.3658: duplicate code in xxd
Bram Moolenaar <Bram@vim.org>
parents: 26038
diff changeset
323 new
3a13efec0016 patch 8.2.3658: duplicate code in xxd
Bram Moolenaar <Bram@vim.org>
parents: 26038
diff changeset
324 exe 'r! printf "\n\r xxxx 0: 42 42" | ' . s:xxd_cmd . ' -r'
3a13efec0016 patch 8.2.3658: duplicate code in xxd
Bram Moolenaar <Bram@vim.org>
parents: 26038
diff changeset
325 call assert_match('BB', join(getline(1, 3)))
3a13efec0016 patch 8.2.3658: duplicate code in xxd
Bram Moolenaar <Bram@vim.org>
parents: 26038
diff changeset
326 bwipe!
3a13efec0016 patch 8.2.3658: duplicate code in xxd
Bram Moolenaar <Bram@vim.org>
parents: 26038
diff changeset
327 endfunc
3a13efec0016 patch 8.2.3658: duplicate code in xxd
Bram Moolenaar <Bram@vim.org>
parents: 26038
diff changeset
328
3a13efec0016 patch 8.2.3658: duplicate code in xxd
Bram Moolenaar <Bram@vim.org>
parents: 26038
diff changeset
329 func Test_xxd_bit_dump()
3a13efec0016 patch 8.2.3658: duplicate code in xxd
Bram Moolenaar <Bram@vim.org>
parents: 26038
diff changeset
330 new
3a13efec0016 patch 8.2.3658: duplicate code in xxd
Bram Moolenaar <Bram@vim.org>
parents: 26038
diff changeset
331 exe 'r! printf "123456" | ' . s:xxd_cmd . ' -b1'
3a13efec0016 patch 8.2.3658: duplicate code in xxd
Bram Moolenaar <Bram@vim.org>
parents: 26038
diff changeset
332 call assert_match('00000000: 00110001 00110010 00110011 00110100 00110101 00110110 123456', join(getline(1, 3)))
3a13efec0016 patch 8.2.3658: duplicate code in xxd
Bram Moolenaar <Bram@vim.org>
parents: 26038
diff changeset
333 bwipe!
3a13efec0016 patch 8.2.3658: duplicate code in xxd
Bram Moolenaar <Bram@vim.org>
parents: 26038
diff changeset
334 endfunc
3a13efec0016 patch 8.2.3658: duplicate code in xxd
Bram Moolenaar <Bram@vim.org>
parents: 26038
diff changeset
335
15627
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
336 func Test_xxd_version()
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
337 new
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
338 exe 'r! ' . s:xxd_cmd . ' -v'
25076
5690cf66ee07 patch 8.2.3075: xxd always reports an old version string
Bram Moolenaar <Bram@vim.org>
parents: 21765
diff changeset
339 call assert_match('xxd 20\d\d-\d\d-\d\d by Juergen Weigert et al\.', join(getline(1, 3)))
15627
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
340 bwipe!
11879b89bb69 patch 8.1.0821: xxd "usage" output and other arguments not tested
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
341 endfunc
21765
08940efa6b4e patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents: 20784
diff changeset
342
27102
4061623aa316 patch 8.2.4080: not sufficient test coverage for xxd
Bram Moolenaar <Bram@vim.org>
parents: 26254
diff changeset
343 " number of columns must be non-negative
4061623aa316 patch 8.2.4080: not sufficient test coverage for xxd
Bram Moolenaar <Bram@vim.org>
parents: 26254
diff changeset
344 func Test_xxd_min_cols()
4061623aa316 patch 8.2.4080: not sufficient test coverage for xxd
Bram Moolenaar <Bram@vim.org>
parents: 26254
diff changeset
345 for cols in ['-c-1', '-c -1', '-cols -1']
4061623aa316 patch 8.2.4080: not sufficient test coverage for xxd
Bram Moolenaar <Bram@vim.org>
parents: 26254
diff changeset
346 for fmt in ['', '-b', '-e', '-i', '-p', ]
4061623aa316 patch 8.2.4080: not sufficient test coverage for xxd
Bram Moolenaar <Bram@vim.org>
parents: 26254
diff changeset
347 new
4061623aa316 patch 8.2.4080: not sufficient test coverage for xxd
Bram Moolenaar <Bram@vim.org>
parents: 26254
diff changeset
348 exe 'r! printf "ignored" | ' . s:xxd_cmd . ' ' . cols . ' ' . fmt
4061623aa316 patch 8.2.4080: not sufficient test coverage for xxd
Bram Moolenaar <Bram@vim.org>
parents: 26254
diff changeset
349 call assert_match("invalid number of columns", join(getline(1, '$')))
4061623aa316 patch 8.2.4080: not sufficient test coverage for xxd
Bram Moolenaar <Bram@vim.org>
parents: 26254
diff changeset
350 bwipe!
4061623aa316 patch 8.2.4080: not sufficient test coverage for xxd
Bram Moolenaar <Bram@vim.org>
parents: 26254
diff changeset
351 endfor
4061623aa316 patch 8.2.4080: not sufficient test coverage for xxd
Bram Moolenaar <Bram@vim.org>
parents: 26254
diff changeset
352 endfor
4061623aa316 patch 8.2.4080: not sufficient test coverage for xxd
Bram Moolenaar <Bram@vim.org>
parents: 26254
diff changeset
353 endfunc
4061623aa316 patch 8.2.4080: not sufficient test coverage for xxd
Bram Moolenaar <Bram@vim.org>
parents: 26254
diff changeset
354
4061623aa316 patch 8.2.4080: not sufficient test coverage for xxd
Bram Moolenaar <Bram@vim.org>
parents: 26254
diff changeset
355 " some hex formats limit columns to 256 (a #define in xxd.c)
4061623aa316 patch 8.2.4080: not sufficient test coverage for xxd
Bram Moolenaar <Bram@vim.org>
parents: 26254
diff changeset
356 func Test_xxd_max_cols()
4061623aa316 patch 8.2.4080: not sufficient test coverage for xxd
Bram Moolenaar <Bram@vim.org>
parents: 26254
diff changeset
357 for cols in ['-c257', '-c 257', '-cols 257']
4061623aa316 patch 8.2.4080: not sufficient test coverage for xxd
Bram Moolenaar <Bram@vim.org>
parents: 26254
diff changeset
358 for fmt in ['', '-b', '-e' ]
4061623aa316 patch 8.2.4080: not sufficient test coverage for xxd
Bram Moolenaar <Bram@vim.org>
parents: 26254
diff changeset
359 new
4061623aa316 patch 8.2.4080: not sufficient test coverage for xxd
Bram Moolenaar <Bram@vim.org>
parents: 26254
diff changeset
360 exe 'r! printf "ignored" | ' . s:xxd_cmd . ' ' . cols . ' ' . fmt
4061623aa316 patch 8.2.4080: not sufficient test coverage for xxd
Bram Moolenaar <Bram@vim.org>
parents: 26254
diff changeset
361 call assert_match("invalid number of columns", join(getline(1, '$')))
4061623aa316 patch 8.2.4080: not sufficient test coverage for xxd
Bram Moolenaar <Bram@vim.org>
parents: 26254
diff changeset
362 bwipe!
4061623aa316 patch 8.2.4080: not sufficient test coverage for xxd
Bram Moolenaar <Bram@vim.org>
parents: 26254
diff changeset
363 endfor
4061623aa316 patch 8.2.4080: not sufficient test coverage for xxd
Bram Moolenaar <Bram@vim.org>
parents: 26254
diff changeset
364 endfor
4061623aa316 patch 8.2.4080: not sufficient test coverage for xxd
Bram Moolenaar <Bram@vim.org>
parents: 26254
diff changeset
365 endfunc
4061623aa316 patch 8.2.4080: not sufficient test coverage for xxd
Bram Moolenaar <Bram@vim.org>
parents: 26254
diff changeset
366
4061623aa316 patch 8.2.4080: not sufficient test coverage for xxd
Bram Moolenaar <Bram@vim.org>
parents: 26254
diff changeset
367 " -c0 selects the format specific default column value, as if no -c was given
27118
2f854597399f patch 8.2.4088: xxd cannot output everything in one line
Bram Moolenaar <Bram@vim.org>
parents: 27102
diff changeset
368 " except for -ps, where it disables extra newlines
27102
4061623aa316 patch 8.2.4080: not sufficient test coverage for xxd
Bram Moolenaar <Bram@vim.org>
parents: 26254
diff changeset
369 func Test_xxd_c0_is_def_cols()
30869
bff3fa5f4c74 patch 9.0.0769: too many delete() calls in tests
Bram Moolenaar <Bram@vim.org>
parents: 29330
diff changeset
370 call writefile(["abcdefghijklmnopqrstuvwxyz0123456789"], 'Xxdin', 'D')
27102
4061623aa316 patch 8.2.4080: not sufficient test coverage for xxd
Bram Moolenaar <Bram@vim.org>
parents: 26254
diff changeset
371 for cols in ['-c0', '-c 0', '-cols 0']
27118
2f854597399f patch 8.2.4088: xxd cannot output everything in one line
Bram Moolenaar <Bram@vim.org>
parents: 27102
diff changeset
372 for fmt in ['', '-b', '-e', '-i']
27102
4061623aa316 patch 8.2.4080: not sufficient test coverage for xxd
Bram Moolenaar <Bram@vim.org>
parents: 26254
diff changeset
373 exe 'r! ' . s:xxd_cmd . ' ' . fmt ' Xxdin > Xxdout1'
4061623aa316 patch 8.2.4080: not sufficient test coverage for xxd
Bram Moolenaar <Bram@vim.org>
parents: 26254
diff changeset
374 exe 'r! ' . s:xxd_cmd . ' ' . cols . ' ' . fmt ' Xxdin > Xxdout2'
4061623aa316 patch 8.2.4080: not sufficient test coverage for xxd
Bram Moolenaar <Bram@vim.org>
parents: 26254
diff changeset
375 call assert_equalfile('Xxdout1', 'Xxdout2')
4061623aa316 patch 8.2.4080: not sufficient test coverage for xxd
Bram Moolenaar <Bram@vim.org>
parents: 26254
diff changeset
376 endfor
4061623aa316 patch 8.2.4080: not sufficient test coverage for xxd
Bram Moolenaar <Bram@vim.org>
parents: 26254
diff changeset
377 endfor
4061623aa316 patch 8.2.4080: not sufficient test coverage for xxd
Bram Moolenaar <Bram@vim.org>
parents: 26254
diff changeset
378 call delete('Xxdout1')
4061623aa316 patch 8.2.4080: not sufficient test coverage for xxd
Bram Moolenaar <Bram@vim.org>
parents: 26254
diff changeset
379 call delete('Xxdout2')
4061623aa316 patch 8.2.4080: not sufficient test coverage for xxd
Bram Moolenaar <Bram@vim.org>
parents: 26254
diff changeset
380 endfunc
4061623aa316 patch 8.2.4080: not sufficient test coverage for xxd
Bram Moolenaar <Bram@vim.org>
parents: 26254
diff changeset
381
27118
2f854597399f patch 8.2.4088: xxd cannot output everything in one line
Bram Moolenaar <Bram@vim.org>
parents: 27102
diff changeset
382 " all output in a single line for -c0 -ps
2f854597399f patch 8.2.4088: xxd cannot output everything in one line
Bram Moolenaar <Bram@vim.org>
parents: 27102
diff changeset
383 func Test_xxd_plain_one_line()
2f854597399f patch 8.2.4088: xxd cannot output everything in one line
Bram Moolenaar <Bram@vim.org>
parents: 27102
diff changeset
384 call writefile([
2f854597399f patch 8.2.4088: xxd cannot output everything in one line
Bram Moolenaar <Bram@vim.org>
parents: 27102
diff changeset
385 \ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
2f854597399f patch 8.2.4088: xxd cannot output everything in one line
Bram Moolenaar <Bram@vim.org>
parents: 27102
diff changeset
386 \ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
2f854597399f patch 8.2.4088: xxd cannot output everything in one line
Bram Moolenaar <Bram@vim.org>
parents: 27102
diff changeset
387 \ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
2f854597399f patch 8.2.4088: xxd cannot output everything in one line
Bram Moolenaar <Bram@vim.org>
parents: 27102
diff changeset
388 \ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
2f854597399f patch 8.2.4088: xxd cannot output everything in one line
Bram Moolenaar <Bram@vim.org>
parents: 27102
diff changeset
389 \ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
2f854597399f patch 8.2.4088: xxd cannot output everything in one line
Bram Moolenaar <Bram@vim.org>
parents: 27102
diff changeset
390 \ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"],
30869
bff3fa5f4c74 patch 9.0.0769: too many delete() calls in tests
Bram Moolenaar <Bram@vim.org>
parents: 29330
diff changeset
391 \ 'Xxdin', 'D')
27118
2f854597399f patch 8.2.4088: xxd cannot output everything in one line
Bram Moolenaar <Bram@vim.org>
parents: 27102
diff changeset
392 for cols in ['-c0', '-c 0', '-cols 0']
2f854597399f patch 8.2.4088: xxd cannot output everything in one line
Bram Moolenaar <Bram@vim.org>
parents: 27102
diff changeset
393 exe 'r! ' . s:xxd_cmd . ' -ps ' . cols ' Xxdin'
2f854597399f patch 8.2.4088: xxd cannot output everything in one line
Bram Moolenaar <Bram@vim.org>
parents: 27102
diff changeset
394 " output seems to start in line 2
2f854597399f patch 8.2.4088: xxd cannot output everything in one line
Bram Moolenaar <Bram@vim.org>
parents: 27102
diff changeset
395 let out = join(getline(2, '$'))
2f854597399f patch 8.2.4088: xxd cannot output everything in one line
Bram Moolenaar <Bram@vim.org>
parents: 27102
diff changeset
396 bwipe!
2f854597399f patch 8.2.4088: xxd cannot output everything in one line
Bram Moolenaar <Bram@vim.org>
parents: 27102
diff changeset
397 " newlines in xxd output result in spaces in the string variable out
2f854597399f patch 8.2.4088: xxd cannot output everything in one line
Bram Moolenaar <Bram@vim.org>
parents: 27102
diff changeset
398 call assert_notmatch(" ", out)
2f854597399f patch 8.2.4088: xxd cannot output everything in one line
Bram Moolenaar <Bram@vim.org>
parents: 27102
diff changeset
399 " xxd output must be non-empty and comprise only lower case hex digits
2f854597399f patch 8.2.4088: xxd cannot output everything in one line
Bram Moolenaar <Bram@vim.org>
parents: 27102
diff changeset
400 call assert_match("^[0-9a-f][0-9a-f]*$", out)
2f854597399f patch 8.2.4088: xxd cannot output everything in one line
Bram Moolenaar <Bram@vim.org>
parents: 27102
diff changeset
401 endfor
2f854597399f patch 8.2.4088: xxd cannot output everything in one line
Bram Moolenaar <Bram@vim.org>
parents: 27102
diff changeset
402 endfunc
2f854597399f patch 8.2.4088: xxd cannot output everything in one line
Bram Moolenaar <Bram@vim.org>
parents: 27102
diff changeset
403
32104
5a1113ece237 patch 9.0.1383: xxd: combination of little endian and cols fails
Bram Moolenaar <Bram@vim.org>
parents: 31849
diff changeset
404 func Test_xxd_little_endian_with_cols()
5a1113ece237 patch 9.0.1383: xxd: combination of little endian and cols fails
Bram Moolenaar <Bram@vim.org>
parents: 31849
diff changeset
405 enew!
5a1113ece237 patch 9.0.1383: xxd: combination of little endian and cols fails
Bram Moolenaar <Bram@vim.org>
parents: 31849
diff changeset
406 call writefile(["ABCDEF"], 'Xxdin', 'D')
5a1113ece237 patch 9.0.1383: xxd: combination of little endian and cols fails
Bram Moolenaar <Bram@vim.org>
parents: 31849
diff changeset
407 exe 'r! ' .. s:xxd_cmd .. ' -e -c6 ' .. ' Xxdin'
5a1113ece237 patch 9.0.1383: xxd: combination of little endian and cols fails
Bram Moolenaar <Bram@vim.org>
parents: 31849
diff changeset
408 call assert_equal('00000000: 44434241 4645 ABCDEF', getline(2))
5a1113ece237 patch 9.0.1383: xxd: combination of little endian and cols fails
Bram Moolenaar <Bram@vim.org>
parents: 31849
diff changeset
409
5a1113ece237 patch 9.0.1383: xxd: combination of little endian and cols fails
Bram Moolenaar <Bram@vim.org>
parents: 31849
diff changeset
410 enew!
5a1113ece237 patch 9.0.1383: xxd: combination of little endian and cols fails
Bram Moolenaar <Bram@vim.org>
parents: 31849
diff changeset
411 call writefile(["ABCDEFGHI"], 'Xxdin', 'D')
5a1113ece237 patch 9.0.1383: xxd: combination of little endian and cols fails
Bram Moolenaar <Bram@vim.org>
parents: 31849
diff changeset
412 exe 'r! ' .. s:xxd_cmd .. ' -e -c9 ' .. ' Xxdin'
5a1113ece237 patch 9.0.1383: xxd: combination of little endian and cols fails
Bram Moolenaar <Bram@vim.org>
parents: 31849
diff changeset
413 call assert_equal('00000000: 44434241 48474645 49 ABCDEFGHI', getline(2))
5a1113ece237 patch 9.0.1383: xxd: combination of little endian and cols fails
Bram Moolenaar <Bram@vim.org>
parents: 31849
diff changeset
414
5a1113ece237 patch 9.0.1383: xxd: combination of little endian and cols fails
Bram Moolenaar <Bram@vim.org>
parents: 31849
diff changeset
415 bwipe!
5a1113ece237 patch 9.0.1383: xxd: combination of little endian and cols fails
Bram Moolenaar <Bram@vim.org>
parents: 31849
diff changeset
416 endfunc
5a1113ece237 patch 9.0.1383: xxd: combination of little endian and cols fails
Bram Moolenaar <Bram@vim.org>
parents: 31849
diff changeset
417
21765
08940efa6b4e patch 8.2.1432: various inconsistencies in test files
Bram Moolenaar <Bram@vim.org>
parents: 20784
diff changeset
418 " vim: shiftwidth=2 sts=2 expandtab