tio.nim 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. discard """
  2. outputsub: ""
  3. disabled: true
  4. """
  5. import
  6. unittest, osproc, streams, os, strformat, strutils
  7. const STRING_DATA = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."
  8. const TEST_FILE = "tests/testdata/string.txt"
  9. proc echoLoop(str: string): string =
  10. result = ""
  11. let exe = findExe("tests/system/helpers/readall_echo")
  12. echo "exe: ", exe
  13. var process = startProcess(exe)
  14. var input = process.inputStream
  15. input.write(str)
  16. input.close()
  17. var output = process.outputStream
  18. discard process.waitForExit
  19. while not output.atEnd:
  20. result.add(output.readLine)
  21. block: # io
  22. block: # readAll
  23. block: # stdin
  24. check:
  25. echoLoop(STRING_DATA) == STRING_DATA
  26. block: # file
  27. check:
  28. readFile(TEST_FILE).strip == STRING_DATA
  29. proc verifyFileSize(sz: int64) =
  30. # issue 7121, large file size (2-4GB and >4Gb)
  31. const fn = "tmpfile112358"
  32. let size_in_mb = sz div 1_000_000
  33. when defined(windows):
  34. discard execProcess(&"fsutil file createnew {fn} {sz}" )
  35. else:
  36. discard execProcess(&"dd if=/dev/zero of={fn} bs=1000000 count={size_in_mb}")
  37. doAssert os.getFileSize(fn) == sz # Verify OS filesize by string
  38. var f = open(fn)
  39. doAssert f.getFileSize() == sz # Verify file handle filesize
  40. f.close()
  41. os.removeFile(fn)
  42. #disable tests for automatic testers
  43. #for s in [50_000_000'i64, 3_000_000_000, 5_000_000_000]:
  44. # verifyFileSize(s)