|
| 1 | +// @ts-check |
| 2 | + |
| 3 | +const assert = require("assert"); |
| 4 | +const child_process = require("child_process"); |
| 5 | + |
| 6 | +const cliHelp = |
| 7 | + "Usage: rescript <options> <subcommand>\n" + |
| 8 | + "\n" + |
| 9 | + "`rescript` is equivalent to `rescript build`\n" + |
| 10 | + "\n" + |
| 11 | + "Options:\n" + |
| 12 | + " -v, -version display version number\n" + |
| 13 | + " -h, -help display help\n" + |
| 14 | + "\n" + |
| 15 | + "Subcommands:\n" + |
| 16 | + " build\n" + |
| 17 | + " clean\n" + |
| 18 | + " format\n" + |
| 19 | + " convert\n" + |
| 20 | + " dump\n" + |
| 21 | + " help\n" + |
| 22 | + "\n" + |
| 23 | + "Run `rescript <subcommand> -h` for subcommand help. Examples:\n" + |
| 24 | + " rescript build -h\n" + |
| 25 | + " rescript format -h\n" + |
| 26 | + "The default `rescript` is equivalent to `rescript build` subcommand\n" + |
| 27 | + "\n"; |
| 28 | + |
| 29 | +const buildHelp = |
| 30 | + "Usage: rescript build <options> -- <ninja_options>\n" + |
| 31 | + "\n" + |
| 32 | + "`rescript build` builds the project with dependencies\n" + |
| 33 | + "\n" + |
| 34 | + "`rescript -- -h` for Ninja options (internal usage only; unstable)\n" + |
| 35 | + "\n" + |
| 36 | + "Options:\n" + |
| 37 | + " -w Watch mode\n" + |
| 38 | + " -ws [host]:port set up host & port for WebSocket build notifications\n" + |
| 39 | + " -verbose Set the output to be verbose\n" + |
| 40 | + " -with-deps *deprecated* This is the default behavior now. This option will be removed in a future release\n"; |
| 41 | + |
| 42 | +const cleanHelp = |
| 43 | + "Usage: rescript clean <options>\n" + |
| 44 | + "\n" + |
| 45 | + "`rescript clean` cleans build artifacts\n" + |
| 46 | + "\n" + |
| 47 | + "Options:\n" + |
| 48 | + " -verbose Set the output to be verbose\n" + |
| 49 | + " -with-deps *deprecated* This is the default behavior now. This option will be removed in a future release\n"; |
| 50 | + |
| 51 | +const formatHelp = |
| 52 | + "Usage: rescript format <options> [files]\n" + |
| 53 | + "\n" + |
| 54 | + "`rescript format` formats the current directory\n" + |
| 55 | + "\n" + |
| 56 | + "Options:\n" + |
| 57 | + " -stdin [.res|.resi|.ml|.mli] Read the code from stdin and print\n" + |
| 58 | + " the formatted code to stdout in ReScript syntax\n" + |
| 59 | + " -all Format the whole project \n" + |
| 60 | + " -check Check formatting for file or the whole project. Use `-all` to check the whole project\n"; |
| 61 | + |
| 62 | +const convertHelp = |
| 63 | + "Usage: rescript convert <options> [files]\n" + |
| 64 | + "\n" + |
| 65 | + "`rescript convert` converts the current directory\n" + |
| 66 | + "\n" + |
| 67 | + "**This command removes old OCaml files and creates new ReScript \n" + |
| 68 | + "files. Make sure your work is saved first!**\n" + |
| 69 | + "\n" + |
| 70 | + "Options:\n" + |
| 71 | + " -all Convert the whole project\n"; |
| 72 | + |
| 73 | +const dumpHelp = |
| 74 | + "Usage: rescript dump <options> [target]\n" + |
| 75 | + "`rescript dump` dumps the information for the target\n"; |
| 76 | + |
| 77 | +// Shows build help with --help arg |
| 78 | +let out = child_process.spawnSync(`../../../rescript`, ["build", "--help"], { |
| 79 | + encoding: "utf8", |
| 80 | + cwd: __dirname, |
| 81 | +}); |
| 82 | +assert.equal(out.stdout, buildHelp); |
| 83 | + |
| 84 | +// Shows build help with -h arg |
| 85 | +out = child_process.spawnSync(`../../../rescript`, ["build", "-h"], { |
| 86 | + encoding: "utf8", |
| 87 | + cwd: __dirname, |
| 88 | +}); |
| 89 | +assert.equal(out.stdout, buildHelp); |
| 90 | + |
| 91 | +// Exits with build help with unknown arg |
| 92 | +out = child_process.spawnSync(`../../../rescript`, ["build", "-wtf"], { |
| 93 | + encoding: "utf8", |
| 94 | + cwd: __dirname, |
| 95 | +}); |
| 96 | +assert.equal(out.stderr, "Error: unknown option: '-wtf'.\n" + buildHelp + "\n"); |
| 97 | + |
| 98 | +// Shows cli help with --help arg |
| 99 | +out = child_process.spawnSync(`../../../rescript`, ["--help"], { |
| 100 | + encoding: "utf8", |
| 101 | + cwd: __dirname, |
| 102 | +}); |
| 103 | +assert.equal(out.stdout, cliHelp); |
| 104 | + |
| 105 | +// Shows cli help with -h arg |
| 106 | +out = child_process.spawnSync(`../../../rescript`, ["-h"], { |
| 107 | + encoding: "utf8", |
| 108 | + cwd: __dirname, |
| 109 | +}); |
| 110 | +assert.equal(out.stdout, cliHelp); |
| 111 | + |
| 112 | +// Shows cli help with help command |
| 113 | +out = child_process.spawnSync(`../../../rescript`, ["help"], { |
| 114 | + encoding: "utf8", |
| 115 | + cwd: __dirname, |
| 116 | +}); |
| 117 | +assert.equal(out.stdout, cliHelp); |
| 118 | + |
| 119 | +// Shows cli help with unknown command |
| 120 | +out = child_process.spawnSync(`../../../rescript`, ["built"], { |
| 121 | + encoding: "utf8", |
| 122 | + cwd: __dirname, |
| 123 | +}); |
| 124 | +// Should write to stderr instead ??? |
| 125 | +assert.equal(out.stdout, cliHelp); |
| 126 | + |
| 127 | +// Shows cli help with unknown args |
| 128 | +out = child_process.spawnSync(`../../../rescript`, ["-w"], { |
| 129 | + encoding: "utf8", |
| 130 | + cwd: __dirname, |
| 131 | +}); |
| 132 | +// Should write to stderr instead ??? |
| 133 | +assert.equal(out.stdout, cliHelp); |
| 134 | + |
| 135 | +// Shows clean help with --help arg |
| 136 | +out = child_process.spawnSync(`../../../rescript`, ["clean", "--help"], { |
| 137 | + encoding: "utf8", |
| 138 | + cwd: __dirname, |
| 139 | +}); |
| 140 | +assert.equal(out.stdout, cleanHelp); |
| 141 | + |
| 142 | +// Shows clean help with -h arg |
| 143 | +out = child_process.spawnSync(`../../../rescript`, ["clean", "-h"], { |
| 144 | + encoding: "utf8", |
| 145 | + cwd: __dirname, |
| 146 | +}); |
| 147 | +assert.equal(out.stdout, cleanHelp); |
| 148 | + |
| 149 | +// Exits with clean help with unknown arg |
| 150 | +out = child_process.spawnSync(`../../../rescript`, ["clean", "-wtf"], { |
| 151 | + encoding: "utf8", |
| 152 | + cwd: __dirname, |
| 153 | +}); |
| 154 | +assert.equal(out.stderr, "Error: unknown option: '-wtf'.\n" + cleanHelp + "\n"); |
| 155 | + |
| 156 | +// Shows format help with --help arg |
| 157 | +out = child_process.spawnSync(`../../../rescript`, ["format", "--help"], { |
| 158 | + encoding: "utf8", |
| 159 | + cwd: __dirname, |
| 160 | +}); |
| 161 | +// Note: it writes to stderr |
| 162 | +assert.equal(out.stderr, formatHelp); |
| 163 | + |
| 164 | +// Shows format help with -h arg |
| 165 | +out = child_process.spawnSync(`../../../rescript`, ["format", "-h"], { |
| 166 | + encoding: "utf8", |
| 167 | + cwd: __dirname, |
| 168 | +}); |
| 169 | +// Note: it writes to stderr |
| 170 | +assert.equal(out.stderr, formatHelp); |
| 171 | + |
| 172 | +// Shows convert help with --help arg |
| 173 | +out = child_process.spawnSync(`../../../rescript`, ["convert", "--help"], { |
| 174 | + encoding: "utf8", |
| 175 | + cwd: __dirname, |
| 176 | +}); |
| 177 | +// Note: it writes to stderr |
| 178 | +assert.equal(out.stderr, convertHelp); |
| 179 | + |
| 180 | +// Shows convert help with -h arg |
| 181 | +out = child_process.spawnSync(`../../../rescript`, ["convert", "-h"], { |
| 182 | + encoding: "utf8", |
| 183 | + cwd: __dirname, |
| 184 | +}); |
| 185 | +// Note: it writes to stderr |
| 186 | +assert.equal(out.stderr, convertHelp); |
| 187 | + |
| 188 | +// Shows dump help with --help arg |
| 189 | +out = child_process.spawnSync(`../../../rescript`, ["dump", "--help"], { |
| 190 | + encoding: "utf8", |
| 191 | + cwd: __dirname, |
| 192 | +}); |
| 193 | +// Note: it writes to stderr |
| 194 | +assert.equal(out.stderr, dumpHelp); |
| 195 | + |
| 196 | +// Shows dump help with -h arg |
| 197 | +out = child_process.spawnSync(`../../../rescript`, ["dump", "-h"], { |
| 198 | + encoding: "utf8", |
| 199 | + cwd: __dirname, |
| 200 | +}); |
| 201 | +// Note: it writes to stderr |
| 202 | +assert.equal(out.stderr, dumpHelp); |
0 commit comments