Add test cases for a big file.

This commit is contained in:
Geoff Greer 2014-06-25 15:14:06 -07:00
parent a744f26ead
commit 0eef7cbee8
4 changed files with 54 additions and 0 deletions

2
.gitignore vendored
View file

@ -23,4 +23,6 @@ missing
src/config.h*
stamp-h1
tests/*.err
tests/big/*.err
tests/big/big_file.txt
the_silver_searcher.spec

View file

@ -17,4 +17,7 @@ EXTRA_DIST = Makefile.w32 LICENSE NOTICE the_silver_searcher.spec README.md
test:
cram -v tests/*.t
test_big:
cram -v tests/big/*.t
.PHONY : all test clean

20
tests/big/big_file.t Normal file
View file

@ -0,0 +1,20 @@
Setup and create really big file:
$ . $TESTDIR/../setup.sh
$ python $TESTDIR/create_big_file.py $TESTDIR/big_file.txt
Search a big file:
$ $TESTDIR/../../ag --nocolor --workers=1 --parallel hello $TESTDIR/big_file.txt
33554432:hello1073741824
67108864:hello2147483648
100663296:hello3221225472
134217728:hello4294967296
167772160:hello5368709120
201326592:hello6442450944
234881024:hello7516192768
268435456:hello
Fail to regex search a big file:
$ $TESTDIR/../../ag --nocolor --workers=1 --parallel 'hello.*' $TESTDIR/big_file.txt
ERR: Skipping /Users/ggreer/code/ag/tests/big/big_file.txt: pcre_exec() can't handle files larger than 2147483647 bytes.

29
tests/big/create_big_file.py Executable file
View file

@ -0,0 +1,29 @@
#!/usr/bin/env python
# Create an 8GB file of mostly "abcdefghijklmnopqrstuvwxyz01234",
# with a few instances of "hello"
import sys
if len(sys.argv) != 2:
print("Usage: %s big_file.txt" % sys.argv[0])
sys.exit(1)
big_file = sys.argv[1]
def create_big_file():
with open(big_file, "w") as fd:
for i in range(1, 2**28):
byte = i * 32
if byte % 2**30 == 0:
fd.write("hello%s\n" % byte)
else:
fd.write("abcdefghijklmnopqrstuvwxyz01234\n")
fd.write("hello\n")
try:
fd = open(big_file, "r")
except Exception as e:
create_big_file()