cli.rs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. use std::process::Command;
  2. #[test]
  3. fn test_help() {
  4. let output = Command::new("target/debug/image-tiler")
  5. .args(&["--help"])
  6. .output()
  7. .expect("image-tiler should be executable");
  8. let stdout = String::from_utf8(output.stdout).expect("output of image-tiler should be UTF-8");
  9. assert!(output.status.success());
  10. let expected_stdout = "\
  11. Program to generate a larger image made up of different image tiles of the same size
  12. Usage: image-tiler [OPTIONS] <ROWS> <COLS>
  13. Arguments:
  14. <ROWS>
  15. Number of rows
  16. <COLS>
  17. Number of columns
  18. Options:
  19. -b, --border <CONNECTOR_NAME>
  20. Optional connector name that tiles must exhibit towards the border of the image; if this
  21. option is omitted, bordering tiles may have any connection towards the border
  22. -c, --config <PATH>
  23. Optional path to a tile configuration file; overrides any configuration file in the tile
  24. directory
  25. -d, --tile-directory <PATH>
  26. Optional path to a tile directory; if omitted, assume the current working directory.
  27. The directory may contain a tile configuration file named “config.yaml”.
  28. -m, --missing-tile-policy <MISSING_TILE_POLICY>
  29. Optional policy name that specifies how to behave in case there is no
  30. tile with a required connectors list.
  31. MISSING_TILE_POLICY may have one of the following values:
  32. - avoid: Try to avoid leaving empty positions in the tile grid. This may
  33. take a considerable amount of time and memory to finish due to
  34. backtracking. The run may terminate unsuccessfully in case
  35. there is no solution.
  36. - exit: (default) Exit immediately if there is no fitting tile; this
  37. may be useful for debugging tile configurations.
  38. [default: exit]
  39. [possible values: avoid, exit]
  40. -n, --no-config
  41. Do not use any user defined tile configuration; Instead, assume all tiles have the
  42. connectors { north: “c”, south: “c”, east: “c”, west: “c” } and a weight of 1
  43. -o, --output <PATH>
  44. Path to the output file (default: output/tiled)
  45. [default: output/tiled]
  46. -t, --tile-type <TILE_TYPE>
  47. Optional type of tiles; if omitted, the type is guessed by inspecting
  48. the tile configuration (see option “--config”).
  49. TILE_TYPE may have one of the following values:
  50. - raster: raster graphics tiles, e.g. PNG, JPEG or GIF
  51. - svg: SVG (Scalable Vector Graphics) tiles
  52. - text: text based tiles, e.g. for ASCII art
  53. [possible values: raster, svg, text]
  54. -v, --vacancy-policy <VACANCY_POLICY>
  55. Optional policy name that specifies how to handle vacant areas.
  56. VACANCY_POLICY may have one of the following values:
  57. - avoid: Try to avoid leaving vacant areas in the tile grid. This may
  58. take a considerable amount of time and memory to finish due
  59. to backtracking. The run may terminate unsuccessfully in
  60. case there is no solution.
  61. - avoid-strict: Same as avoid, but searches the entire problem space for
  62. a valid solution, if necessary, which might be slow.
  63. - ignore: (default) Ignore and vacant areas in the tile grid untouched.
  64. [default: ignore]
  65. [possible values: avoid, avoid-strict, ignore]
  66. -h, --help
  67. Print help (see a summary with '-h')
  68. -V, --version
  69. Print version
  70. ";
  71. assert_eq!(stdout, expected_stdout);
  72. assert_eq!(output.stderr.len(), 0);
  73. }
  74. #[test]
  75. fn check_that_parameters_config_and_no_config_are_not_passed_together() {
  76. let output = Command::new("target/debug/image-tiler")
  77. .args(&["-c", "file.yaml", "-n"])
  78. .output()
  79. .expect("failed to execute command");
  80. let stderr = String::from_utf8(output.stderr).expect("output of image-tiler should be UTF-8");
  81. assert_eq!(output.status.code(), Some(2));
  82. assert_eq!(output.stdout.len(), 0);
  83. let expected_stderr = "\
  84. error: the argument '--config <PATH>' cannot be used with '--no-config'
  85. Usage: image-tiler --config <PATH> <ROWS> <COLS>
  86. For more information, try '--help'.
  87. ";
  88. assert_eq!(stderr, expected_stderr);
  89. }