18 Commits

Author SHA1 Message Date
Koichi ITO
f4c16c57aa [ruby/optparse] Make the result of tty? obtainable with flexible stdout
In mock testing for stdout, `StringIO.new` is sometimes used to redirect the output.
In such cases, the assignment is done with `$stdout = StringIO.new`, not the constant `STDOUT`.
e.g., https://github.com/rubocop/rubocop/blob/v1.71.1/lib/rubocop/rspec/shared_contexts.rb#L154-L164

After assigning `StringIO.new`, `$stdout.tty?` returns `false`,
allowing the standard output destination to be switched during test execution.

```ruby
STDOUT.tty?       # => true
StringIO.new.tty? # => false
```

However, since `STDOUT.tty?` returns `true`, a failure occurred in environments
where the environment variables `RUBY_PAGER` or `PAGER` are set.
e.g., https://github.com/rubocop/rubocop/pull/13784

To address this, `STDOUT` has been updated to `$stdout` so that the result of `tty?` can be flexibly overridden.

A potential concern is that `$stdout`, unlike `STDOUT`,
does not always represent the standard output at the time the Ruby process started.
However, no concrete examples of issues related to this have been identified.

`STDOUT.tty?` is the logic of optparse introduced in https://github.com/ruby/optparse/pull/70.

This PR replaces `STDOUT` with `$stdout` throughout, based on the assumption
that `$stdout` is sufficient for use with optparse.

https://github.com/ruby/optparse/commit/262cf6f9ac
2025-03-10 10:19:58 +00:00
fatkodima
a35d324862 [ruby/optparse] Fix parsing array arguments with :into option
https://github.com/ruby/optparse/commit/19700e96d8
2024-08-05 02:28:12 +00:00
Nobuyoshi Nakada
5d76fe6b2a [ruby/optparse] Invoke pager for --help
https://github.com/ruby/optparse/commit/77dccce37c
2024-03-01 07:10:08 +00:00
Nobuyoshi Nakada
41c0fb6991 [ruby/optparse] Add exact: keyword argument
https://github.com/ruby/optparse/commit/07e83673a8
2024-02-23 21:16:59 +09:00
Nobuyoshi Nakada
2c6767b71e [ruby/optparse] Respect default values in block parameters
Fix https://github.com/ruby/optparse/pull/55

https://github.com/ruby/optparse/commit/9d53e74aa4
2024-02-09 19:58:19 +09:00
fatkodima
f7a407cabd [ruby/optparse] Fix require_exact to work with options defined as --[no]-something
https://github.com/ruby/optparse/commit/4e346ad337
2024-02-09 03:31:13 +00:00
Nobuyoshi Nakada
502ca37dde [ruby/optparse] The encoding argument of Regexp.new has been ignored since 1.9
https://github.com/ruby/optparse/commit/766f567405
2022-12-21 14:09:12 +09:00
Yusuke Endoh
f3ad68dd16 [ruby/optparse] Fix the test failure i ruby/ruby
```
$ make test-all TESTS=test/optparse/
...

[148/178] TestOptionParserDidYouMean#test_raise_unknown = 0.00 s
  1) Failure:
TestOptionParserDidYouMean#test_raise_unknown [/home/mame/work/ruby/test/optparse/test_optparse.rb:106]:
<["--bar"]> expected but was
<[]>.
```

In the old test/unit (bundled in ruby/ruby), when a test class inherits from
another test class, the child class runs all the tests defined in the parent
class.
However, it looks like the new test/unit does not do so. This is because the
test failure does not occur in ruby/optparse.

As a tentative solution, this changes the option names in TestOptionParser to
avoid the name conflict with TestOptionParserDidYouMean.

https://github.com/ruby/optparse/commit/fee86ef7a4
2022-11-28 16:20:40 +00:00
Nobuyoshi Nakada
0bfb185654 [ruby/optparse] Add raise_unknown flag
(https://github.com/ruby/optparse/pull/38)

https://github.com/ruby/optparse/commit/12529653cd
2022-11-28 14:24:06 +00:00
Nobuyoshi Nakada
e8317d90b0
[ruby/optparse] Fixed error message of unparsed non-option
Close https://github.com/ruby/optparse/issues/3

https://github.com/ruby/optparse/commit/94c5cf4032
2021-03-29 19:37:24 +09:00
Jeremy Evans
eca8ffaa0b
[ruby/optparse] Add OptionParser#require_exact accessor
This allows you to disable allowing abbreviations of long options
and using short options for long options.

Implements Ruby Feature #11523

https://github.com/ruby/optparse/commit/dfefb2d2e2
2021-03-29 15:55:41 +09:00
nobu
30d23ec903 multiple arguments to write
Make write methods of IO-like objects accept multiple arguments,
as well as IO#write.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60383 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-23 14:05:07 +00:00
nobu
49684589cd optparse.rb: into kwdarg
* lib/optparse.rb (OptionParser#order!): add `into` optional
  keyword argument to store the results.  [Feature #11191]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53444 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-01-06 08:23:10 +00:00
naruse
3e92b635fb Add frozen_string_literal: false for all files
When you change this to true, you may need to add more tests.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53141 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-12-16 05:07:31 +00:00
nobu
b5550361c9 test_optparse.rb: skip no_error in backtrace
* test/optparse/test_optparse.rb (TestOptionParser#assert_no_error):
  prefix with assert_ so it will be skipped in backtrace.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40041 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-04-01 15:00:36 +00:00
nobu
de1e4881d4 * lib/optparse.rb (Regexp): fix incorrect options when casting to
a Regexp, and suppress encoding option warnings.
  https://github.com/ruby/ruby/pull/82


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34316 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-01-16 07:42:01 +00:00
nobu
a20f1713c3 * lib/optparse.rb (OptionParser#parse_in_order): do not make an
option from non-option argument.  [ruby-dev:38333]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23286 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-04-26 06:13:11 +00:00
nobu
4dada1c8a2 * lib/optparse.rb (OptionParser::Switch::PlacedArgument::parse):
do not remove next argument if empty value is placed.

* test/optparse: added.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4903 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-11-05 10:09:58 +00:00