-
Notifications
You must be signed in to change notification settings - Fork 468
Fix compile status with help command #6439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
cknitt
merged 7 commits into
rescript-lang:master
from
DZakh-forks:fix-compile-status-in-help
Oct 30, 2023
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c6de8a7
Fx compile status with help command
DZakh 8396247
Update changelog
DZakh bbaf8ca
Update tests
DZakh 71ec60a
Improve cli consistency
DZakh df001a7
Finish cli help consistency improvements
DZakh b04113b
Update changelog
DZakh f1d4059
Fix build help
DZakh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// @ts-check | ||
|
||
const assert = require("assert"); | ||
const child_process = require("child_process"); | ||
|
||
// Shows compile time for `rescript build` command | ||
let out = child_process.spawnSync(`../../../rescript`, ["build"], { | ||
encoding: "utf8", | ||
cwd: __dirname, | ||
}); | ||
assert.match( | ||
out.stdout, | ||
new RegExp(`>>>> Start compiling | ||
Dependency Finished | ||
>>>> Finish compiling \\d+ mseconds`) | ||
); | ||
|
||
// Shows compile time for `rescript` command | ||
out = child_process.spawnSync(`../../../rescript`, { | ||
encoding: "utf8", | ||
cwd: __dirname, | ||
}); | ||
assert.match( | ||
out.stdout, | ||
new RegExp(`>>>> Start compiling | ||
Dependency Finished | ||
>>>> Finish compiling \\d+ mseconds`) | ||
); | ||
|
||
// Doesn't show compile time for `rescript build -verbose` command | ||
// Because we can't be sure that -verbose is a valid argument | ||
// And bsb won't fail with a usage message. | ||
// It works this way not only for -verbose, but any other arg, including -h/--help/-help | ||
out = child_process.spawnSync(`../../../rescript`, ["build", "-verbose"], { | ||
encoding: "utf8", | ||
cwd: __dirname, | ||
}); | ||
assert.match( | ||
out.stdout, | ||
new RegExp( | ||
`Package stack: test \nDependency Finished\nninja.exe -C lib/bs \n` | ||
) | ||
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name": "test", | ||
"version": "0.1.0", | ||
"sources": [] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,243 @@ | ||
// @ts-check | ||
|
||
const assert = require("assert"); | ||
const child_process = require("child_process"); | ||
|
||
const cliHelp = | ||
"Usage: rescript <options> <subcommand>\n" + | ||
"\n" + | ||
"`rescript` is equivalent to `rescript build`\n" + | ||
"\n" + | ||
"Options:\n" + | ||
" -v, -version display version number\n" + | ||
" -h, -help display help\n" + | ||
"\n" + | ||
"Subcommands:\n" + | ||
" build\n" + | ||
" clean\n" + | ||
" format\n" + | ||
" convert\n" + | ||
" dump\n" + | ||
" help\n" + | ||
"\n" + | ||
"Run `rescript <subcommand> -h` for subcommand help. Examples:\n" + | ||
" rescript build -h\n" + | ||
" rescript format -h\n"; | ||
|
||
const buildHelp = | ||
"Usage: rescript build <options> -- <ninja_options>\n" + | ||
"\n" + | ||
"`rescript build` builds the project with dependencies\n" + | ||
"\n" + | ||
"`rescript build -- -h` for Ninja options (internal usage only; unstable)\n" + | ||
"\n" + | ||
"Options:\n" + | ||
" -w Watch mode\n" + | ||
" -ws [host]:port set up host & port for WebSocket build notifications\n" + | ||
" -verbose Set the output to be verbose\n" + | ||
" -with-deps *deprecated* This is the default behavior now. This option will be removed in a future release\n"; | ||
|
||
const cleanHelp = | ||
"Usage: rescript clean <options>\n" + | ||
"\n" + | ||
"`rescript clean` cleans build artifacts\n" + | ||
"\n" + | ||
"Options:\n" + | ||
" -verbose Set the output to be verbose\n" + | ||
" -with-deps *deprecated* This is the default behavior now. This option will be removed in a future release\n"; | ||
|
||
const formatHelp = | ||
"Usage: rescript format <options> [files]\n" + | ||
"\n" + | ||
"`rescript format` formats the current directory\n" + | ||
"\n" + | ||
"Options:\n" + | ||
" -stdin [.res|.resi|.ml|.mli] Read the code from stdin and print\n" + | ||
" the formatted code to stdout in ReScript syntax\n" + | ||
" -all Format the whole project \n" + | ||
" -check Check formatting for file or the whole project. Use `-all` to check the whole project\n"; | ||
|
||
const convertHelp = | ||
"Usage: rescript convert <options> [files]\n" + | ||
"\n" + | ||
"`rescript convert` converts the current directory\n" + | ||
"\n" + | ||
"**This command removes old OCaml files and creates new ReScript \n" + | ||
"files. Make sure your work is saved first!**\n" + | ||
"\n" + | ||
"Options:\n" + | ||
" -all Convert the whole project\n"; | ||
|
||
const dumpHelp = | ||
"Usage: rescript dump <options> [target]\n" + | ||
"`rescript dump` dumps the information for the target\n"; | ||
|
||
// Shows build help with --help arg | ||
let out = child_process.spawnSync(`../../../rescript`, ["build", "--help"], { | ||
encoding: "utf8", | ||
cwd: __dirname, | ||
}); | ||
assert.equal(out.stdout, buildHelp); | ||
assert.equal(out.stderr, ""); | ||
assert.equal(out.status, 0); | ||
|
||
// FIXME: Help works incorrectly in watch mode | ||
out = child_process.spawnSync(`../../../rescript`, ["build", "-w", "--help"], { | ||
encoding: "utf8", | ||
cwd: __dirname, | ||
}); | ||
// FIXME: Shouldn't have "Start compiling" for help | ||
assert.equal(out.stdout, ">>>> Start compiling\n" + buildHelp); | ||
// FIXME: Don't run the watcher when showing help | ||
assert.match( | ||
out.stderr, | ||
new RegExp( | ||
"Uncaught Exception Error: ENOENT: no such file or directory, watch 'bsconfig.json'\n" | ||
) | ||
); | ||
// FIXME: Should be 0 | ||
assert.equal(out.status, 1); | ||
|
||
// Shows build help with -h arg | ||
out = child_process.spawnSync(`../../../rescript`, ["build", "-h"], { | ||
encoding: "utf8", | ||
cwd: __dirname, | ||
}); | ||
assert.equal(out.stdout, buildHelp); | ||
assert.equal(out.stderr, ""); | ||
assert.equal(out.status, 0); | ||
|
||
// Exits with build help with unknown arg | ||
out = child_process.spawnSync(`../../../rescript`, ["build", "-wtf"], { | ||
encoding: "utf8", | ||
cwd: __dirname, | ||
}); | ||
assert.equal(out.stdout, ""); | ||
assert.equal(out.stderr, 'Error: Unknown option "-wtf".\n' + buildHelp); | ||
assert.equal(out.status, 2); | ||
|
||
// Shows cli help with --help arg | ||
out = child_process.spawnSync(`../../../rescript`, ["--help"], { | ||
encoding: "utf8", | ||
cwd: __dirname, | ||
}); | ||
assert.equal(out.stdout, cliHelp); | ||
assert.equal(out.stderr, ""); | ||
assert.equal(out.status, 0); | ||
|
||
// Shows cli help with -h arg | ||
out = child_process.spawnSync(`../../../rescript`, ["-h"], { | ||
encoding: "utf8", | ||
cwd: __dirname, | ||
}); | ||
assert.equal(out.stdout, cliHelp); | ||
assert.equal(out.stderr, ""); | ||
assert.equal(out.status, 0); | ||
|
||
// Shows cli help with help command | ||
out = child_process.spawnSync(`../../../rescript`, ["help"], { | ||
encoding: "utf8", | ||
cwd: __dirname, | ||
}); | ||
assert.equal(out.stdout, cliHelp); | ||
assert.equal(out.stderr, ""); | ||
assert.equal(out.status, 0); | ||
|
||
// Shows cli help with unknown command | ||
out = child_process.spawnSync(`../../../rescript`, ["built"], { | ||
encoding: "utf8", | ||
cwd: __dirname, | ||
}); | ||
assert.equal(out.stdout, ""); | ||
assert.equal(out.stderr, `Error: Unknown command or flag "built".\n` + cliHelp); | ||
assert.equal(out.status, 2); | ||
|
||
// Shows cli help with unknown args | ||
out = child_process.spawnSync(`../../../rescript`, ["-w"], { | ||
encoding: "utf8", | ||
cwd: __dirname, | ||
}); | ||
assert.equal(out.stdout, ""); | ||
assert.equal(out.stderr, `Error: Unknown command or flag "-w".\n` + cliHelp); | ||
assert.equal(out.status, 2); | ||
|
||
// Shows clean help with --help arg | ||
out = child_process.spawnSync(`../../../rescript`, ["clean", "--help"], { | ||
encoding: "utf8", | ||
cwd: __dirname, | ||
}); | ||
assert.equal(out.stdout, cleanHelp); | ||
assert.equal(out.stderr, ""); | ||
assert.equal(out.status, 0); | ||
|
||
// Shows clean help with -h arg | ||
out = child_process.spawnSync(`../../../rescript`, ["clean", "-h"], { | ||
encoding: "utf8", | ||
cwd: __dirname, | ||
}); | ||
assert.equal(out.stdout, cleanHelp); | ||
assert.equal(out.stderr, ""); | ||
assert.equal(out.status, 0); | ||
|
||
// Exits with clean help with unknown arg | ||
out = child_process.spawnSync(`../../../rescript`, ["clean", "-wtf"], { | ||
encoding: "utf8", | ||
cwd: __dirname, | ||
}); | ||
assert.equal(out.stdout, ""); | ||
assert.equal(out.stderr, 'Error: Unknown option "-wtf".\n' + cleanHelp); | ||
assert.equal(out.status, 2); | ||
|
||
// Shows format help with --help arg | ||
out = child_process.spawnSync(`../../../rescript`, ["format", "--help"], { | ||
encoding: "utf8", | ||
cwd: __dirname, | ||
}); | ||
assert.equal(out.stdout, formatHelp); | ||
assert.equal(out.stderr, ""); | ||
assert.equal(out.status, 0); | ||
|
||
// Shows format help with -h arg | ||
out = child_process.spawnSync(`../../../rescript`, ["format", "-h"], { | ||
encoding: "utf8", | ||
cwd: __dirname, | ||
}); | ||
assert.equal(out.stdout, formatHelp); | ||
assert.equal(out.stderr, ""); | ||
assert.equal(out.status, 0); | ||
|
||
// Shows convert help with --help arg | ||
out = child_process.spawnSync(`../../../rescript`, ["convert", "--help"], { | ||
encoding: "utf8", | ||
cwd: __dirname, | ||
}); | ||
assert.equal(out.stdout, convertHelp); | ||
assert.equal(out.stderr, ""); | ||
assert.equal(out.status, 0); | ||
|
||
// Shows convert help with -h arg | ||
out = child_process.spawnSync(`../../../rescript`, ["convert", "-h"], { | ||
encoding: "utf8", | ||
cwd: __dirname, | ||
}); | ||
assert.equal(out.stdout, convertHelp); | ||
assert.equal(out.stderr, ""); | ||
assert.equal(out.status, 0); | ||
|
||
// Shows dump help with --help arg | ||
out = child_process.spawnSync(`../../../rescript`, ["dump", "--help"], { | ||
encoding: "utf8", | ||
cwd: __dirname, | ||
}); | ||
assert.equal(out.stdout, dumpHelp); | ||
assert.equal(out.stderr, ""); | ||
assert.equal(out.status, 0); | ||
|
||
// Shows dump help with -h arg | ||
out = child_process.spawnSync(`../../../rescript`, ["dump", "-h"], { | ||
encoding: "utf8", | ||
cwd: __dirname, | ||
}); | ||
assert.equal(out.stdout, dumpHelp); | ||
assert.equal(out.stderr, ""); | ||
assert.equal(out.status, 0); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,13 +86,13 @@ let stop_raise ~usage ~(error : error) (speclist : t) = | |
Ext_buffer.output_buffer stdout b; | ||
exit 0 | ||
| Unknown s -> | ||
b +> "unknown option: '"; | ||
b +> "Unknown option \""; | ||
b +> s; | ||
b +> "'.\n" | ||
b +> "\".\n" | ||
| Missing s -> | ||
b +> "option '"; | ||
b +> "Option \""; | ||
b +> s; | ||
b +> "' needs an argument.\n"); | ||
Comment on lines
-89
to
-95
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, the code is not used in my case. I've just decided to make it consistent with bsb_arg.ml. |
||
b +> "\" needs an argument.\n"); | ||
usage_b b ~usage speclist; | ||
bad_arg (Ext_buffer.contents b) | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'll be only possible to fix by moving the args parsing logic in one place. I want to do it when I have more free time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about the other three FIXMEs above? Also something for later?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, they are all caused by one problem