-
-
Notifications
You must be signed in to change notification settings - Fork 13k
edit 1.1.0 (new formula) #225837
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
base: main
Are you sure you want to change the base?
edit 1.1.0 (new formula) #225837
Conversation
Thanks for contributing to Homebrew! 🎉 It looks like you're having trouble with a CI failure. See our contribution guide for help. You may be most interested in the section on dealing with CI failures. You can find the CI logs in the Checks tab of your pull request. |
end | ||
|
||
test do | ||
system bin/"edit", "--version" |
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.
We need a test that exercises the some of the functionality of the app. Version checks or usage checks (foo --version or foo --help) are not sufficient, as explained in the formula cookbook.
In most cases, a good test would involve running a simple test case: run #{bin}/foo input.txt.
- Then you can check that the output is as expected (with assert_equal or assert_match on the output of shell_output)
- You can also check that an output file was created, if that is expected: assert_predicate testpath/"output.txt", :exist?
Some advice for specific cases:
- If the formula is a library, compile and run some simple code that links against it. It could be taken from upstream's documentation / source examples.
- If the formula is for a GUI program, try to find some function that runs as command-line only, like a format conversion, reading or displaying a config file, etc.
- If the software cannot function without credentials, a test could be to try to connect with invalid credentials (or without credentials) and confirm that it fails as expected.
- Same if the software requires a virtual machine, docker instance, etc. to be running.
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.
I did take note of this when defining the formula. The edit package is very similar to the 'nano' text editor and has very limited options/switches:
PS C:\Users\****> edit -h
Usage: edit [OPTIONS] [FILE[:LINE[:COLUMN]]]
Options:
-h, --help Print this help message
-v, --version Print the version number
Arguments:
FILE[:LINE[:COLUMN]] The file to open, optionally with line and column (e.g., foo.txt:123:45)
I looked at the nano formula for inspiration but see that only a basic version test is performed.
homebrew-core/Formula/n/nano.rb
Lines 43 to 45 in 4387fac
test do | |
system bin/"nano", "--version" | |
end |
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.
nano also pre-dates edit by a long time. When we introduce new requirement we don't backport all of them. Is there no way to start edit and send a key combination to close it after a couple of seconds? That way we would be sure it works.
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 is possible to close an unedited file with ctrl + q
. Would you be able to suggest a formula that shows how to send keyboard combinations?
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.
I've found the amp text editor which looks like it has a test a can replicate.
homebrew-core/Formula/a/amp.rb
Lines 33 to 56 in 54f1e28
test do | |
require "pty" | |
require "io/console" | |
PTY.spawn(bin/"amp", "test.txt") do |r, w, _pid| | |
r.winsize = [80, 43] | |
sleep 1 | |
# switch to insert mode and add data | |
w.write "i" | |
sleep 1 | |
w.write "test data" | |
sleep 1 | |
# escape to normal mode, save the file, and quit | |
w.write "\e" | |
sleep 1 | |
w.write "s" | |
sleep 1 | |
w.write "Q" | |
begin | |
r.read | |
rescue Errno::EIO | |
# GNU/Linux raises EIO when read is done on closed pty | |
end | |
end |
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.
Haven't written or reviewed much Rust code but it seems like edit only accepts individual [a-zA-Z0-9 ]
characters through stdin (https://github.com/microsoft/edit/blob/main/src/tui.rs#L543-L554) so sending "\u0013" doesn't work because it gets filtered out. Nor can I find any alternate routes like an auto-save option, or sigints, etc.
Seems like the only options going forward, assuming the test is a genuine blocker, would be to:
-
Submit a PR to https://github.com/microsoft/edit/ to permit ctrl-modified inputs through stdin.
-
Update the test to launch edit in such a way where keyboard inputs can be sent programmatically.
-
Yoink whatever tests the other package managers are using, if any.
EDIT: Nevermind, it seems like stdin is first run through a tokeniser and Ctrl characters are extracted and turned into keyboard inputs (https://github.com/microsoft/edit/blob/main/src/input.rs#L333-L343), which is what the earlier link is iterating over. I honestly have no clue why this isn't working other than perhaps the application isn't starting up correctly or not ticking?
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.
Arch Linux's check
simply runs cargo test --frozen
. I think it's feasible for us to do that.
check() {
cd "$pkgname"
cargo test --frozen
}
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.
I just tested it out and I'm getting an error. I couldn't find any formula using cargo test
so I'm not sure how to proceed.
% brew test edit
==> Testing edit
==> cargo test --frozen
Last 15 lines from /Users/adminaccount/Library/Logs/Homebrew/edit/test.01.cargo:
2025-07-25 17:13:34 +0300
cargo
test
--frozen
error: could not find `Cargo.toml` in `/private/tmp/edit-test-20250725-4552-lw4ems` or any parent directory
Error: edit: failed
Warning: Removed Sorbet lines from backtrace!
Rerun with `--verbose` to see the original backtrace
An exception occurred within a child process:
BuildError: Failed executing: cargo test --frozen
/opt/homebrew/Library/Homebrew/formula.rb:3118:in 'block in Formula#system'
/opt/homebrew/Library/Homebrew/formula.rb:3054:in 'IO.open'
/opt/homebrew/Library/Homebrew/formula.rb:3054:in 'Formula#system'
/opt/homebrew/Library/Taps/homebrew/homebrew-core/Formula/e/edit.rb:16:in 'block in <class:Edit>'
/opt/homebrew/Library/Homebrew/formula.rb:2842:in 'block (3 levels) in Formula#run_test'
/opt/homebrew/Library/Homebrew/extend/kernel.rb:565:in 'Kernel#with_env'
/opt/homebrew/Library/Homebrew/formula.rb:2841:in 'block (2 levels) in Formula#run_test'
/opt/homebrew/Library/Homebrew/formula.rb:1194:in 'Formula#with_logging'
/opt/homebrew/Library/Homebrew/formula.rb:2840:in 'block in Formula#run_test'
/opt/homebrew/Library/Homebrew/mktemp.rb:88:in 'block in Mktemp#run'
/opt/homebrew/Library/Homebrew/mktemp.rb:88:in 'Dir.chdir'
/opt/homebrew/Library/Homebrew/mktemp.rb:88:in 'Mktemp#run'
/opt/homebrew/Library/Homebrew/formula.rb:3180:in 'Formula#mktemp'
/opt/homebrew/Library/Homebrew/formula.rb:2834:in 'Formula#run_test'
/opt/homebrew/Library/Homebrew/test.rb:48:in 'block in <main>'
/opt/homebrew/Library/Homebrew/vendor/portable-ruby/3.4.5/lib/ruby/3.4.0/timeout.rb:185:in 'block in Timeout.timeout'
/opt/homebrew/Library/Homebrew/vendor/portable-ruby/3.4.5/lib/ruby/3.4.0/timeout.rb:38:in 'Timeout::Error.handle_timeout'
/opt/homebrew/Library/Homebrew/vendor/portable-ruby/3.4.5/lib/ruby/3.4.0/timeout.rb:194:in 'Timeout.timeout'
/opt/homebrew/Library/Homebrew/test.rb:54:in '<main>'
test do
system "cargo", "test", "--frozen"
end
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.
I just tested it out and I'm getting an error. I couldn't find any formula using
cargo test
so I'm not sure how to proceed.
When you run a test, the cwd is a temporary folder somewhere with essentially nothing in it, so the 'edit' source code isn't there to run the Cargo tests on. You'll need to run on wherever Homebrew has stored the source code, assuming that it has stored the source code and that this is possible to ascertain. You could also re-clone the source with a depth of 1?
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 that explains why cargo test
is never used to test Homebrew packages. Re-cloning is probably not a good idea because we want to test the edit
that Homebrew compiled already compiled.
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.
probably better as ms-edit or microsoft-edit per https://repology.org/project/microsoft-edit/versions
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.
There's a section on the https://github.com/microsoft/edit readme that mentions this:
The canonical executable name is "edit" and the alternative name is "msedit". We're aware of the potential conflict of "edit" with existing commands and recommend alternatively naming packages and executables "msedit". Names such as "ms-edit" should be avoided. Assigning an "edit" alias is recommended, if possible.
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.
Pretty sure @chenrui333 is talking about the formula name, not the executable that users would run.
Also, brew search edit
already surfaces 18 matching formulae, so I agree that edit
as a formula name is way too ambiguous and would actually hurt discovery compared to microsoft-edit
.
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
- For Homebrew#225837 - Fixes microsoft/edit#506 Co-authored-by: Luke Thomas <[email protected]>
HOMEBREW_NO_INSTALL_FROM_API=1 brew install --build-from-source <formula>
, where<formula>
is the name of the formula you're submitting?Only on a Linux environment.
brew test <formula>
, where<formula>
is the name of the formula you're submitting?brew audit --strict <formula>
(after doingHOMEBREW_NO_INSTALL_FROM_API=1 brew install --build-from-source <formula>
)? If this is a new formula, does it passbrew audit --new <formula>
?