genTestRes.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/usr/bin/env python3
  2. # Generates files and directories in test-res used for Unicode sys tests.
  3. # The test vector printf'ed into data.bin, as well as the names in filenames()
  4. # should correspond exactly to the sequences in UnicodeSequences.valid.
  5. import os
  6. import shutil
  7. TESTDIR = "test-res"
  8. # delete previous, if any
  9. if os.path.isdir(TESTDIR):
  10. shutil.rmtree(TESTDIR)
  11. os.mkdir(TESTDIR)
  12. # Unicode test vectors
  13. allUnicode = [
  14. [0x01],
  15. [0x7F],
  16. [0xC2, 0x80],
  17. [0xDF, 0xBF],
  18. [0xE0, 0xA0, 0x80],
  19. [0xED, 0x9F, 0xBF],
  20. [0xEE, 0x80, 0x80],
  21. [0xEF, 0xBF, 0xBD],
  22. [0xF0, 0x90, 0x80, 0x80],
  23. [0xF0, 0x9F, 0xBF, 0xBF],
  24. [0xF3, 0xBF, 0xBF, 0xBF],
  25. [0xF4, 0x80, 0x80, 0x80],
  26. [0xF4, 0x8F, 0xBF, 0xBF],
  27. [0xF0, 0x9F, 0x98, 0x82, 0xF0, 0x9F, 0x98, 0x84, 0xF0, 0x9F, 0x98, 0x99],
  28. [0xC8, 0xA7],
  29. [0xE4, 0xB8, 0xAD, 0xE6, 0x96, 0x87, 0xEF, 0xBC, 0x8C, 0xE3, 0x81, 0xAB, 0xE3, 0x81, 0xBB, 0xE3, 0x82, 0x93, 0xE3, 0x81, 0x94]
  30. ]
  31. allStrings = [ bytes(data).decode("utf-8") for data in allUnicode ]
  32. allFilenames = allStrings[:]
  33. # Windows does not allow codepoints in the U+0000 - U+001F range
  34. # see https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file
  35. if os.name == "nt":
  36. allFilenames.remove(bytes([0x01]).decode("utf-8"))
  37. allBinary = b""
  38. for data in allUnicode:
  39. allBinary += bytes(data) + b"\n"
  40. # generate a file with Unicode data
  41. with open(os.path.join(TESTDIR, "data.bin"), "wb") as f:
  42. f.write(allBinary)
  43. # generate sub-directories with symlinks
  44. os.mkdir(os.path.join(TESTDIR, "a"))
  45. for data in allFilenames:
  46. os.mkdir(os.path.join(TESTDIR, data))
  47. os.mkdir(os.path.join(TESTDIR, "a", data))
  48. if os.name != "nt":
  49. for target, name in [
  50. ("../../bin/cpp/UtilityProcess-debug", "bin-cpp-debug"),
  51. ("../../bin/cpp/UtilityProcess", "bin-cpp"),
  52. ("../../bin/cs/bin/UtilityProcess-Debug.exe", "bin-cs-debug"),
  53. ("../../bin/cs/bin/UtilityProcess.exe", "bin-cs"),
  54. ("../../bin/hl/UtilityProcess.hl", "bin-hl"),
  55. ("../../bin/lua/UtilityProcess.lua", "bin-lua"),
  56. ("../../bin/java/UtilityProcess-Debug.jar", "bin-java-debug"),
  57. ("../../bin/java/UtilityProcess.jar", "bin-java"),
  58. ("../../bin/jvm/UtilityProcess-Debug.jar", "bin-jvm-debug"),
  59. ("../../bin/jvm/UtilityProcess.jar", "bin-jvm"),
  60. ("../../bin/neko/UtilityProcess.n", "bin-neko"),
  61. ("../../bin/php/UtilityProcess/index.php", "bin-php"),
  62. ("../../bin/python/UtilityProcess.py", "bin-py"),
  63. ("../../src/UtilityProcess.hx", "bin-eval")
  64. ]:
  65. os.symlink(target, os.path.join(TESTDIR, data, name), target_is_directory = False)
  66. # files
  67. os.mkdir(os.path.join(TESTDIR, "b"))
  68. for data in allFilenames:
  69. with open(os.path.join(TESTDIR, "b", data), "wb") as f:
  70. f.write(allBinary)