Skip to content

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

edit 1.1.0 (new formula) #225837

wants to merge 2 commits into from

Conversation

Zoobdude
Copy link

@Zoobdude Zoobdude commented Jun 5, 2025

  • Have you followed the guidelines for contributing?
  • Have you ensured that your commits follow the commit style guide?
  • Have you checked that there aren't other open pull requests for the same formula update/change?
  • Have you built your formula locally with 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.
  • Is your test running fine brew test <formula>, where <formula> is the name of the formula you're submitting?
  • Does your build pass brew audit --strict <formula> (after doing HOMEBREW_NO_INSTALL_FROM_API=1 brew install --build-from-source <formula>)? If this is a new formula, does it pass brew audit --new <formula>?

@github-actions github-actions bot added new formula PR adds a new formula to Homebrew/homebrew-core rust Rust use is a significant feature of the PR or issue labels Jun 5, 2025
Copy link
Contributor

github-actions bot commented Jun 5, 2025

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"
Copy link
Member

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.

Copy link
Author

@Zoobdude Zoobdude Jun 5, 2025

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.

test do
system bin/"nano", "--version"
end

Copy link
Member

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.

Copy link
Author

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?

Copy link
Author

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.

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

Copy link

@Protonull Protonull Jul 25, 2025

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?

Copy link
Contributor

@osalbahr osalbahr Jul 25, 2025

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
}

https://gitlab.archlinux.org/archlinux/packaging/packages/msedit/-/blob/main/PKGBUILD?ref_type=heads#L36-39

Copy link
Contributor

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

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?

Copy link
Contributor

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.

@github-actions github-actions bot added the autosquash Automatically squash pull request commits according to Homebrew style. label Jun 5, 2025
Copy link
Member

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

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

@github-actions github-actions bot added the stale No recent activity label Jul 19, 2025
osalbahr added a commit to osalbahr/homebrew-core that referenced this pull request Jul 22, 2025
osalbahr added a commit to osalbahr/homebrew-core that referenced this pull request Jul 22, 2025
@github-actions github-actions bot removed the stale No recent activity label Jul 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosquash Automatically squash pull request commits according to Homebrew style. new formula PR adds a new formula to Homebrew/homebrew-core rust Rust use is a significant feature of the PR or issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants