diff --git a/.github/workflows/mingw.yml b/.github/workflows/mingw.yml index b6704299e55b4c..a3cbf8a458260f 100644 --- a/.github/workflows/mingw.yml +++ b/.github/workflows/mingw.yml @@ -2,10 +2,7 @@ name: MinGW on: [push, pull_request] # Notes: -# Action ENV TEMP and TMP are short 8.3 paths, but the long path differs. -# Code uses TMPDIR, which is Ruby's 'first' check -# -# Console encoding causes issues, see test-all & test-spec steps +# Actions console encoding causes issues, see test-all & test-spec steps # jobs: make: @@ -42,15 +39,15 @@ jobs: git clone --single-branch --depth=50 --branch=${{ github.event.pull_request.head.ref }} https://github.com/${{ github.event.pull_request.head.repo.full_name }} src git -C src reset --hard ${{ github.event.pull_request.head.sha }} if: github.event_name == 'pull_request' + shell: bash - run: ./src/tool/actions-commit-info.sh shell: bash id: commit_info - name: Set up Ruby & MSYS2 - uses: MSP-Greg/actions-ruby@master + uses: MSP-Greg/setup-ruby-pkgs@v1 with: - ruby-version: 2.6.x - base: update - mingw: gdbm gmp libffi libyaml openssl ragel readline + ruby-version: 2.6 + mingw: _upgrade_ gdbm gmp libffi libyaml openssl ragel readline msys2: automake1.16 bison - name: where check run: | @@ -110,14 +107,12 @@ jobs: timeout-minutes: 5 working-directory: build run: | - $env:TMPDIR = "$pwd/../temp" make test - name: test-all timeout-minutes: 50 working-directory: build run: | - $env:TMPDIR = "$pwd/../temp" # Actions uses UTF8, causes test failures, similar to normal OS setup $PSDefaultParameterValues['*:Encoding'] = 'utf8' [Console]::OutputEncoding = [System.Text.Encoding]::GetEncoding("IBM437") @@ -129,8 +124,7 @@ jobs: timeout-minutes: 10 working-directory: src/spec/ruby run: | - $env:TMPDIR = "$pwd/../../../temp" - $env:PATH = "$pwd/../../../install/bin;$env:PATH" + $env:Path = "$pwd/../../../install/bin;$env:Path" # Actions uses UTF8, causes test failures, similar to normal OS setup $PSDefaultParameterValues['*:Encoding'] = 'utf8' [Console]::OutputEncoding = [System.Text.Encoding]::GetEncoding("IBM437") diff --git a/.github/workflows/mjit.yml b/.github/workflows/mjit.yml index 08a659e3e2bd80..fbeed8d925abb1 100644 --- a/.github/workflows/mjit.yml +++ b/.github/workflows/mjit.yml @@ -33,8 +33,9 @@ jobs: id: commit_info - name: Fixed world writable dirs run: | - chmod go-w $HOME + chmod -v go-w $HOME $HOME/.config sudo chmod -R go-w /usr/share + sudo bash -c 'IFS=:; for d in '"$PATH"'; do chmod -v go-w $d; done' || : - name: Set ENV run: | echo '::set-env name=JOBS::'-j$((1 + $(nproc --all))) diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index c98d05c1d78134..27ce6ae68257f5 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -39,15 +39,16 @@ jobs: id: commit_info - name: Fixed world writable dirs run: | - chmod go-w $HOME + chmod -v go-w $HOME $HOME/.config sudo chmod -R go-w /usr/share + sudo bash -c 'IFS=:; for d in '"$PATH"'; do chmod -v go-w $d; done' || : - name: Set ENV run: | echo '::set-env name=JOBS::'-j$((1 + $(nproc --all))) - run: autoconf working-directory: src - run: mkdir build - - name: Run confiugre + - name: Run configure run: ../src/configure -C --disable-install-doc working-directory: build - run: make $JOBS diff --git a/.travis.yml b/.travis.yml index 1bd1ce88855b0b..20a70a2fc17db8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -360,27 +360,25 @@ env: -Wunused-variable' - LDFLAGS=-Wno-unused-command-line-argument - - &rubyspec25 - name: Check ruby/spec version guards on Ruby 2.5 + - &spec-on-old-ruby language: ruby - rvm: 2.5.7 before_install: install: before_script: chmod -R u+w spec/ruby # -j randomly hangs. script: ruby -C spec/ruby ../mspec/bin/mspec . + + - &rubyspec25 + name: Check ruby/spec version guards on Ruby 2.5 + rvm: 2.5.7 + <<: *spec-on-old-ruby after_failure: - echo "ruby/spec failed on Ruby 2.5. This is likely because of a missing ruby_version_is guard, please add it. See spec/README.md." - &rubyspec27 name: Check ruby/spec version guards on Ruby 2.7 - language: ruby rvm: 2.7.0 - before_install: - install: - before_script: chmod -R u+w spec/ruby - # -j randomly hangs. - script: ruby -C spec/ruby ../mspec/bin/mspec . + <<: *spec-on-old-ruby after_failure: - echo "ruby/spec failed on Ruby 2.7. This is likely because of a missing ruby_version_is guard, please add it. See spec/README.md." @@ -428,10 +426,7 @@ matrix: include: # Build every commit: - <<: *x86_64-linux - - <<: *arm64-linux - <<: *i686-linux - - <<: *arm32-linux - - <<: *s390x-linux - <<: *pedanticism - <<: *assertions - <<: *baseruby @@ -439,6 +434,9 @@ matrix: - <<: *rubyspec27 - <<: *dependency # Build every commit (Allowed Failures): + - <<: *arm32-linux + - <<: *arm64-linux + - <<: *s390x-linux - <<: *ASAN - <<: *MSAN - <<: *UBSAN @@ -453,10 +451,11 @@ matrix: - <<: *CALL_THREADED_CODE - <<: *NO_THREADED_CODE allow_failures: - - name: -fsanitize=address - - name: -fsanitize=memory - name: arm32-linux - name: arm64-linux + - name: s390x-linux + - name: -fsanitize=address + - name: -fsanitize=memory fast_finish: true before_script: @@ -535,7 +534,6 @@ notifications: webhooks: urls: - secure: mRsoS/UbqDkKkW5p3AEqM27d4SZnV6Gsylo3bm8T/deltQzTsGzZwrm7OIBXZv0UFZdE68XmPlyHfZFLSP2V9QZ7apXMf9/vw0GtcSe1gchtnjpAPF6lYBn7nMCbVPPx9cS0dwL927fjdRM1vj7IKZ2bk4F0lAJ25R25S6teqdk= # ruby-lang slack: ruby/simpler-alerts-bot (travis) - on_pull_requests: false on_success: never on_failure: always diff --git a/LEGAL b/LEGAL index 565c4c9cde49a6..61d8dbf2902a7b 100644 --- a/LEGAL +++ b/LEGAL @@ -12,33 +12,11 @@ ccan/check_type/check_type.h:: ccan/container_of/container_of.h:: ccan/str/str.h:: - These files are licensed under the CC0. - - >>> - https://creativecommons.org/choose/zero/ + These files are licensed under the {CC0}[https://creativecommons.org/choose/zero/]. ccan/list/list.h:: - This file is licensed under the MIT License. - - >>> - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - THE SOFTWARE. + This file is licensed under the {MIT License}[rdoc-label:label-MIT+License]. include/ruby/onigmo.h:: include/ruby/oniguruma.h:: @@ -415,8 +393,7 @@ missing/procstat_vm.c:: vsnprintf.c:: - This file is under the old-style BSD license. Note that the - paragraph 3 below is now null and void. + This file is under the {old-style BSD license}[rdoc-label:label-Old-style+BSD+license]. >>> Copyright (c) 1990, 1993 @@ -425,35 +402,6 @@ vsnprintf.c:: This code is derived from software contributed to Berkeley by Chris Torek. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - 3. Neither the name of the University nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - SUCH DAMAGE. - - IMPORTANT NOTE: - -------------- - From ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change - paragraph 3 above is now null and void. - st.c:: strftime.c:: include/ruby/st.h:: @@ -482,8 +430,7 @@ ext/sdbm/sdbm.h:: missing/crypt.c:: - This file is under the old-style BSD license. Note that the - paragraph 3 below is now null and void. + This file is under the {old-style BSD license}[rdoc-label:label-Old-style+BSD+license]. >>> Copyright (c) 1989, 1993 @@ -492,34 +439,9 @@ missing/crypt.c:: This code is derived from software contributed to Berkeley by Tom Truscott. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - 3. Neither the name of the University nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - SUCH DAMAGE. - missing/setproctitle.c:: - This file is under the old-style BSD license. Note that the - paragraph 3 below is now null and void. + This file is under the {old-style BSD license}[rdoc-label:label-Old-style+BSD+license]. >>> Copyright 2003 Damien Miller @@ -527,30 +449,6 @@ missing/setproctitle.c:: Copyright (c) 1988, 1993 The Regents of the University of California. All rights reserved. - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - 3. Neither the name of the University nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - SUCH DAMAGE. - missing/strlcat.c:: missing/strlcpy.c:: @@ -806,10 +704,7 @@ ext/win32ole/win32ole.c:: lib/rdoc/generator/template/darkfish/css/fonts.css:: - This file is licensed under the SIL Open Font License. - - >>> - http://scripts.sil.org/OFL + This file is licensed under the {SIL Open Font License}[http://scripts.sil.org/OFL]. spec/mspec:: spec/ruby:: @@ -849,8 +744,8 @@ test/rubygems:: >>> RubyGems is copyrighted free software by Chad Fowler, Rich Kilmer, Jim Weirich and others. You can redistribute it and/or modify it under - either the terms of the MIT license (see the file MIT.txt), or the - conditions below: + either the terms of the {MIT license}[rdoc-label:label-MIT+License], or the conditions + below: 1. You may make and give away verbatim copies of the source form of the software without restriction, provided that you duplicate all of the @@ -913,8 +808,10 @@ man/bundle-*,gemfile.*:: Portions copyright (c) 2010 Andre Arko Portions copyright (c) 2009 Engine Yard - MIT License:: + {MIT License}[rdoc-label:label-MIT+License] +== MIT License +>>> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including @@ -933,3 +830,34 @@ man/bundle-*,gemfile.*:: LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +== Old-style BSD license +>>> + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the University nor the names of its contributors + may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + SUCH DAMAGE. + + IMPORTANT NOTE:: + + From ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change + paragraph 3 above is now null and void. diff --git a/NEWS.md b/NEWS.md index 2322e468b7b51e..406c5d23099c0d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -152,6 +152,8 @@ Excluding feature bug fixes. * When writing to STDOUT redirected to a closed pipe, no broken pipe error message will be shown now. [[Feature #14413]] +* `TRUE`/`FALSE`/`NIL` constants are no longer defined. + ## Stdlib compatibility issues Excluding feature bug fixes. @@ -161,7 +163,7 @@ Excluding feature bug fixes. * C API functions related to $SAFE have been removed. [[Feature #16131]] -* C API header file `ruby/ruby.h` was split. [[GH-2991]] Should have no implact +* C API header file `ruby/ruby.h` was split. [[GH-2991]] Should have no impact on extension libraries, but users might experience slow compilations. ## Implementation improvements @@ -180,8 +182,13 @@ Excluding feature bug fixes. * Taint deprecation warnings are now issued in regular mode in addition to verbose warning mode. [[Feature #16131]] +* When an exception is caught in the default handler, the error + message and backtrace are printed in order from the innermost. + [[Feature #8661]] + [Bug #4352]: https://bugs.ruby-lang.org/issues/4352 +[Feature #8661]: https://bugs.ruby-lang.org/issues/8661 [Feature #8709]: https://bugs.ruby-lang.org/issues/8709 [Feature #8948]: https://bugs.ruby-lang.org/issues/8948 [Feature #9573]: https://bugs.ruby-lang.org/issues/9573 diff --git a/array.c b/array.c index 05fcc1c58f62cf..dbb40db50825de 100644 --- a/array.c +++ b/array.c @@ -32,6 +32,7 @@ #include "builtin.h" #if !ARRAY_DEBUG +# undef NDEBUG # define NDEBUG #endif #include "ruby_assert.h" diff --git a/benchmark/kernel_float.yml b/benchmark/kernel_float.yml new file mode 100644 index 00000000000000..215f6750fcc080 --- /dev/null +++ b/benchmark/kernel_float.yml @@ -0,0 +1,5 @@ +benchmark: + float: "Float(42)" + float_true: "Float(42, exception: true)" + float_false: "Float(42, exception: false)" +loop_count: 10000 diff --git a/bootstraptest/pending.rb b/bootstraptest/pending.rb index 0959bfa2b09324..2c4b85a4193d0c 100644 --- a/bootstraptest/pending.rb +++ b/bootstraptest/pending.rb @@ -1,19 +1,3 @@ -assert_equal 'A', %q{ - class A - @@a = 'A' - def a=(x) - @@a = x - end - def a - @@a - end - end - - B = A.dup - B.new.a = 'B' - A.new.a -}, '[ruby-core:17019]' - assert_equal 'ok', %q{ def m lambda{ @@ -31,13 +15,6 @@ def m end } -assert_normal_exit %q{ - r = Range.allocate - def r.<=>(o) true end - r.instance_eval { initialize r, r } - r.inspect -} - # This randomly fails on mswin. assert_equal %q{[]}, %q{ Thread.new{sleep}.backtrace diff --git a/common.mk b/common.mk index 1715518bde24f8..811ccf0851a3fd 100644 --- a/common.mk +++ b/common.mk @@ -47,7 +47,7 @@ GEM_PATH = GEM_VENDOR = BENCHMARK_DRIVER_GIT_URL = https://github.com/benchmark-driver/benchmark-driver -BENCHMARK_DRIVER_GIT_REF = v0.15.7 +BENCHMARK_DRIVER_GIT_REF = v0.15.12 SIMPLECOV_GIT_URL = https://github.com/colszowka/simplecov.git SIMPLECOV_GIT_REF = v0.17.0 SIMPLECOV_HTML_GIT_URL = https://github.com/colszowka/simplecov-html.git @@ -224,7 +224,7 @@ mjit_config.h: Makefile # Other `-Dxxx`s preceding `-DMJIT_HEADER` will be removed in transform_mjit_header.rb. # So `-DMJIT_HEADER` should be passed first when rb_mjit_header.h is generated. $(TIMESTAMPDIR)/$(MJIT_HEADER:.h=)$(MJIT_HEADER_SUFFIX).time: probes.h vm.$(OBJEXT) \ - $(TIMESTAMPDIR)/$(arch)/.time $(tooldir)/mjit_tabs.rb $(PREP) + $(TIMESTAMPDIR)/$(arch)/.time $(tooldir)/mjit_tabs.rb $(PREP) $(RBCONFIG) $(ECHO) building $(@F:.time=.h) $(MINIRUBY) $(tooldir)/mjit_tabs.rb "$(MJIT_TABS)" \ $(CPP) -DMJIT_HEADER $(MJIT_HEADER_FLAGS) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(srcdir)/vm.c $(CPPOUTFLAG)$(@F:.time=.h).new @@ -723,8 +723,10 @@ clean-spec: PHONY check: main test test-tool test-all test-spec $(ECHO) check succeeded - -$(Q) if [ x"$(GIT)" != x ] && $(CHDIR) "$(srcdir)" && $(GIT) rev-parse > /dev/null 2>&1; then \ - set -x; $(GIT) --no-pager log --format=oneline -G "^ *# *include" origin/master..HEAD; \ + -$(Q) if [ x"$(GIT)" != x ] && $(CHDIR) "$(srcdir)" && \ + b=`$(GIT) symbolic-ref --short HEAD 2>&1` && \ + u=`$(GIT) branch --list --format='%(upstream:short)' $$b`; then \ + set -x; $(GIT) --no-pager log --format=oneline -G "^ *# *include" $$u..HEAD --; \ fi check-ruby: test test-ruby @@ -11804,6 +11806,7 @@ ruby.$(OBJEXT): $(top_srcdir)/internal/parse.h ruby.$(OBJEXT): $(top_srcdir)/internal/serial.h ruby.$(OBJEXT): $(top_srcdir)/internal/static_assert.h ruby.$(OBJEXT): $(top_srcdir)/internal/string.h +ruby.$(OBJEXT): $(top_srcdir)/internal/process.h ruby.$(OBJEXT): $(top_srcdir)/internal/variable.h ruby.$(OBJEXT): $(top_srcdir)/internal/vm.h ruby.$(OBJEXT): $(top_srcdir)/internal/warnings.h diff --git a/compile.c b/compile.c index 3c948186410231..97548b422fa953 100644 --- a/compile.c +++ b/compile.c @@ -5635,7 +5635,6 @@ iseq_compile_pattern_each(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *c * goto match_failed * end * end - * true * goto matched * type_error: * FrozenCore.raise TypeError @@ -5806,7 +5805,6 @@ iseq_compile_pattern_each(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *c * end * end * end - * true * goto matched * type_error: * FrozenCore.raise TypeError diff --git a/complex.c b/complex.c index 50f78ef1e4998f..95b1abbd45e7ca 100644 --- a/complex.c +++ b/complex.c @@ -15,6 +15,7 @@ #include #include +#undef NDEBUG #define NDEBUG #include "id.h" #include "internal.h" @@ -660,8 +661,9 @@ f_complex_polar(VALUE klass, VALUE x, VALUE y) y = DBL2NUM(imag); } else { - y = f_mul(x, DBL2NUM(sin(arg))); - x = f_mul(x, DBL2NUM(cos(arg))); + const double ax = sin(arg), ay = cos(arg); + y = f_mul(x, DBL2NUM(ax)); + x = f_mul(x, DBL2NUM(ay)); if (canonicalization && f_zero_p(y)) return x; } return nucomp_s_new_internal(klass, x, y); @@ -671,6 +673,16 @@ f_complex_polar(VALUE klass, VALUE x, VALUE y) f_mul(x, m_sin(y))); } +#ifdef HAVE___COSPI +# define cospi(x) __cospi(x) +#else +# define cospi(x) cos((x) * M_PI) +#endif +#ifdef HAVE___SINPI +# define sinpi(x) __sinpi(x) +#else +# define sinpi(x) sin((x) * M_PI) +#endif /* returns a Complex or Float of ang*PI-rotated abs */ VALUE rb_dbl_complex_new_polar_pi(double abs, double ang) @@ -688,8 +700,8 @@ rb_dbl_complex_new_polar_pi(double abs, double ang) return DBL2NUM(abs); } else { - ang *= M_PI; - return rb_complex_new(DBL2NUM(abs * cos(ang)), DBL2NUM(abs * sin(ang))); + const double real = abs * cospi(ang), imag = abs * sinpi(ang); + return rb_complex_new(DBL2NUM(real), DBL2NUM(imag)); } } diff --git a/configure.ac b/configure.ac index ba86deffbebbb4..f78eb38c935d89 100644 --- a/configure.ac +++ b/configure.ac @@ -414,6 +414,30 @@ AC_CHECK_PROG(PKG_CONFIG, pkg-config, [pkg-config], [], [], # checks for UNIX variants that set C preprocessor variables AC_USE_SYSTEM_EXTENSIONS +AC_MSG_CHECKING([whether it is Android]) +AC_TRY_COMPILE([ + @%:@ifdef __ANDROID__ + @%:@error android + @%:@endif +], [], +[AC_MSG_RESULT(no)], +[ + AC_MSG_RESULT(yes) + target_os=${target_os}-android + AC_MSG_CHECKING([for Android API version]) + AC_TRY_COMPILE([ + @%:@ifndef __ANDROID_API__ + @%:@error android + @%:@endif + ], [], + [AC_MSG_RESULT(defined by the compiler)], + [ + rb_android_api=`getprop ro.build.version.sdk` + AC_MSG_RESULT($rb_android_api) + RUBY_APPEND_OPTIONS(CPPFLAGS, -D__ANDROID_API__=$rb_android_api) + ]) +]) + AC_SUBST(RM, ['rm -f']) AC_SUBST(CP, ['cp']) RMDIRS='$(top_srcdir)/tool/rmdirs' @@ -1967,6 +1991,8 @@ AC_CHECK_FUNCS(utimensat) AC_CHECK_FUNCS(utimes) AC_CHECK_FUNCS(wait4) AC_CHECK_FUNCS(waitpid) +AC_CHECK_FUNCS(__cospi) +AC_CHECK_FUNCS(__sinpi) AS_IF([test "x$ac_cv_member_struct_statx_stx_btime" = xyes], [AC_CHECK_FUNCS(statx)]) diff --git a/debug.c b/debug.c index 9b5dc016abe704..e841b76f0fb687 100644 --- a/debug.c +++ b/debug.c @@ -44,13 +44,18 @@ const union { enum ruby_method_ids method_ids; enum ruby_id_types id_types; enum ruby_fl_type fl_types; + enum ruby_fl_ushift fl_ushift; enum ruby_encoding_consts encoding_consts; enum ruby_coderange_type enc_coderange_types; enum ruby_econv_flag_type econv_flag_types; + rb_econv_result_t econv_result; enum ruby_robject_flags robject_flags; + enum ruby_robject_consts robject_consts; enum ruby_rmodule_flags rmodule_flags; enum ruby_rstring_flags rstring_flags; + enum ruby_rstring_consts rstring_consts; enum ruby_rarray_flags rarray_flags; + enum ruby_rarray_consts rarray_consts; enum { RUBY_FMODE_READABLE = FMODE_READABLE, RUBY_FMODE_WRITABLE = FMODE_WRITABLE, diff --git a/doc/globals.rdoc b/doc/globals.rdoc index 89b94e9a8ff8bc..1d7cda69f952a6 100644 --- a/doc/globals.rdoc +++ b/doc/globals.rdoc @@ -50,9 +50,6 @@ $-p:: True if option -p is set. Read-only variable. == Pre-defined global constants -TRUE:: The typical true value. Deprecated. -FALSE:: The +false+ itself. Deprecated. -NIL:: The +nil+ itself. Deprecated. STDIN:: The standard input. The default value for $stdin. STDOUT:: The standard output. The default value for $stdout. STDERR:: The standard error output. The default value for $stderr. diff --git a/doc/implicit_conversion.rdoc b/doc/implicit_conversion.rdoc new file mode 100644 index 00000000000000..fae5973f5c2993 --- /dev/null +++ b/doc/implicit_conversion.rdoc @@ -0,0 +1,198 @@ +== Implicit Conversions + +Some Ruby methods accept one or more objects +that can be either: +* Of a given class, and so accepted as is. +* Implicitly convertible to that class, in which case + the called method converts the object. + +For each of the relevant classes, the conversion is done by calling +a specific conversion method: + +* Array: +to_ary+ +* Hash: +to_hash+ +* Integer: +to_int+ +* String: +to_str+ + +=== Array-Convertible Objects + +An Array-convertible object is an object that: +* Has instance method +to_ary+. +* The method accepts no arguments. +* The method returns an object +obj+ for which obj.kind_of?(Array) returns +true+. + +The examples in this section use method Array#replace, +which accepts an Array-convertible argument. + +This class is Array-convertible: + + class ArrayConvertible + def to_ary + [:foo, 'bar', baz = 2] + end + end + a = [] + a.replace(ArrayConvertible.new) # => [:foo, "bar", 2] + +This class is not Array-convertible (no +to_ary+ method): + + class NotArrayConvertible; end + a = [] + # Raises TypeError (no implicit conversion of NotArrayConvertible into Array) + a.replace(NotArrayConvertible.new) + +This class is not Array-convertible (method +to_ary+ takes arguments): + + class NotArrayConvertible + def to_ary(x) + [:foo, 'bar', baz = 2] + end + end + a = [] + # Raises ArgumentError (wrong number of arguments (given 0, expected 1)) + a.replace(NotArrayConvertible.new) + +This class is not Array-convertible (method +to_ary+ returns non-Array): + + class NotArrayConvertible + def to_ary + :foo + end + end + a = [] + # Raises TypeError (can't convert NotArrayConvertible to Array (NotArrayConvertible#to_ary gives Symbol)) + a.replace(NotArrayConvertible.new) + +=== Hash-Convertible Objects + +A Hash-convertible object is an object that: +* Has instance method +to_hash+. +* The method accepts no arguments. +* The method returns an object +obj+ for which obj.kind_of?(Hash) returns +true+. + +The examples in this section use method Hash#merge, +which accepts a Hash-convertible argument. + +This class is Hash-convertible: + + class HashConvertible + def to_hash + {foo: 0, bar: 1, baz: 2} + end + end + h = {} + h.merge(HashConvertible.new) # => {:foo=>0, :bar=>1, :baz=>2} + +This class is not Hash-convertible (no +to_hash+ method): + + class NotHashConvertible; end + h = {} + # Raises TypeError (no implicit conversion of NotHashConvertible into Hash) + h.merge(NotHashConvertible.new) + +This class is not Hash-convertible (method +to_hash+ takes arguments): + + class NotHashConvertible + def to_hash(x) + {foo: 0, bar: 1, baz: 2} + end + end + h = {} + # Raises ArgumentError (wrong number of arguments (given 0, expected 1)) + h.merge(NotHashConvertible.new) + +This class is not Hash-convertible (method +to_hash+ returns non-Hash): + + class NotHashConvertible + def to_hash + :foo + end + end + h = {} + # Raises TypeError (can't convert NotHashConvertible to Hash (ToHashReturnsNonHash#to_hash gives Symbol)) + h.merge(NotHashConvertible.new) + +=== Integer-Convertible Objects + +An Integer-convertible object is an object that: +* Has instance method +to_int+. +* The method accepts no arguments. +* The method returns an object +obj+ for which obj.kind_of?(Integer) returns +true+. + +The examples in this section use method Array.new, +which accepts an Integer-convertible argument. + +This user-defined class is Integer-convertible: + + class IntegerConvertible + def to_int + 3 + end + end + a = Array.new(IntegerConvertible.new).size + a # => 3 + +This class is not Integer-convertible (method +to_int+ takes arguments): + + class NotIntegerConvertible + def to_int(x) + 3 + end + end + # Raises ArgumentError (wrong number of arguments (given 0, expected 1)) + Array.new(NotIntegerConvertible.new) + +This class is not Integer-convertible (method +to_int+ returns non-Integer): + + class NotIntegerConvertible + def to_int + :foo + end + end + # Raises TypeError (can't convert NotIntegerConvertible to Integer (NotIntegerConvertible#to_int gives Symbol)) + Array.new(NotIntegerConvertible.new) + +=== String-Convertible Objects + +A String-convertible object is an object that: +* Has instance method +to_str+. +* The method accepts no arguments. +* The method returns an object +obj+ for which obj.kind_of?(String) returns +true+. + +The examples in this section use method String::new, +which accepts a String-convertible argument. + +This class is String-convertible: + + class StringConvertible + def to_str + 'foo' + end + end + String.new(StringConvertible.new) # => "foo" + +This class is not String-convertible (no +to_str+ method): + + class NotStringConvertible; end + # Raises TypeError (no implicit conversion of NotStringConvertible into String) + String.new(NotStringConvertible.new) + +This class is not String-convertible (method +to_str+ takes arguments): + + class NotStringConvertible + def to_str(x) + 'foo' + end + end + # Raises ArgumentError (wrong number of arguments (given 0, expected 1)) + String.new(NotStringConvertible.new) + +This class is not String-convertible (method +to_str+ returns non-String): + + class NotStringConvertible + def to_str + :foo + end + end + # Raises TypeError (can't convert NotStringConvertible to String (NotStringConvertible#to_str gives Symbol)) + String.new(NotStringConvertible.new) diff --git a/doc/maintainers.rdoc b/doc/maintainers.rdoc index 3cf248c51bb09c..4cef5b9b668822 100644 --- a/doc/maintainers.rdoc +++ b/doc/maintainers.rdoc @@ -350,7 +350,7 @@ Zachary Scott (zzak) [minitest] https://github.com/seattlerb/minitest [power_assert] - https://github.com/k-tsj/power_assert + https://github.com/ruby/power_assert [rake] https://github.com/ruby/rake [test-unit] diff --git a/doc/make_cheatsheet.md b/doc/make_cheatsheet.md index e01eb2d001d71a..bf245bea031b33 100644 --- a/doc/make_cheatsheet.md +++ b/doc/make_cheatsheet.md @@ -52,22 +52,46 @@ $ make test-spec MSPECOPT=-Vfs ## How to run a part of the test suite +### Runs a directory ``` -# Runs a directory $ make test-all TESTS=test/rubygems $ make test-all TESTS=rubygems +``` -# Runs a file +### Runs a file +``` $ make test-all TESTS=test/ruby/test_foo.rb $ make test-all TESTS=ruby/foo +``` -# Runs a test whose name includes test_bar +### Runs a test whose name includes test_bar +``` $ make test-all TESTS="test/ruby/test_foo.rb -n /test_bar/" ``` +### Runs a file or directory with GNU make +``` +$ make test/ruby/test_foo.rb +$ make test/ruby/test_foo.rb TESTOPTS="-n /test_bar/" +``` + +### Runs a ruby-spec directory +``` +$ make test-spec MSPECOPT=spec/ruby/core/foo +``` + +### Runs a ruby-spec file ``` $ make test-spec MSPECOPT=spec/ruby/core/foo/bar_spec.rb +``` +### Runs a ruby-spec file or directory with GNU make +``` +$ make spec/ruby/core/foo/bar_spec.rb +``` + +### Runs a bundler spec file +``` $ make test-bundler BUNDLER_SPECS=commands/exec_spec.rb:58 ``` diff --git a/doc/syntax/literals.rdoc b/doc/syntax/literals.rdoc index 38bfa38676c055..e58430e96f3ea8 100644 --- a/doc/syntax/literals.rdoc +++ b/doc/syntax/literals.rdoc @@ -20,9 +20,6 @@ Literals create objects you can use in your program. Literals include: +true+ is a true value. All objects except +nil+ and +false+ evaluate to a true value in conditional expressions. -(There are also the constants +TRUE+, +FALSE+ and +NIL+, but the lowercase -literal forms are preferred.) - == Numbers You can write integers of any size as follows: diff --git a/enc/unicode.c b/enc/unicode.c index 6e8c3d8816aa91..18fba02476af66 100644 --- a/enc/unicode.c +++ b/enc/unicode.c @@ -493,6 +493,10 @@ onigenc_unicode_get_case_fold_codes_by_str(OnigEncoding enc, #endif if ((to = onigenc_unicode_fold_lookup(code)) != 0) { + if (OnigCodePointCount(to->n) == 0) { + /* any codepoint should not be empty */ + UNREACHABLE_RETURN(0); + } if (OnigCodePointCount(to->n) == 1) { OnigCodePoint orig_code = code; diff --git a/enumerator.c b/enumerator.c index 9632b026981dbd..cc0cce8fae4a80 100644 --- a/enumerator.c +++ b/enumerator.c @@ -81,6 +81,14 @@ * puts e.next # => 3 * puts e.next # raises StopIteration * + * Note that enumeration sequence by +next+, +next_values+, +peek+ and + * +peek_values+ do not affect other non-external + * enumeration methods, unless the underlying iteration method itself has + * side-effect, e.g. IO#each_line. + * + * Moreover, implementation typically uses fibers so performance could be + * slower and exception stacktraces different than expected. + * * You can use this to implement an internal iterator as follows: * * def ext_each(e) @@ -804,6 +812,8 @@ get_next_values(VALUE obj, struct enumerator *e) * internal position forward. When the position reached at the end, * StopIteration is raised. * + * See class-level notes about external iterators. + * * This method can be used to distinguish yield and yield * nil. * @@ -837,10 +847,6 @@ get_next_values(VALUE obj, struct enumerator *e) * # yield nil [nil] nil * # yield [1, 2] [[1, 2]] [1, 2] * - * Note that +next_values+ does not affect other non-external enumeration - * methods unless underlying iteration method itself has side-effect, e.g. - * IO#each_line. - * */ static VALUE @@ -894,9 +900,7 @@ ary2sv(VALUE args, int dup) * p e.next #=> 3 * p e.next #raises StopIteration * - * Note that enumeration sequence by +next+ does not affect other non-external - * enumeration methods, unless the underlying iteration methods itself has - * side-effect, e.g. IO#each_line. + * See class-level notes about external iterators. * */ @@ -926,6 +930,8 @@ enumerator_peek_values(VALUE obj) * doesn't move the internal position forward. If the position is already at * the end, StopIteration is raised. * + * See class-level notes about external iterators. + * * === Example * * o = Object.new @@ -960,6 +966,8 @@ enumerator_peek_values_m(VALUE obj) * position forward. If the position is already at the end, StopIteration * is raised. * + * See class-level notes about external iterators. + * * === Example * * a = [1,2,3] diff --git a/eval_error.c b/eval_error.c index 74f09a8d8bdc85..89e27afe56e728 100644 --- a/eval_error.c +++ b/eval_error.c @@ -309,9 +309,9 @@ rb_error_write(VALUE errinfo, VALUE emesg, VALUE errat, VALUE str, VALUE highlig errat = Qnil; } eclass = CLASS_OF(errinfo); - if (NIL_P(reverse) || NIL_P(highlight)) { + if (NIL_P(reverse)) reverse = Qfalse; + if (NIL_P(highlight)) { VALUE tty = (VALUE)rb_stderr_tty_p(); - if (NIL_P(reverse)) reverse = tty; if (NIL_P(highlight)) highlight = tty; } if (reverse) { @@ -362,7 +362,7 @@ rb_ec_error_print(rb_execution_context_t * volatile ec, volatile VALUE errinfo) emesg = rb_get_message(errinfo); } - rb_error_write(errinfo, emesg, errat, Qnil, Qnil, Qnil); + rb_error_write(errinfo, emesg, errat, Qnil, Qnil, Qfalse); EC_POP_TAG(); ec->errinfo = errinfo; diff --git a/ext/objspace/objspace.c b/ext/objspace/objspace.c index f470f74c5a2bf6..0799944a5b6ffe 100644 --- a/ext/objspace/objspace.c +++ b/ext/objspace/objspace.c @@ -382,9 +382,9 @@ count_nodes(int argc, VALUE *argv, VALUE os) COUNT_NODE(NODE_UNLESS); COUNT_NODE(NODE_CASE); COUNT_NODE(NODE_CASE2); - COUNT_NODE(NODE_CASE3); + COUNT_NODE(NODE_CASE3); COUNT_NODE(NODE_WHEN); - COUNT_NODE(NODE_IN); + COUNT_NODE(NODE_IN); COUNT_NODE(NODE_WHILE); COUNT_NODE(NODE_UNTIL); COUNT_NODE(NODE_ITER); @@ -478,8 +478,8 @@ count_nodes(int argc, VALUE *argv, VALUE os) COUNT_NODE(NODE_DSYM); COUNT_NODE(NODE_ATTRASGN); COUNT_NODE(NODE_LAMBDA); - COUNT_NODE(NODE_ARYPTN); - COUNT_NODE(NODE_HSHPTN); + COUNT_NODE(NODE_ARYPTN); + COUNT_NODE(NODE_HSHPTN); #undef COUNT_NODE case NODE_LAST: break; } diff --git a/ext/pty/extconf.rb b/ext/pty/extconf.rb index 7721a744c812af..038bdf4d2c337f 100644 --- a/ext/pty/extconf.rb +++ b/ext/pty/extconf.rb @@ -10,9 +10,9 @@ have_header("util.h") # OpenBSD openpty have_header("pty.h") have_header("pwd.h") - have_library("util", "openpty") + util = have_library("util", "openpty") if have_func("posix_openpt") or - have_func("openpty") or + (util or have_func("openpty")) or have_func("_getpty") or have_func("ptsname") or have_func("ioctl") diff --git a/ext/ripper/eventids2.c b/ext/ripper/eventids2.c index cdac2081e64b09..ac38663f2d2398 100644 --- a/ext/ripper/eventids2.c +++ b/ext/ripper/eventids2.c @@ -1,12 +1,20 @@ enum { tIGNORED_NL = tLAST_TOKEN + 1, +# define tIGNORED_NL ((enum yytokentype)tIGNORED_NL) tCOMMENT, +# define tCOMMENT ((enum yytokentype)tCOMMENT) tEMBDOC_BEG, +# define tEMBDOC_BEG ((enum yytokentype)tEMBDOC_BEG) tEMBDOC, +# define tEMBDOC ((enum yytokentype)tEMBDOC) tEMBDOC_END, +# define tEMBDOC_END ((enum yytokentype)tEMBDOC_END) tHEREDOC_BEG, +# define tHEREDOC_BEG ((enum yytokentype)tHEREDOC_BEG) tHEREDOC_END, - k__END__ +# define tHEREDOC_END ((enum yytokentype)tHEREDOC_END) + k__END__, +# define k__END__ ((enum yytokentype)k__END__) }; typedef struct { diff --git a/ext/socket/raddrinfo.c b/ext/socket/raddrinfo.c index 9ec2fdc329ead4..079f66dddc2da3 100644 --- a/ext/socket/raddrinfo.c +++ b/ext/socket/raddrinfo.c @@ -1913,7 +1913,7 @@ addrinfo_to_sockaddr(VALUE self) * call-seq: * addrinfo.canonname => string or nil * - * returns the canonical name as an string. + * returns the canonical name as a string. * * nil is returned if no canonical name. * diff --git a/ext/win32ole/win32ole.c b/ext/win32ole/win32ole.c index f20bfc84f633b3..4b55f6ea54a27c 100644 --- a/ext/win32ole/win32ole.c +++ b/ext/win32ole/win32ole.c @@ -2651,7 +2651,7 @@ ole_invoke(int argc, VALUE *argv, VALUE self, USHORT wFlags, BOOL is_bracket) /*------------------------------------------ hash object ==> named dispatch parameters --------------------------------------------*/ - cNamedArgs = rb_long2int(RHASH_SIZE(param)); + cNamedArgs = rb_long2int((long)RHASH_SIZE(param)); op.dp.cArgs = cNamedArgs + argc - 2; op.pNamedArgs = ALLOCA_N(OLECHAR*, cNamedArgs + 1); op.dp.rgvarg = ALLOCA_N(VARIANTARG, op.dp.cArgs); diff --git a/gc.c b/gc.c index 115afa17d013f2..a3f2de74aa9bdb 100644 --- a/gc.c +++ b/gc.c @@ -2327,6 +2327,7 @@ rb_imemo_new_debug(enum imemo_type type, VALUE v1, VALUE v2, VALUE v3, VALUE v0, VALUE rb_data_object_wrap(VALUE klass, void *datap, RUBY_DATA_FUNC dmark, RUBY_DATA_FUNC dfree) { + RUBY_ASSERT_ALWAYS(dfree != (RUBY_DATA_FUNC)1); if (klass) Check_Type(klass, T_CLASS); return newobj_of(klass, T_DATA, (VALUE)dmark, (VALUE)dfree, (VALUE)datap, FALSE); } @@ -2342,6 +2343,7 @@ rb_data_object_zalloc(VALUE klass, size_t size, RUBY_DATA_FUNC dmark, RUBY_DATA_ VALUE rb_data_typed_object_wrap(VALUE klass, void *datap, const rb_data_type_t *type) { + RUBY_ASSERT_ALWAYS(type); if (klass) Check_Type(klass, T_CLASS); return newobj_of(klass, T_DATA, (VALUE)type, (VALUE)1, (VALUE)datap, type->flags & RUBY_FL_WB_PROTECTED); } @@ -8507,11 +8509,13 @@ gc_compact_stats(rb_objspace_t *objspace) VALUE moved = rb_hash_new(); for (i=0; ircompactor.considered_count_table[i])); - } + if(objspace->rcompactor.considered_count_table[i]) { + rb_hash_aset(considered, type_sym(i), SIZET2NUM(objspace->rcompactor.considered_count_table[i])); + } - for (i=0; ircompactor.moved_count_table[i])); + if(objspace->rcompactor.moved_count_table[i]) { + rb_hash_aset(moved, type_sym(i), SIZET2NUM(objspace->rcompactor.moved_count_table[i])); + } } rb_hash_aset(h, ID2SYM(rb_intern("considered")), considered); @@ -9594,6 +9598,8 @@ ruby_memerror_body(void *dummy) return 0; } +NORETURN(static void ruby_memerror(void)); +RUBY3_ATTR_MAYBE_UNUSED() static void ruby_memerror(void) { @@ -9607,9 +9613,9 @@ ruby_memerror(void) else { /* no ruby thread */ fprintf(stderr, "[FATAL] failed to allocate memory\n"); - exit(EXIT_FAILURE); } } + exit(EXIT_FAILURE); } void @@ -9854,7 +9860,37 @@ objspace_malloc_fixup(rb_objspace_t *objspace, void *mem, size_t size) return mem; } -#define TRY_WITH_GC(alloc) do { \ +#if defined(__GNUC__) && RUBY_DEBUG +#define RB_BUG_INSTEAD_OF_RB_MEMERROR +#endif + +#ifdef RB_BUG_INSTEAD_OF_RB_MEMERROR +#define TRY_WITH_GC(siz, expr) do { \ + const gc_profile_record_flag gpr = \ + GPR_FLAG_FULL_MARK | \ + GPR_FLAG_IMMEDIATE_MARK | \ + GPR_FLAG_IMMEDIATE_SWEEP | \ + GPR_FLAG_MALLOC; \ + objspace_malloc_gc_stress(objspace); \ + \ + if (LIKELY((expr))) { \ + /* Success on 1st try */ \ + } \ + else if (!garbage_collect_with_gvl(objspace, gpr)) { \ + /* @shyouhei thinks this doesn't happen */ \ + rb_bug("TRY_WITH_GC: could not GC"); \ + } \ + else if ((expr)) { \ + /* Success on 2nd try */ \ + } \ + else { \ + rb_bug("TRY_WITH_GC: could not allocate:" \ + "%"PRIdSIZE" bytes for %s", \ + siz, # expr); \ + } \ + } while (0) +#else +#define TRY_WITH_GC(siz, alloc) do { \ objspace_malloc_gc_stress(objspace); \ if (!(alloc) && \ (!garbage_collect_with_gvl(objspace, GPR_FLAG_FULL_MARK | \ @@ -9864,9 +9900,10 @@ objspace_malloc_fixup(rb_objspace_t *objspace, void *mem, size_t size) ruby_memerror(); \ } \ } while (0) +#endif /* these shouldn't be called directly. - * objspace_* functinos do not check allocation size. + * objspace_* functions do not check allocation size. */ static void * objspace_xmalloc0(rb_objspace_t *objspace, size_t size) @@ -9874,7 +9911,7 @@ objspace_xmalloc0(rb_objspace_t *objspace, size_t size) void *mem; size = objspace_malloc_prepare(objspace, size); - TRY_WITH_GC(mem = malloc(size)); + TRY_WITH_GC(size, mem = malloc(size)); RB_DEBUG_COUNTER_INC(heap_xmalloc); return objspace_malloc_fixup(objspace, mem, size); } @@ -9945,7 +9982,7 @@ objspace_xrealloc(rb_objspace_t *objspace, void *ptr, size_t new_size, size_t ol #endif old_size = objspace_malloc_size(objspace, ptr, old_size); - TRY_WITH_GC(mem = realloc(ptr, new_size)); + TRY_WITH_GC(new_size, mem = realloc(ptr, new_size)); new_size = objspace_malloc_size(objspace, mem, new_size); #if CALC_EXACT_MALLOC_SIZE @@ -10127,7 +10164,7 @@ objspace_xcalloc(rb_objspace_t *objspace, size_t size) void *mem; size = objspace_malloc_prepare(objspace, size); - TRY_WITH_GC(mem = calloc1(size)); + TRY_WITH_GC(size, mem = calloc1(size)); return objspace_malloc_fixup(objspace, mem, size); } @@ -10703,26 +10740,26 @@ wmap_aset_update(st_data_t *key, st_data_t *val, st_data_t arg, int existing) /* Creates a weak reference from the given key to the given value */ static VALUE -wmap_aset(VALUE self, VALUE wmap, VALUE orig) +wmap_aset(VALUE self, VALUE key, VALUE value) { struct weakmap *w; TypedData_Get_Struct(self, struct weakmap, &weakmap_type, w); - if (FL_ABLE(orig)) { - define_final0(orig, w->final); + if (FL_ABLE(value)) { + define_final0(value, w->final); } - if (FL_ABLE(wmap)) { - define_final0(wmap, w->final); + if (FL_ABLE(key)) { + define_final0(key, w->final); } - st_update(w->obj2wmap, (st_data_t)orig, wmap_aset_update, wmap); - st_insert(w->wmap2obj, (st_data_t)wmap, (st_data_t)orig); - return nonspecial_obj_id(orig); + st_update(w->obj2wmap, (st_data_t)value, wmap_aset_update, key); + st_insert(w->wmap2obj, (st_data_t)key, (st_data_t)value); + return nonspecial_obj_id(value); } /* Retrieves a weakly referenced object with the given key */ static VALUE -wmap_aref(VALUE self, VALUE wmap) +wmap_lookup(VALUE self, VALUE key) { st_data_t data; VALUE obj; @@ -10730,17 +10767,25 @@ wmap_aref(VALUE self, VALUE wmap) rb_objspace_t *objspace = &rb_objspace; TypedData_Get_Struct(self, struct weakmap, &weakmap_type, w); - if (!st_lookup(w->wmap2obj, (st_data_t)wmap, &data)) return Qnil; + if (!st_lookup(w->wmap2obj, (st_data_t)key, &data)) return Qundef; obj = (VALUE)data; - if (!wmap_live_p(objspace, obj)) return Qnil; + if (!wmap_live_p(objspace, obj)) return Qundef; return obj; } +/* Retrieves a weakly referenced object with the given key */ +static VALUE +wmap_aref(VALUE self, VALUE key) +{ + VALUE obj = wmap_lookup(self, key); + return obj != Qundef ? obj : Qnil; +} + /* Returns +true+ if +key+ is registered */ static VALUE wmap_has_key(VALUE self, VALUE key) { - return NIL_P(wmap_aref(self, key)) ? Qfalse : Qtrue; + return wmap_lookup(self, key) == Qundef ? Qfalse : Qtrue; } /* Returns the number of referenced objects */ diff --git a/gems/bundled_gems b/gems/bundled_gems index 21e0423bedbe35..f0faa93daa9ba2 100644 --- a/gems/bundled_gems +++ b/gems/bundled_gems @@ -1,5 +1,5 @@ minitest 5.14.0 https://github.com/seattlerb/minitest -power_assert 1.1.7 https://github.com/k-tsj/power_assert +power_assert 1.2.0 https://github.com/ruby/power_assert rake 13.0.1 https://github.com/ruby/rake test-unit 3.3.5 https://github.com/test-unit/test-unit rexml 3.2.4 https://github.com/ruby/rexml diff --git a/hash.c b/hash.c index 769af0df7d2343..ab6dd3ba793698 100644 --- a/hash.c +++ b/hash.c @@ -1810,22 +1810,74 @@ rb_hash_initialize(int argc, VALUE *argv, VALUE hash) /* * call-seq: - * Hash[ key, value, ... ] -> new_hash - * Hash[ [ [key, value], ... ] ] -> new_hash - * Hash[ object ] -> new_hash + * Hash[] -> new_empty_hash + * Hash[ [*2_element_arrays] ] -> new_hash + * Hash[*objects] -> new_hash + * Hash[hash_convertible_object] -> new_hash * - * Creates a new hash populated with the given objects. + * Returns a new \Hash object populated with the given objects, if any. * - * Similar to the literal { _key_ => _value_, ... }. In the first - * form, keys and values occur in pairs, so there must be an even number of - * arguments. + * The initial default value and default proc are set to nil + * (see {Default Values}[#class-Hash-label-Default+Values]): * - * The second and third form take a single argument which is either an array - * of key-value pairs or an object convertible to a hash. + * h = Hash[] + * h # => {} + * h.class # => Hash + * h.default # => nil + * h.default_proc # => nil + * + * When argument [*2_element_arrays] is given, + * each element of the outer array must be a 2-element array; + * returns a new \Hash object wherein each 2-element array forms a key-value entry: + * + * Hash[ [ [:foo, 0], [:bar, 1] ] ] # => {:foo=>0, :bar=>1} + * + * When arguments *objects are given, + * the argument count must be an even number; + * returns a new \Hash object wherein each successive pair of arguments has become a key-value entry: + * + * Hash[] # => {} + * Hash[:foo, 0, :bar, 1] # => {:foo=>0, :bar=>1} + * + * When argument hash_convertible_object is given, + * the argument must be a + * {Hash-convertible object}[doc/implicit_conversion_rdoc.html#label-Hash-Convertible+Objects]; + * converts the object and returns the resulting \Hash object: + * + * class Foo + * def to_hash + * {foo: 0, bar: 1} + * end + * end + * Hash[Foo.new] # => {:foo=>0, :bar=>1} + * + * --- + * + * Raises an exception if the argument count is 1, + * but the argument is not an array of 2-element arrays or a + * {Hash-convertible object}[doc/implicit_conversion_rdoc.html#label-Hash-Convertible+Objects]: + * + * Hash[:foo] # Raises ArgumentError (odd number of arguments + * Hash[ [ [:foo, 0, 1] ] ] # Raises ArgumentError (invalid number of elements (3 for 1..2)) + * + * Raises an exception if the argument count is odd and greater than 1: + * + * Hash[0, 1, 2] # Raises ArgumentError (odd number of arguments for Hash) * - * Hash["a", 100, "b", 200] #=> {"a"=>100, "b"=>200} - * Hash[ [ ["a", 100], ["b", 200] ] ] #=> {"a"=>100, "b"=>200} - * Hash["a" => 100, "b" => 200] #=> {"a"=>100, "b"=>200} + * Raises an exception if the argument is an array containing an element + * that is not a 2-element array: + * + * Hash[ [ :foo ] ] # Raises ArgumentError (wrong element type Symbol at 0 (expected array)) + * + * Raises an exception if the argument is an array containing an element + * that is an array of size different from 2: + * + * Hash[ [ [0, 1, 2] ] ] # Raises ArgumentError (invalid number of elements (3 for 1..2)) + * + * Raises an exception if any proposed key is not a valid key: + * + * Hash[:foo, 0, BasicObject.new, 1] # Raises NoMethodError (undefined method `hash' for #) + * Hash[ [ [:foo, 0], [BasicObject.new, 1] ] ] # Raises NoMethodError (undefined method `hash' for #) */ static VALUE @@ -4881,14 +4933,9 @@ env_name(volatile VALUE *s) static VALUE env_aset(VALUE nm, VALUE val); -static VALUE -env_delete(VALUE name) +static void +reset_by_modified_env(const char *nam) { - const char *nam, *val; - - nam = env_name(name); - val = getenv(nam); - /* * ENV['TZ'] = nil has a special meaning. * TZ is no longer considered up-to-date and ruby call tzset() as needed. @@ -4898,6 +4945,15 @@ env_delete(VALUE name) if (ENVMATCH(nam, TZ_ENV)) { ruby_reset_timezone(); } +} + +static VALUE +env_delete(VALUE name) +{ + const char *nam = env_name(name); + const char *val = getenv(nam); + + reset_by_modified_env(nam); if (val) { VALUE value = env_str_new2(val); @@ -5327,24 +5383,26 @@ env_aset(VALUE nm, VALUE val) if (ENVMATCH(name, PATH_ENV)) { RB_GC_GUARD(nm); } - else if (ENVMATCH(name, TZ_ENV)) { - ruby_reset_timezone(); - } + reset_by_modified_env(name); return val; } static VALUE -env_keys(void) +env_keys(int raw) { char **env; VALUE ary; + rb_encoding *enc = raw ? 0 : rb_locale_encoding(); ary = rb_ary_new(); env = GET_ENVIRON(environ); while (*env) { char *s = strchr(*env, '='); if (s) { - rb_ary_push(ary, env_str_new(*env, s-*env)); + const char *p = *env; + size_t l = s - p; + VALUE e = raw ? rb_utf8_str_new(p, l) : env_enc_str_new(p, l, enc); + rb_ary_push(ary, e); } env++; } @@ -5370,7 +5428,7 @@ env_keys(void) static VALUE env_f_keys(VALUE _) { - return env_keys(); + return env_keys(FALSE); } static VALUE @@ -5413,7 +5471,7 @@ env_each_key(VALUE ehash) long i; RETURN_SIZED_ENUMERATOR(ehash, 0, 0, rb_env_size); - keys = env_keys(); + keys = env_keys(FALSE); for (i=0; i> 1; const long w = RUBY3_CAST((long)z); diff --git a/include/ruby/3/assume.h b/include/ruby/3/assume.h index 9664f5606ca983..98059d7cbfa362 100644 --- a/include/ruby/3/assume.h +++ b/include/ruby/3/assume.h @@ -59,7 +59,7 @@ # define RUBY3_UNREACHABLE() __assume(0) #endif -/** Wraps (or simulates) `__asume`. */ +/** Wraps (or simulates) `__assume`. */ #if RUBY3_COMPILER_SINCE(Intel, 13, 0, 0) # /* icc warnings are false positives. Ignore them. */ # /* "warning #2261: __assume expression with side effects discarded" */ diff --git a/include/ruby/3/core/rarray.h b/include/ruby/3/core/rarray.h index 3234daae90dcf9..added0c41c325d 100644 --- a/include/ruby/3/core/rarray.h +++ b/include/ruby/3/core/rarray.h @@ -79,7 +79,7 @@ enum ruby_rarray_flags { #endif }; -enum { +enum ruby_rarray_consts { RARRAY_EMBED_LEN_SHIFT = RUBY_FL_USHIFT + 3, RARRAY_EMBED_LEN_MAX = RUBY3_EMBED_LEN_MAX_OF(VALUE) }; diff --git a/include/ruby/3/core/robject.h b/include/ruby/3/core/robject.h index 3f298214a923d4..c6101af2d24fb1 100644 --- a/include/ruby/3/core/robject.h +++ b/include/ruby/3/core/robject.h @@ -43,7 +43,7 @@ enum ruby_robject_flags { ROBJECT_EMBED = RUBY_FL_USER1 }; -enum { ROBJECT_EMBED_LEN_MAX = RUBY3_EMBED_LEN_MAX_OF(VALUE) }; +enum ruby_robject_consts { ROBJECT_EMBED_LEN_MAX = RUBY3_EMBED_LEN_MAX_OF(VALUE) }; struct RObject { struct RBasic basic; diff --git a/include/ruby/3/core/rstring.h b/include/ruby/3/core/rstring.h index 8951dd0d3017be..10104c7a555855 100644 --- a/include/ruby/3/core/rstring.h +++ b/include/ruby/3/core/rstring.h @@ -65,7 +65,7 @@ enum ruby_rstring_flags { RSTRING_FSTR = RUBY_FL_USER17 }; -enum { +enum ruby_rstring_consts { RSTRING_EMBED_LEN_SHIFT = RUBY_FL_USHIFT + 2, RSTRING_EMBED_LEN_MAX = RUBY3_EMBED_LEN_MAX_OF(char) - 1 }; diff --git a/include/ruby/3/fl_type.h b/include/ruby/3/fl_type.h index 2adb6006c7b098..6366e7037ce5d6 100644 --- a/include/ruby/3/fl_type.h +++ b/include/ruby/3/fl_type.h @@ -146,7 +146,7 @@ /** @} */ /* This is an enum because GDB wants it (rather than a macro) */ -enum { RUBY_FL_USHIFT = 12 }; +enum ruby_fl_ushift { RUBY_FL_USHIFT = 12 }; /* > The expression that defines the value of an enumeration constant shall be * > an integer constant expression that has a value representable as an `int`. diff --git a/include/ruby/3/intern/load.h b/include/ruby/3/intern/load.h index 1a1dfb001efefe..6baf6b72b6dd59 100644 --- a/include/ruby/3/intern/load.h +++ b/include/ruby/3/intern/load.h @@ -32,7 +32,6 @@ int rb_provided(const char*); int rb_feature_provided(const char *, const char **); void rb_provide(const char*); VALUE rb_f_require(VALUE, VALUE); -VALUE rb_require_safe(VALUE, int); /* Remove in 3.0 */ VALUE rb_require_string(VALUE); RUBY3_SYMBOL_EXPORT_END() diff --git a/include/ruby/3/scan_args.h b/include/ruby/3/scan_args.h index bc4faddd56a259..409cef909f2f15 100644 --- a/include/ruby/3/scan_args.h +++ b/include/ruby/3/scan_args.h @@ -112,7 +112,7 @@ RUBY3_SYMBOL_EXPORT_END() # * Static assertions need such integer constant expressions as defined in # * ISO/IEC 9899:2018 section 6.7.10 paragraph #3. # * -# * GCC nontheless constant-folds this into no-op, though. */ +# * GCC nonetheless constant-folds this into no-op, though. */ # define rb_scan_args_verify(fmt, varc) \ (sizeof(char[1-2*(rb_scan_args_count(fmt)<0)])!=1 ? \ rb_scan_args_bad_format(fmt) : \ @@ -380,7 +380,7 @@ rb_scan_args_set(int kw_flag, int argc, const VALUE *argv, argc, argvp, fmt, \ (sizeof((VALUE*[]){__VA_ARGS__})/sizeof(VALUE*)), \ ((VALUE*[]){__VA_ARGS__})), \ - (rb_scan_args)(argc, argvp, fmt, ## __VA_ARGS__)) + (rb_scan_args)(argc, argvp, fmt, __VA_ARGS__)) # define rb_scan_args_kw(kw_flag, argc, argvp, fmt, ...) \ __builtin_choose_expr( \ __builtin_constant_p(fmt), \ @@ -388,7 +388,7 @@ rb_scan_args_set(int kw_flag, int argc, const VALUE *argv, kw_flag, argc, argvp, fmt, \ (sizeof((VALUE*[]){__VA_ARGS__})/sizeof(VALUE*)), \ ((VALUE*[]){__VA_ARGS__})), \ - (rb_scan_args_kw)(kw_flag, argc, argvp, fmt, ## __VA_ARGS__)) + (rb_scan_args_kw)(kw_flag, argc, argvp, fmt, __VA_ARGS__ /**/)) #endif #endif /* RUBY3_SCAN_ARGS_H */ diff --git a/include/ruby/3/special_consts.h b/include/ruby/3/special_consts.h index 683cebf1ed779a..3ef7b57a985cca 100644 --- a/include/ruby/3/special_consts.h +++ b/include/ruby/3/special_consts.h @@ -82,7 +82,7 @@ ruby_special_consts { RUBY_FIXNUM_FLAG = 0x01, /* ...xxxx xxx1 */ RUBY_FLONUM_MASK = 0x03, /* ...0000 0011 */ RUBY_FLONUM_FLAG = 0x02, /* ...xxxx xx10 */ - RUBY_SYMBOL_FLAG = 0x0c /* ...xxxx 1100 */ + RUBY_SYMBOL_FLAG = 0x0c, /* ...xxxx 1100 */ #else RUBY_Qfalse = 0x00, /* ...0000 0000 */ RUBY_Qtrue = 0x02, /* ...0000 0010 */ @@ -92,12 +92,11 @@ ruby_special_consts { RUBY_FIXNUM_FLAG = 0x01, /* ...xxxx xxx1 */ RUBY_FLONUM_MASK = 0x00, /* any values ANDed with FLONUM_MASK cannot be FLONUM_FLAG */ RUBY_FLONUM_FLAG = 0x02, /* ...0000 0010 */ - RUBY_SYMBOL_FLAG = 0x0e /* ...0000 1110 */ + RUBY_SYMBOL_FLAG = 0x0e, /* ...0000 1110 */ #endif -}; -/** Least significant 8 bits are reserved. */ -enum { RUBY_SPECIAL_SHIFT = 8 }; + RUBY_SPECIAL_SHIFT = 8 /** Least significant 8 bits are reserved. */ +}; RUBY3_ATTR_CONST() RUBY3_ATTR_CONSTEXPR(CXX11) diff --git a/internal/process.h b/internal/process.h index b47f857bb4b609..1ee9b03cca5d42 100644 --- a/internal/process.h +++ b/internal/process.h @@ -22,6 +22,7 @@ #include "ruby/ruby.h" /* for VALUE */ #include "internal/imemo.h" /* for RB_IMEMO_TMPBUF_PTR */ +#include "internal/warnings.h" /* for COMPILER_WARNING_PUSH */ #define RB_MAX_GROUPS (65536) @@ -113,4 +114,17 @@ ARGVSTR2ARGC(VALUE argv_str) return i - 1; } +#ifdef HAVE_WORKING_FORK +COMPILER_WARNING_PUSH +#if __has_warning("-Wdeprecated-declarations") || RUBY3_COMPILER_IS(GCC) +COMPILER_WARNING_IGNORED(-Wdeprecated-declarations) +#endif +static inline rb_pid_t +rb_fork(void) +{ + return fork(); +} +COMPILER_WARNING_POP +#endif + #endif /* INTERNAL_PROCESS_H */ diff --git a/internal/sanitizers.h b/internal/sanitizers.h index 81ee7e3ea51895..628c225439238d 100644 --- a/internal/sanitizers.h +++ b/internal/sanitizers.h @@ -46,7 +46,7 @@ # define ATTRIBUTE_NO_ADDRESS_SAFETY_ANALYSIS(x) x #endif -#if defined(NO_SANITIZE) && defined(__GNUC__) &&! defined(__clang__) +#if defined(NO_SANITIZE) && RUBY3_COMPILER_IS(GCC) /* GCC warns about unknown sanitizer, which is annoying. */ # include "internal/warnings.h" # undef NO_SANITIZE diff --git a/io.c b/io.c index 7f43ca36d608fc..44f608753f40f3 100644 --- a/io.c +++ b/io.c @@ -13014,53 +13014,55 @@ argf_write(VALUE argf, VALUE str) } void -rb_readwrite_sys_fail(enum rb_io_wait_readwrite writable, const char *mesg) +rb_readwrite_sys_fail(enum rb_io_wait_readwrite waiting, const char *mesg) { - rb_readwrite_syserr_fail(writable, errno, mesg); + rb_readwrite_syserr_fail(waiting, errno, mesg); } void -rb_readwrite_syserr_fail(enum rb_io_wait_readwrite writable, int n, const char *mesg) +rb_readwrite_syserr_fail(enum rb_io_wait_readwrite waiting, int n, const char *mesg) { - VALUE arg; + VALUE arg, c = Qnil; arg = mesg ? rb_str_new2(mesg) : Qnil; - if (writable == RB_IO_WAIT_WRITABLE) { + switch (waiting) { + case RB_IO_WAIT_WRITABLE: switch (n) { case EAGAIN: - rb_exc_raise(rb_class_new_instance(1, &arg, rb_eEAGAINWaitWritable)); + c = rb_eEAGAINWaitWritable; break; #if EAGAIN != EWOULDBLOCK case EWOULDBLOCK: - rb_exc_raise(rb_class_new_instance(1, &arg, rb_eEWOULDBLOCKWaitWritable)); + c = rb_eEWOULDBLOCKWaitWritable; break; #endif case EINPROGRESS: - rb_exc_raise(rb_class_new_instance(1, &arg, rb_eEINPROGRESSWaitWritable)); + c = rb_eEINPROGRESSWaitWritable; break; default: - rb_mod_sys_fail_str(rb_mWaitWritable, arg); + rb_mod_syserr_fail_str(rb_mWaitWritable, n, arg); } - } - else if (writable == RB_IO_WAIT_READABLE) { + break; + case RB_IO_WAIT_READABLE: switch (n) { case EAGAIN: - rb_exc_raise(rb_class_new_instance(1, &arg, rb_eEAGAINWaitReadable)); + c = rb_eEAGAINWaitReadable; break; #if EAGAIN != EWOULDBLOCK case EWOULDBLOCK: - rb_exc_raise(rb_class_new_instance(1, &arg, rb_eEWOULDBLOCKWaitReadable)); + c = rb_eEWOULDBLOCKWaitReadable; break; #endif case EINPROGRESS: - rb_exc_raise(rb_class_new_instance(1, &arg, rb_eEINPROGRESSWaitReadable)); + c = rb_eEINPROGRESSWaitReadable; break; default: - rb_mod_sys_fail_str(rb_mWaitReadable, arg); + rb_mod_syserr_fail_str(rb_mWaitReadable, n, arg); } + break; + default: + rb_bug("invalid read/write type passed to rb_readwrite_sys_fail: %d", waiting); } - else { - rb_bug("invalid read/write type passed to rb_readwrite_sys_fail: %d", writable); - } + rb_exc_raise(rb_class_new_instance(1, &arg, c)); } static VALUE diff --git a/kernel.rb b/kernel.rb index d3fa9d80531856..aa3f8b72a46a4e 100644 --- a/kernel.rb +++ b/kernel.rb @@ -26,4 +26,28 @@ module Kernel def clone(freeze: nil) __builtin_rb_obj_clone2(freeze) end + + module_function + + # + # call-seq: + # Float(arg, exception: true) -> float or nil + # + # Returns arg converted to a float. Numeric types are + # converted directly, and with exception to String and + # nil the rest are converted using + # arg.to_f. Converting a String with invalid + # characters will result in a ArgumentError. Converting + # nil generates a TypeError. Exceptions can be + # suppressed by passing exception: false. + # + # Float(1) #=> 1.0 + # Float("123.456") #=> 123.456 + # Float("123.0_badstring") #=> ArgumentError: invalid value for Float(): "123.0_badstring" + # Float(nil) #=> TypeError: can't convert nil into Float + # Float("123.0_badstring", exception: false) #=> nil + # + def Float(arg, exception: true) + __builtin_rb_f_float(arg, exception) + end end diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index 443458f2d99c86..3ef0e28f2678d2 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -122,7 +122,9 @@ def help(cli = nil) else command = "bundle-#{cli}" end - man_path = File.expand_path("../../../man", __FILE__) + man_path = File.expand_path("../../../man", __FILE__) + # man files are located under the share directory with the default gems of bundler + man_path = File.expand_path("../../../../../share/man/man1", __FILE__) unless File.directory?(man_path) man_pages = Hash[Dir.glob(File.join(man_path, "*")).grep(/.*\.\d*\Z/).collect do |f| [File.basename(f, ".*"), f] end] diff --git a/lib/irb/cmd/info.rb b/lib/irb/cmd/info.rb new file mode 100644 index 00000000000000..53ec71d754739f --- /dev/null +++ b/lib/irb/cmd/info.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: false + +require_relative "nop" + +# :stopdoc: +module IRB + module ExtendCommand + class Info < Nop + def execute + Class.new { + def inspect + str = "Ruby version: #{RUBY_VERSION}\n" + str += "IRB version: #{IRB.version}\n" + str += "InputMethod: #{IRB.CurrentContext.io.inspect}\n" + str += ".irbrc path: #{IRB.rc_file}\n" if File.exist?(IRB.rc_file) + str + end + alias_method :to_s, :inspect + }.new + end + end + end +end +# :startdoc: diff --git a/lib/irb/extend-command.rb b/lib/irb/extend-command.rb index de145e962db85d..2f4fcfb5c6f1fe 100644 --- a/lib/irb/extend-command.rb +++ b/lib/irb/extend-command.rb @@ -121,6 +121,10 @@ def irb_context [:help, NO_OVERRIDE], ], + [ + :irb_info, :Info, "irb/cmd/info" + ], + ] # Installs the default irb commands: @@ -169,11 +173,14 @@ def #{cmd_name}(*opts, &b) args << "&block" args = args.join(", ") line = __LINE__; eval %[ - def #{cmd_name}(\#{args}) - ExtendCommand::#{cmd_class}.execute(irb_context, \#{args}) + unless self.class.class_variable_defined?(:@@#{cmd_name}_) + self.class.class_variable_set(:@@#{cmd_name}_, true) + def #{cmd_name}_(\#{args}) + ExtendCommand::#{cmd_class}.execute(irb_context, \#{args}) + end end ], nil, __FILE__, line - send :#{cmd_name}, *opts, &b + send :#{cmd_name}_, *opts, &b end ], nil, __FILE__, line else diff --git a/lib/irb/init.rb b/lib/irb/init.rb index 37d1f8d6091041..da40bee5e19f9c 100644 --- a/lib/irb/init.rb +++ b/lib/irb/init.rb @@ -271,10 +271,19 @@ def IRB.rc_file_generators if irbrc = ENV["IRBRC"] yield proc{|rc| rc == "rc" ? irbrc : irbrc+rc} end + if xdg_config_home = ENV["XDG_CONFIG_HOME"] + irb_home = File.join(xdg_config_home, "irb") + unless File.exist? irb_home + require 'fileutils' + FileUtils.mkdir_p irb_home + end + yield proc{|rc| irb_home + "/irb#{rc}"} + end if home = ENV["HOME"] yield proc{|rc| home+"/.irb#{rc}"} end current_dir = Dir.pwd + yield proc{|rc| current_dir+"/.config/irb/irb#{rc}"} yield proc{|rc| current_dir+"/.irb#{rc}"} yield proc{|rc| current_dir+"/irb#{rc.sub(/\A_?/, '.')}"} yield proc{|rc| current_dir+"/_irb#{rc}"} diff --git a/lib/irb/input-method.rb b/lib/irb/input-method.rb index 9fbbaeb0f33e32..8f337e0eac8f91 100644 --- a/lib/irb/input-method.rb +++ b/lib/irb/input-method.rb @@ -43,6 +43,11 @@ def gets def readable_after_eof? false end + + # For debug message + def inspect + 'Abstract InputMethod' + end end class StdioInputMethod < InputMethod @@ -93,6 +98,11 @@ def line(line_no) def encoding @stdin.external_encoding end + + # For debug message + def inspect + 'StdioInputMethod' + end end # Use a File for IO with irb, see InputMethod @@ -125,6 +135,11 @@ def gets def encoding @io.external_encoding end + + # For debug message + def inspect + 'FileInputMethod' + end end begin @@ -202,6 +217,15 @@ def encoding end Readline.completion_append_character = nil Readline.completion_proc = IRB::InputCompletor::CompletionProc + + # For debug message + def inspect + readline_impl = (defined?(Reline) && Readline == Reline) ? 'Reline' : 'ext/readline' + str = "ReadlineInputMethod with #{readline_impl} #{Readline::VERSION}" + inputrc_path = File.expand_path(ENV['INPUTRC'] || '~/.inputrc') + str += " and #{inputrc_path}" if File.exist?(inputrc_path) + str + end end rescue LoadError end @@ -297,5 +321,18 @@ def line(line_no) def encoding @stdin.external_encoding end + + # For debug message + def inspect + config = Reline::Config.new + str = "ReidlineInputMethod with Reline #{Reline::VERSION}" + if config.respond_to?(:inputrc_path) + inputrc_path = config.inputrc_path + else + inputrc_path = File.expand_path(ENV['INPUTRC'] || '~/.inputrc') + end + str += " and #{inputrc_path}" if File.exist?(inputrc_path) + str + end end end diff --git a/lib/matrix.rb b/lib/matrix.rb index 81e3f596cad441..336a92877b9785 100644 --- a/lib/matrix.rb +++ b/lib/matrix.rb @@ -72,8 +72,8 @@ class Matrix # # Creates a matrix where each argument is a row. # Matrix[ [25, 93], [-1, 66] ] - # => 25 93 - # -1 66 + # # => 25 93 + # # -1 66 # def Matrix.[](*rows) rows(rows, false) @@ -84,8 +84,8 @@ def Matrix.[](*rows) # of the matrix. If the optional argument +copy+ is false, use the given # arrays as the internal structure of the matrix without copying. # Matrix.rows([[25, 93], [-1, 66]]) - # => 25 93 - # -1 66 + # # => 25 93 + # # -1 66 # def Matrix.rows(rows, copy = true) rows = convert_to_array(rows, copy) @@ -102,8 +102,8 @@ def Matrix.rows(rows, copy = true) # # Creates a matrix using +columns+ as an array of column vectors. # Matrix.columns([[25, 93], [-1, 66]]) - # => 25 -1 - # 93 66 + # # => 25 -1 + # # 93 66 # def Matrix.columns(columns) rows(columns, false).transpose @@ -116,9 +116,9 @@ def Matrix.columns(columns) # Returns an enumerator if no block is given. # # m = Matrix.build(2, 4) {|row, col| col - row } - # => Matrix[[0, 1, 2, 3], [-1, 0, 1, 2]] + # # => Matrix[[0, 1, 2, 3], [-1, 0, 1, 2]] # m = Matrix.build(3) { rand } - # => a 3x3 matrix with random elements + # # => a 3x3 matrix with random elements # def Matrix.build(row_count, column_count = row_count) row_count = CoercionHelper.coerce_to_int(row_count) @@ -136,9 +136,9 @@ def Matrix.build(row_count, column_count = row_count) # # Creates a matrix where the diagonal elements are composed of +values+. # Matrix.diagonal(9, 5, -3) - # => 9 0 0 - # 0 5 0 - # 0 0 -3 + # # => 9 0 0 + # # 0 5 0 + # # 0 0 -3 # def Matrix.diagonal(*values) size = values.size @@ -155,8 +155,8 @@ def Matrix.diagonal(*values) # Creates an +n+ by +n+ diagonal matrix where each diagonal element is # +value+. # Matrix.scalar(2, 5) - # => 5 0 - # 0 5 + # # => 5 0 + # # 0 5 # def Matrix.scalar(n, value) diagonal(*Array.new(n, value)) @@ -165,8 +165,8 @@ def Matrix.scalar(n, value) # # Creates an +n+ by +n+ identity matrix. # Matrix.identity(2) - # => 1 0 - # 0 1 + # # => 1 0 + # # 0 1 # def Matrix.identity(n) scalar(n, 1) @@ -179,8 +179,8 @@ class << Matrix # # Creates a zero matrix. # Matrix.zero(2) - # => 0 0 - # 0 0 + # # => 0 0 + # # 0 0 # def Matrix.zero(row_count, column_count = row_count) rows = Array.new(row_count){Array.new(column_count, 0)} @@ -191,7 +191,7 @@ def Matrix.zero(row_count, column_count = row_count) # Creates a single-row matrix where the values of that row are as given in # +row+. # Matrix.row_vector([4,5,6]) - # => 4 5 6 + # # => 4 5 6 # def Matrix.row_vector(row) row = convert_to_array(row) @@ -202,9 +202,9 @@ def Matrix.row_vector(row) # Creates a single-column matrix where the values of that column are as given # in +column+. # Matrix.column_vector([4,5,6]) - # => 4 - # 5 - # 6 + # # => 4 + # # 5 + # # 6 # def Matrix.column_vector(column) column = convert_to_array(column) @@ -217,12 +217,12 @@ def Matrix.column_vector(column) # # m = Matrix.empty(2, 0) # m == Matrix[ [], [] ] - # => true + # # => true # n = Matrix.empty(0, 3) # n == Matrix.columns([ [], [], [] ]) - # => true + # # => true # m * n - # => Matrix[[0, 0, 0], [0, 0, 0]] + # # => Matrix[[0, 0, 0], [0, 0, 0]] # def Matrix.empty(row_count = 0, column_count = 0) raise ArgumentError, "One size must be 0" if column_count != 0 && row_count != 0 @@ -276,6 +276,8 @@ def Matrix.hstack(x, *matrices) new result, total_column_count end + # :call-seq: + # Matrix.combine(*matrices) { |*elements| ... } # # Create a matrix by combining matrices entrywise, using the given block # @@ -301,12 +303,21 @@ def Matrix.combine(*matrices) new rows, x.column_count end + # :call-seq: + # combine(*other_matrices) { |*elements| ... } + # + # Creates new matrix by combining with other_matrices entrywise, + # using the given block. + # + # x = Matrix[[6, 6], [4, 4]] + # y = Matrix[[1, 2], [3, 4]] + # x.combine(y) {|a, b| a - b} # => Matrix[[5, 4], [1, 0]] def combine(*matrices, &block) Matrix.combine(self, *matrices, &block) end # - # Matrix.new is private; use Matrix.rows, columns, [], etc... to create. + # Matrix.new is private; use ::rows, ::columns, ::[], etc... to create. # def initialize(rows, column_count = rows[0].size) # No checking is done at this point. rows must be an Array of Arrays. @@ -491,8 +502,8 @@ def column(j) # :yield: e # * :strict_upper: yields only elements above the diagonal # * :upper: yields only elements on or above the diagonal # Matrix[ [1,2], [3,4] ].collect { |e| e**2 } - # => 1 4 - # 9 16 + # # => 1 4 + # # 9 16 # def collect(which = :all, &block) # :yield: e return to_enum(:collect, which) unless block_given? @@ -537,9 +548,9 @@ def freeze # * :strict_upper: yields only elements above the diagonal # * :upper: yields only elements on or above the diagonal # - # Matrix[ [1,2], [3,4] ].each { |e| puts e } - # # => prints the numbers 1 to 4 - # Matrix[ [1,2], [3,4] ].each(:strict_lower).to_a # => [3] + # Matrix[ [1,2], [3,4] ].each { |e| puts e } + # # => prints the numbers 1 to 4 + # Matrix[ [1,2], [3,4] ].each(:strict_lower).to_a # => [3] # def each(which = :all, &block) # :yield: e return to_enum :each, which unless block_given? @@ -688,8 +699,8 @@ def index(*args) # * row_range, col_range # # Matrix.diagonal(9, 5, -3).minor(0..1, 0..2) - # => 9 0 0 - # 0 5 0 + # # => 9 0 0 + # # 0 5 0 # # Like Array#[], negative indices count backward from the end of the # row or column (-1 is the last element). Returns nil if the starting @@ -732,9 +743,9 @@ def minor(*param) # Returns the submatrix obtained by deleting the specified row and column. # # Matrix.diagonal(9, 5, -3, 4).first_minor(1, 2) - # => 9 0 0 - # 0 0 0 - # 0 0 4 + # # => 9 0 0 + # # 0 0 0 + # # 0 0 4 # def first_minor(row, column) raise RuntimeError, "first_minor of empty matrix is not defined" if empty? @@ -761,7 +772,7 @@ def first_minor(row, column) # the first minor by (-1)**(row + column). # # Matrix.diagonal(9, 5, -3, 4).cofactor(1, 1) - # => -108 + # # => -108 # def cofactor(row, column) raise RuntimeError, "cofactor of empty matrix is not defined" if empty? @@ -775,8 +786,8 @@ def cofactor(row, column) # Returns the adjugate of the matrix. # # Matrix[ [7,6],[3,9] ].adjugate - # => 9 -6 - # -3 7 + # # => 9 -6 + # # -3 7 # def adjugate raise ErrDimensionMismatch unless square? @@ -789,10 +800,10 @@ def adjugate # Returns the Laplace expansion along given row or column. # # Matrix[[7,6], [3,9]].laplace_expansion(column: 1) - # => 45 + # # => 45 # # Matrix[[Vector[1, 0], Vector[0, 1]], [2, 3]].laplace_expansion(row: 0) - # => Vector[3, -2] + # # => Vector[3, -2] # # def laplace_expansion(row: nil, column: nil) @@ -879,11 +890,12 @@ def normal? # def orthogonal? raise ErrDimensionMismatch unless square? - rows.each_with_index do |row, i| - column_count.times do |j| + + rows.each_with_index do |row_i, i| + rows.each_with_index do |row_j, j| s = 0 row_count.times do |k| - s += row[k] * rows[k][j] + s += row_i[k] * row_j[k] end return false unless s == (i == j ? 1 : 0) end @@ -972,11 +984,11 @@ def antisymmetric? # def unitary? raise ErrDimensionMismatch unless square? - rows.each_with_index do |row, i| - column_count.times do |j| + rows.each_with_index do |row_i, i| + rows.each_with_index do |row_j, j| s = 0 row_count.times do |k| - s += row[k].conj * rows[k][j] + s += row_i[k].conj * row_j[k] end return false unless s == (i == j ? 1 : 0) end @@ -1039,31 +1051,33 @@ def hash # # Matrix multiplication. # Matrix[[2,4], [6,8]] * Matrix.identity(2) - # => 2 4 - # 6 8 + # # => 2 4 + # # 6 8 # def *(m) # m is matrix or vector or number case(m) when Numeric - rows = @rows.collect {|row| + new_rows = @rows.collect {|row| row.collect {|e| e * m } } - return new_matrix rows, column_count + return new_matrix new_rows, column_count when Vector m = self.class.column_vector(m) r = self * m return r.column(0) when Matrix raise ErrDimensionMismatch if column_count != m.row_count - - rows = Array.new(row_count) {|i| - Array.new(m.column_count) {|j| - (0 ... column_count).inject(0) do |vij, k| - vij + self[i, k] * m[k, j] + m_rows = m.rows + new_rows = rows.map do |row_i| + Array.new(m.column_count) do |j| + vij = 0 + column_count.times do |k| + vij += row_i[k] * m_rows[k][j] end - } - } - return new_matrix rows, m.column_count + vij + end + end + return new_matrix new_rows, m.column_count else return apply_through_coercion(m, __method__) end @@ -1072,8 +1086,8 @@ def *(m) # m is matrix or vector or number # # Matrix addition. # Matrix.scalar(2,5) + Matrix[[1,0], [-4,7]] - # => 6 0 - # -4 12 + # # => 6 0 + # # -4 12 # def +(m) case m @@ -1099,8 +1113,8 @@ def +(m) # # Matrix subtraction. # Matrix[[1,5], [4,2]] - Matrix[[9,3], [-4,1]] - # => -8 2 - # 8 1 + # # => -8 2 + # # 8 1 # def -(m) case m @@ -1126,8 +1140,8 @@ def -(m) # # Matrix division (multiplication by the inverse). # Matrix[[7,6], [3,9]] / Matrix[[2,9], [3,1]] - # => -7 1 - # -3 -6 + # # => -7 1 + # # -3 -6 # def /(other) case other @@ -1146,8 +1160,8 @@ def /(other) # # Hadamard product # Matrix[[1,2], [3,4]].hadamard_product(Matrix[[1,2], [3,2]]) - # => 1 4 - # 9 8 + # # => 1 4 + # # 9 8 # def hadamard_product(m) combine(m){|a, b| a * b} @@ -1157,8 +1171,8 @@ def hadamard_product(m) # # Returns the inverse of the matrix. # Matrix[[-1, -1], [0, -1]].inverse - # => -1 1 - # 0 -1 + # # => -1 1 + # # 0 -1 # def inverse raise ErrDimensionMismatch unless square? @@ -1216,8 +1230,8 @@ def inverse # Non integer exponents will be handled by diagonalizing the matrix. # # Matrix[[7,6], [3,9]] ** 2 - # => 67 96 - # 48 99 + # # => 67 96 + # # 48 99 # def **(other) case other @@ -1246,6 +1260,11 @@ def +@ self end + # Unary matrix negation. + # + # -Matrix[[1,5], [4,2]] + # # => -1 -5 + # # -4 -2 def -@ collect {|e| -e } end @@ -1269,7 +1288,7 @@ def abs # Consider using exact types like Rational or BigDecimal instead. # # Matrix[[7,6], [3,9]].determinant - # => 45 + # # => 45 # def determinant raise ErrDimensionMismatch unless square? @@ -1377,7 +1396,7 @@ def hstack(*matrices) # Consider using exact types like Rational or BigDecimal instead. # # Matrix[[7,6], [3,9]].rank - # => 2 + # # => 2 # def rank # We currently use Bareiss' multistep integer-preserving gaussian elimination @@ -1425,7 +1444,7 @@ def round(ndigits=0) # # Returns the trace (sum of diagonal elements) of the matrix. # Matrix[[7,6], [3,9]].trace - # => 16 + # # => 16 # def trace raise ErrDimensionMismatch unless square? @@ -1438,12 +1457,12 @@ def trace # # Returns the transpose of the matrix. # Matrix[[1,2], [3,4], [5,6]] - # => 1 2 - # 3 4 - # 5 6 + # # => 1 2 + # # 3 4 + # # 5 6 # Matrix[[1,2], [3,4], [5,6]].transpose - # => 1 3 5 - # 2 4 6 + # # => 1 3 5 + # # 2 4 6 # def transpose return self.class.empty(column_count, 0) if row_count.zero? @@ -1502,25 +1521,36 @@ def lup # # Returns the conjugate of the matrix. # Matrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]] - # => 1+2i i 0 - # 1 2 3 + # # => 1+2i i 0 + # # 1 2 3 # Matrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]].conjugate - # => 1-2i -i 0 - # 1 2 3 + # # => 1-2i -i 0 + # # 1 2 3 # def conjugate collect(&:conjugate) end alias_method :conj, :conjugate + # + # Returns the adjoint of the matrix. + # + # Matrix[ [i,1],[2,-i] ].adjoint + # # => -i 2 + # # 1 i + # + def adjoint + conjugate.transpose + end + # # Returns the imaginary part of the matrix. # Matrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]] - # => 1+2i i 0 - # 1 2 3 + # # => 1+2i i 0 + # # 1 2 3 # Matrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]].imaginary - # => 2i i 0 - # 0 0 0 + # # => 2i i 0 + # # 0 0 0 # def imaginary collect(&:imaginary) @@ -1530,11 +1560,11 @@ def imaginary # # Returns the real part of the matrix. # Matrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]] - # => 1+2i i 0 - # 1 2 3 + # # => 1+2i i 0 + # # 1 2 3 # Matrix[[Complex(1,2), Complex(0,1), 0], [1, 2, 3]].real - # => 1 0 0 - # 1 2 3 + # # => 1 0 0 + # # 1 2 3 # def real collect(&:real) @@ -1544,7 +1574,7 @@ def real # Returns an array containing matrices corresponding to the real and imaginary # parts of the matrix # - # m.rect == [m.real, m.imag] # ==> true for all matrices m + # m.rect == [m.real, m.imag] # ==> true for all matrices m # def rect [real, imag] @@ -1605,7 +1635,7 @@ def to_a # Deprecated. # - # Use map(&:to_f) + # Use map(&:to_f) def elements_to_f warn "Matrix#elements_to_f is deprecated, use map(&:to_f)", uplevel: 1 map(&:to_f) @@ -1613,7 +1643,7 @@ def elements_to_f # Deprecated. # - # Use map(&:to_i) + # Use map(&:to_i) def elements_to_i warn "Matrix#elements_to_i is deprecated, use map(&:to_i)", uplevel: 1 map(&:to_i) @@ -1621,7 +1651,7 @@ def elements_to_i # Deprecated. # - # Use map(&:to_r) + # Use map(&:to_r) def elements_to_r warn "Matrix#elements_to_r is deprecated, use map(&:to_r)", uplevel: 1 map(&:to_r) @@ -1857,8 +1887,8 @@ def **(other) # * #-@ # # Vector functions: -# * #inner_product(v), dot(v) -# * #cross_product(v), cross(v) +# * #inner_product(v), #dot(v) +# * #cross_product(v), #cross(v) # * #collect # * #collect! # * #magnitude @@ -1923,7 +1953,7 @@ def Vector.basis(size:, index:) # # Return a zero vector. # - # Vector.zero(3) => Vector[0, 0, 0] + # Vector.zero(3) # => Vector[0, 0, 0] # def Vector.zero(size) raise ArgumentError, "invalid size (#{size} for 0..)" if size < 0 @@ -2054,10 +2084,10 @@ def collect2(v) # :yield: e1, e2 # Returns +true+ iff all of vectors are linearly independent. # # Vector.independent?(Vector[1,0], Vector[0,1]) - # => true + # # => true # # Vector.independent?(Vector[1,2], Vector[2,4]) - # => false + # # => false # def Vector.independent?(*vs) vs.each do |v| @@ -2072,10 +2102,10 @@ def Vector.independent?(*vs) # Returns +true+ iff all of vectors are linearly independent. # # Vector[1,0].independent?(Vector[0,1]) - # => true + # # => true # # Vector[1,2].independent?(Vector[2,4]) - # => false + # # => false # def independent?(*vs) self.class.independent?(self, *vs) @@ -2212,7 +2242,7 @@ def -@ # # Returns the inner product of this vector with the other. - # Vector[4,7].inner_product Vector[10,1] => 47 + # Vector[4,7].inner_product Vector[10,1] # => 47 # def inner_product(v) raise ErrDimensionMismatch if size != v.size @@ -2227,7 +2257,7 @@ def inner_product(v) # # Returns the cross product of this vector with the others. - # Vector[1, 0, 0].cross_product Vector[0, 1, 0] => Vector[0, 0, 1] + # Vector[1, 0, 0].cross_product Vector[0, 1, 0] # => Vector[0, 0, 1] # # It is generalized to other dimensions to return a vector perpendicular # to the arguments. @@ -2282,7 +2312,7 @@ def collect!(&block) # # Returns the modulus (Pythagorean distance) of the vector. - # Vector[5,8,2].r => 9.643650761 + # Vector[5,8,2].r # => 9.643650761 # def magnitude Math.sqrt(@elements.inject(0) {|v, e| v + e.abs2}) @@ -2305,7 +2335,7 @@ class ZeroVectorError < StandardError # Returns a new vector with the same direction but with norm 1. # v = Vector[5,8,2].normalize # # => Vector[0.5184758473652127, 0.8295613557843402, 0.20739033894608505] - # v.norm => 1.0 + # v.norm # => 1.0 # def normalize n = magnitude diff --git a/lib/matrix/matrix.gemspec b/lib/matrix/matrix.gemspec index 75f6b69a98f452..24e2d596740cdb 100644 --- a/lib/matrix/matrix.gemspec +++ b/lib/matrix/matrix.gemspec @@ -18,7 +18,7 @@ Gem::Specification.new do |spec| spec.homepage = "https://github.com/ruby/matrix" spec.license = "BSD-2-Clause" - spec.files = [".gitignore", ".travis.yml", "Gemfile", "LICENSE.txt", "README.md", "Rakefile", "bin/console", "bin/setup", "lib/matrix.rb", "lib/matrix/eigenvalue_decomposition.rb", "lib/matrix/lup_decomposition.rb", "lib/matrix/version.rb", "matrix.gemspec"] + spec.files = [".gitignore", "Gemfile", "LICENSE.txt", "README.md", "Rakefile", "bin/console", "bin/setup", "lib/matrix.rb", "lib/matrix/eigenvalue_decomposition.rb", "lib/matrix/lup_decomposition.rb", "lib/matrix/version.rb", "matrix.gemspec"] spec.bindir = "exe" spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] diff --git a/lib/matrix/version.rb b/lib/matrix/version.rb index e6f91dae3c3e83..ce9ea828fdc5cd 100644 --- a/lib/matrix/version.rb +++ b/lib/matrix/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true class Matrix - VERSION = "0.2.0" + VERSION = "0.3.0" end diff --git a/lib/racc/parser-text.rb b/lib/racc/parser-text.rb index 8dadeadee51c94..c40736bc99dd6e 100644 --- a/lib/racc/parser-text.rb +++ b/lib/racc/parser-text.rb @@ -181,8 +181,8 @@ class ParseError < StandardError; end # Your own parser is completely yours. module Racc - unless defined?(Racc_No_Extentions) - Racc_No_Extentions = false # :nodoc: + unless defined?(Racc_No_Extensions) + Racc_No_Extensions = false # :nodoc: end class Parser @@ -202,7 +202,7 @@ class Parser unless new.respond_to?(:_racc_do_parse_c, true) raise LoadError, 'old cparse.so' end - if Racc_No_Extentions + if Racc_No_Extensions raise LoadError, 'selecting ruby version of racc runtime core' end diff --git a/lib/racc/parser.rb b/lib/racc/parser.rb index 8346f0193f1b27..e1133f75904034 100644 --- a/lib/racc/parser.rb +++ b/lib/racc/parser.rb @@ -179,8 +179,8 @@ class ParseError < StandardError; end # Your own parser is completely yours. module Racc - unless defined?(Racc_No_Extentions) - Racc_No_Extentions = false # :nodoc: + unless defined?(Racc_No_Extensions) + Racc_No_Extensions = false # :nodoc: end class Parser @@ -200,7 +200,7 @@ class Parser unless new.respond_to?(:_racc_do_parse_c, true) raise LoadError, 'old cparse.so' end - if Racc_No_Extentions + if Racc_No_Extensions raise LoadError, 'selecting ruby version of racc runtime core' end diff --git a/lib/rdoc.rb b/lib/rdoc.rb index fc8ad9e1445e08..2d3f8c1122451d 100644 --- a/lib/rdoc.rb +++ b/lib/rdoc.rb @@ -120,6 +120,27 @@ def self.load_yaml end end + def self.home + rdoc_dir = begin + File.expand_path('~/.rdoc') + rescue ArgumentError + end + + if File.directory?(rdoc_dir) + rdoc_dir + else + begin + # XDG + xdg_data_home = ENV["XDG_DATA_HOME"] || File.join(File.expand_path("~"), '.local', 'share') + unless File.exist?(xdg_data_home) + FileUtils.mkdir_p xdg_data_home + end + File.join xdg_data_home, "rdoc" + rescue Errno::EACCES + end + end + end + autoload :RDoc, 'rdoc/rdoc' autoload :CrossReference, 'rdoc/cross_reference' diff --git a/lib/rdoc/ri/paths.rb b/lib/rdoc/ri/paths.rb index f76721d318e34b..7891d1e0acc793 100644 --- a/lib/rdoc/ri/paths.rb +++ b/lib/rdoc/ri/paths.rb @@ -12,23 +12,9 @@ module RDoc::RI::Paths version = RbConfig::CONFIG['ruby_version'] - BASE = if RbConfig::CONFIG.key? 'ridir' then - File.join RbConfig::CONFIG['ridir'], version - else - File.join RbConfig::CONFIG['datadir'], 'ri', version - end - - homedir = begin - File.expand_path('~') - rescue ArgumentError - end - - homedir ||= ENV['HOME'] || - ENV['USERPROFILE'] || ENV['HOMEPATH'] # for 1.8 compatibility - - HOMEDIR = if homedir then - File.join homedir, ".rdoc" - end + BASE = File.join RbConfig::CONFIG['ridir'], version + + HOMEDIR = RDoc.home #:startdoc: ## diff --git a/lib/rdoc/store.rb b/lib/rdoc/store.rb index 0f6cd06e3cf598..05d8383c86dbf8 100644 --- a/lib/rdoc/store.rb +++ b/lib/rdoc/store.rb @@ -482,7 +482,7 @@ def friendly_path when :gem then parent = File.expand_path '..', @path "gem #{File.basename parent}" - when :home then '~/.rdoc' + when :home then RDoc.home when :site then 'ruby site' when :system then 'ruby core' else @path diff --git a/lib/reline/config.rb b/lib/reline/config.rb index 53b868fd2e7fd5..deca11f0ab9734 100644 --- a/lib/reline/config.rb +++ b/lib/reline/config.rb @@ -3,8 +3,6 @@ class Reline::Config attr_reader :test_mode - DEFAULT_PATH = '~/.inputrc' - KEYSEQ_PATTERN = /\\(?:C|Control)-[A-Za-z_]|\\(?:M|Meta)-[0-9A-Za-z_]|\\(?:C|Control)-(?:M|Meta)-[A-Za-z_]|\\(?:M|Meta)-(?:C|Control)-[A-Za-z_]|\\e|\\[\\\"\'abdfnrtv]|\\\d{1,3}|\\x\h{1,2}|./ class InvalidInputrc < RuntimeError @@ -54,7 +52,8 @@ def initialize @key_actors[:emacs] = Reline::KeyActor::Emacs.new @key_actors[:vi_insert] = Reline::KeyActor::ViInsert.new @key_actors[:vi_command] = Reline::KeyActor::ViCommand.new - @history_size = 500 + # https://tiswww.case.edu/php/chet/readline/readline.html#IDX25 + @history_size = -1 # unlimited @keyseq_timeout = 500 @test_mode = false end @@ -86,14 +85,31 @@ def keymap def inputrc_path case ENV['INPUTRC'] when nil, '' - DEFAULT_PATH else - ENV['INPUTRC'] + return File.expand_path(ENV['INPUTRC']) + end + + # In the XDG Specification, if ~/.config/readline/inputrc exists, then + # ~/.inputrc should not be read, but for compatibility with GNU Readline, + # if ~/.inputrc exists, then it is given priority. + home_rc_path = File.expand_path('~/.inputrc') + return home_rc_path if File.exist?(home_rc_path) + + case path = ENV['XDG_CONFIG_HOME'] + when nil, '' + else + path = File.join(path, 'readline/inputrc') + return path if File.exist?(path) and path == File.expand_path(path) end + + path = File.expand_path('~/.config/readline/inputrc') + return path if File.exist?(path) + + return home_rc_path end def read(file = nil) - file ||= File.expand_path(inputrc_path) + file ||= inputrc_path begin if file.respond_to?(:readlines) lines = file.readlines diff --git a/lib/reline/history.rb b/lib/reline/history.rb index d95f1cebc3b8e4..7a1ed6b90baa41 100644 --- a/lib/reline/history.rb +++ b/lib/reline/history.rb @@ -29,27 +29,47 @@ def concat(*val) end def push(*val) - diff = size + val.size - @config.history_size - if diff > 0 - if diff <= size - shift(diff) - else - diff -= size - clear - val.shift(diff) + # If history_size is zero, all histories are dropped. + return self if @config.history_size.zero? + # If history_size is negative, history size is unlimited. + if @config.history_size.positive? + diff = size + val.size - @config.history_size + if diff > 0 + if diff <= size + shift(diff) + else + diff -= size + clear + val.shift(diff) + end end end - super(*(val.map{ |v| String.new(v, encoding: Reline.encoding_system_needs) })) + super(*(val.map{ |v| + String.new(v, encoding: Reline.encoding_system_needs) + })) end def <<(val) - shift if size + 1 > @config.history_size + # If history_size is zero, all histories are dropped. + return self if @config.history_size.zero? + # If history_size is negative, history size is unlimited. + if @config.history_size.positive? + shift if size + 1 > @config.history_size + end super(String.new(val, encoding: Reline.encoding_system_needs)) end private def check_index(index) index += size if index < 0 - raise RangeError.new("index=<#{index}>") if index < -@config.history_size or @config.history_size < index + if index < -2147483648 or 2147483647 < index + raise RangeError.new("integer #{index} too big to convert to `int'") + end + # If history_size is negative, history size is unlimited. + if @config.history_size.positive? + if index < -@config.history_size or @config.history_size < index + raise RangeError.new("index=<#{index}>") + end + end raise IndexError.new("index=<#{index}>") if index < 0 or size <= index index end diff --git a/lib/reline/key_actor/emacs.rb b/lib/reline/key_actor/emacs.rb index 3886d17f226779..1e51d4fa189857 100644 --- a/lib/reline/key_actor/emacs.rb +++ b/lib/reline/key_actor/emacs.rb @@ -37,9 +37,9 @@ class Reline::KeyActor::Emacs < Reline::KeyActor::Base # 17 ^Q :ed_quoted_insert, # 18 ^R - :ed_search_prev_history, + :vi_search_prev, # 19 ^S - :ed_search_next_history, + :vi_search_next, # 20 ^T :ed_transpose_chars, # 21 ^U @@ -413,11 +413,11 @@ class Reline::KeyActor::Emacs < Reline::KeyActor::Base # 205 M-M :ed_unassigned, # 206 M-N - :ed_search_next_history, + :vi_search_next, # 207 M-O :ed_sequence_lead_in, # 208 M-P - :ed_search_prev_history, + :vi_search_prev, # 209 M-Q :ed_unassigned, # 210 M-R @@ -477,11 +477,11 @@ class Reline::KeyActor::Emacs < Reline::KeyActor::Base # 237 M-m :ed_unassigned, # 238 M-n - :ed_search_next_history, + :vi_search_next, # 239 M-o :ed_unassigned, # 240 M-p - :ed_search_prev_history, + :vi_search_prev, # 241 M-q :ed_unassigned, # 242 M-r diff --git a/lib/reline/key_actor/vi_command.rb b/lib/reline/key_actor/vi_command.rb index 865dfa2e00aedb..54b4a60383ffc2 100644 --- a/lib/reline/key_actor/vi_command.rb +++ b/lib/reline/key_actor/vi_command.rb @@ -37,7 +37,7 @@ class Reline::KeyActor::ViCommand < Reline::KeyActor::Base # 17 ^Q :ed_ignore, # 18 ^R - :ed_search_prev_history, + :vi_search_prev, # 19 ^S :ed_ignore, # 20 ^T @@ -151,7 +151,7 @@ class Reline::KeyActor::ViCommand < Reline::KeyActor::Base # 74 J :vi_join_lines, # 75 K - :ed_search_prev_history, + :vi_search_prev, # 76 L :ed_unassigned, # 77 M diff --git a/lib/reline/key_actor/vi_insert.rb b/lib/reline/key_actor/vi_insert.rb index 06e94a9c30c3b7..b8e89f81d8075d 100644 --- a/lib/reline/key_actor/vi_insert.rb +++ b/lib/reline/key_actor/vi_insert.rb @@ -37,9 +37,9 @@ class Reline::KeyActor::ViInsert < Reline::KeyActor::Base # 17 ^Q :ed_ignore, # 18 ^R - :ed_search_prev_history, + :vi_search_prev, # 19 ^S - :ed_search_next_history, + :vi_search_next, # 20 ^T :ed_insert, # 21 ^U diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb index 095a7b5a095079..ab4b0915f30223 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -1330,7 +1330,7 @@ def finish end end - private def search_history(key) + private def incremental_search_history(key) unless @history_pointer if @is_multiline @line_backup_in_history = whole_buffer @@ -1411,15 +1411,114 @@ def finish } end - private def ed_search_prev_history(key) - search_history(key) + private def vi_search_prev(key) + incremental_search_history(key) end - alias_method :reverse_search_history, :ed_search_prev_history + alias_method :reverse_search_history, :vi_search_prev - private def ed_search_next_history(key) - search_history(key) + private def vi_search_next(key) + incremental_search_history(key) end - alias_method :forward_search_history, :ed_search_next_history + alias_method :forward_search_history, :vi_search_next + + private def ed_search_prev_history(key, arg: 1) + history = nil + h_pointer = nil + line_no = nil + substr = @line.slice(0, @byte_pointer) + if @history_pointer.nil? + return if not @line.empty? and substr.empty? + history = Reline::HISTORY + elsif @history_pointer.zero? + history = nil + h_pointer = nil + else + history = Reline::HISTORY.slice(0, @history_pointer) + end + return if history.nil? + if @is_multiline + h_pointer = history.rindex { |h| + h.split("\n").each_with_index { |l, i| + if l.start_with?(substr) + line_no = i + break + end + } + not line_no.nil? + } + else + h_pointer = history.rindex { |l| + l.start_with?(substr) + } + end + return if h_pointer.nil? + @history_pointer = h_pointer + if @is_multiline + @buffer_of_lines = Reline::HISTORY[@history_pointer].split("\n") + @buffer_of_lines = [String.new(encoding: @encoding)] if @buffer_of_lines.empty? + @line_index = line_no + @line = @buffer_of_lines.last + @rerender_all = true + else + @line = Reline::HISTORY[@history_pointer] + end + @cursor_max = calculate_width(@line) + arg -= 1 + ed_search_prev_history(key, arg: arg) if arg > 0 + end + alias_method :history_search_backward, :ed_search_prev_history + + private def ed_search_next_history(key, arg: 1) + substr = @line.slice(0, @byte_pointer) + if @history_pointer.nil? + return + elsif @history_pointer == (Reline::HISTORY.size - 1) and not substr.empty? + return + end + history = Reline::HISTORY.slice((@history_pointer + 1)..-1) + h_pointer = nil + line_no = nil + if @is_multiline + h_pointer = history.index { |h| + h.split("\n").each_with_index { |l, i| + if l.start_with?(substr) + line_no = i + break + end + } + not line_no.nil? + } + else + h_pointer = history.index { |l| + l.start_with?(substr) + } + end + h_pointer += @history_pointer + 1 if h_pointer and @history_pointer + return if h_pointer.nil? and not substr.empty? + @history_pointer = h_pointer + if @is_multiline + if @history_pointer.nil? and substr.empty? + @buffer_of_lines = [] + @line_index = 0 + else + @buffer_of_lines = Reline::HISTORY[@history_pointer].split("\n") + @line_index = line_no + end + @buffer_of_lines = [String.new(encoding: @encoding)] if @buffer_of_lines.empty? + @line = @buffer_of_lines.last + @rerender_all = true + else + if @history_pointer.nil? and substr.empty? + @line = '' + else + @line = Reline::HISTORY[@history_pointer] + end + end + @cursor_max = calculate_width(@line) + arg -= 1 + ed_search_next_history(key, arg: arg) if arg > 0 + end + alias_method :history_search_forward, :ed_search_next_history private def ed_prev_history(key, arg: 1) if @is_multiline and @line_index > 0 diff --git a/lib/reline/version.rb b/lib/reline/version.rb index 1bf544d74b82c3..a243bf31a0056c 100644 --- a/lib/reline/version.rb +++ b/lib/reline/version.rb @@ -1,3 +1,3 @@ module Reline - VERSION = '0.1.3' + VERSION = '0.1.4' end diff --git a/lib/rss.rb b/lib/rss.rb deleted file mode 100644 index 1438d97bd33807..00000000000000 --- a/lib/rss.rb +++ /dev/null @@ -1,94 +0,0 @@ -# frozen_string_literal: false -## -# = RSS reading and writing -# -# Really Simple Syndication (RSS) is a family of formats that describe 'feeds,' -# specially constructed XML documents that allow an interested person to -# subscribe and receive updates from a particular web service. This portion of -# the standard library provides tooling to read and create these feeds. -# -# The standard library supports RSS 0.91, 1.0, 2.0, and Atom, a related format. -# Here are some links to the standards documents for these formats: -# -# * RSS -# * 0.9.1[http://www.rssboard.org/rss-0-9-1-netscape] -# * 1.0[http://web.resource.org/rss/1.0/] -# * 2.0[http://www.rssboard.org/rss-specification] -# * Atom[http://tools.ietf.org/html/rfc4287] -# -# == Consuming RSS -# -# If you'd like to read someone's RSS feed with your Ruby code, you've come to -# the right place. It's really easy to do this, but we'll need the help of -# open-uri: -# -# require 'rss' -# require 'open-uri' -# -# url = 'http://www.ruby-lang.org/en/feeds/news.rss' -# open(url) do |rss| -# feed = RSS::Parser.parse(rss) -# puts "Title: #{feed.channel.title}" -# feed.items.each do |item| -# puts "Item: #{item.title}" -# end -# end -# -# As you can see, the workhorse is RSS::Parser#parse, which takes the source of -# the feed and a parameter that performs validation on the feed. We get back an -# object that has all of the data from our feed, accessible through methods. -# This example shows getting the title out of the channel element, and looping -# through the list of items. -# -# == Producing RSS -# -# Producing our own RSS feeds is easy as well. Let's make a very basic feed: -# -# require "rss" -# -# rss = RSS::Maker.make("atom") do |maker| -# maker.channel.author = "matz" -# maker.channel.updated = Time.now.to_s -# maker.channel.about = "http://www.ruby-lang.org/en/feeds/news.rss" -# maker.channel.title = "Example Feed" -# -# maker.items.new_item do |item| -# item.link = "http://www.ruby-lang.org/en/news/2010/12/25/ruby-1-9-2-p136-is-released/" -# item.title = "Ruby 1.9.2-p136 is released" -# item.updated = Time.now.to_s -# end -# end -# -# puts rss -# -# As you can see, this is a very Builder-like DSL. This code will spit out an -# Atom feed with one item. If we needed a second item, we'd make another block -# with maker.items.new_item and build a second one. -# -# == Copyright -# -# Copyright (c) 2003-2007 Kouhei Sutou -# -# You can redistribute it and/or modify it under the same terms as Ruby. -# -# There is an additional tutorial by the author of RSS at: -# http://www.cozmixng.org/~rwiki/?cmd=view;name=RSS+Parser%3A%3ATutorial.en - -module RSS -end - -require "rss/version" - -require 'rss/1.0' -require 'rss/2.0' -require 'rss/atom' -require 'rss/content' -require 'rss/dublincore' -require 'rss/image' -require 'rss/itunes' -require 'rss/slash' -require 'rss/syndication' -require 'rss/taxonomy' -require 'rss/trackback' - -require "rss/maker" diff --git a/lib/rubygems.rb b/lib/rubygems.rb index 73321ec47bfbe2..5026fc41e6933c 100644 --- a/lib/rubygems.rb +++ b/lib/rubygems.rb @@ -337,13 +337,6 @@ def self.clear_paths Gem::Security.reset if defined?(Gem::Security) end - ## - # The path to standard location of the user's .gemrc file. - - def self.config_file - @config_file ||= File.join Gem.user_home, '.gemrc' - end - ## # The standard configuration object for gems. @@ -557,33 +550,6 @@ def self.find_latest_files(glob, check_load_path=true) return files end - ## - # Finds the user's home directory. - #-- - # Some comments from the ruby-talk list regarding finding the home - # directory: - # - # I have HOME, USERPROFILE and HOMEDRIVE + HOMEPATH. Ruby seems - # to be depending on HOME in those code samples. I propose that - # it should fallback to USERPROFILE and HOMEDRIVE + HOMEPATH (at - # least on Win32). - #++ - #-- - # - #++ - - def self.find_home - Dir.home.dup - rescue - if Gem.win_platform? - File.expand_path File.join(ENV['HOMEDRIVE'] || ENV['SystemDrive'], '/') - else - File.expand_path "/" - end - end - - private_class_method :find_home - ## # Top level install helper method. Allows you to install gems interactively: # @@ -1056,13 +1022,6 @@ def self.use_paths(home, *paths) self.paths = hash end - ## - # The home directory for the user. - - def self.user_home - @user_home ||= find_home.tap(&Gem::UNTAINT) - end - ## # Is this a windows platform? diff --git a/lib/rubygems/commands/contents_command.rb b/lib/rubygems/commands/contents_command.rb index 989ca5855c95c1..2da8c490316394 100644 --- a/lib/rubygems/commands/contents_command.rb +++ b/lib/rubygems/commands/contents_command.rb @@ -1,5 +1,4 @@ # frozen_string_literal: true -require 'English' require 'rubygems/command' require 'rubygems/version_option' @@ -106,7 +105,8 @@ def files_in_default_gem(spec) spec.files.map do |file| case file when /\A#{spec.bindir}\// - [RbConfig::CONFIG['bindir'], $POSTMATCH] + # $' is POSTMATCH + [RbConfig::CONFIG['bindir'], $'] when /\.so\z/ [RbConfig::CONFIG['archdir'], file] else diff --git a/lib/rubygems/commands/open_command.rb b/lib/rubygems/commands/open_command.rb index 8eaeb64ba953bc..e538e58d469f10 100644 --- a/lib/rubygems/commands/open_command.rb +++ b/lib/rubygems/commands/open_command.rb @@ -1,5 +1,4 @@ # frozen_string_literal: true -require 'English' require 'rubygems/command' require 'rubygems/version_option' require 'rubygems/util' diff --git a/lib/rubygems/config_file.rb b/lib/rubygems/config_file.rb index 54d8a9c152a439..393f947d776ce0 100644 --- a/lib/rubygems/config_file.rb +++ b/lib/rubygems/config_file.rb @@ -261,7 +261,12 @@ def check_credentials_permissions # Location of RubyGems.org credentials def credentials_path - File.join Gem.user_home, '.gem', 'credentials' + credentials = File.join Gem.user_home, '.gem', 'credentials' + if File.exist? credentials + credentials + else + File.join Gem.data_home, "gem", "credentials" + end end def load_api_keys @@ -444,6 +449,10 @@ def to_yaml # :nodoc: # Writes out this config file, replacing its source. def write + unless File.exist?(File.dirname(config_file_name)) + FileUtils.mkdir_p File.dirname(config_file_name) + end + File.open config_file_name, 'w' do |io| io.write to_yaml end diff --git a/lib/rubygems/defaults.rb b/lib/rubygems/defaults.rb index 0e83f1b006de09..2d0b077fdca976 100644 --- a/lib/rubygems/defaults.rb +++ b/lib/rubygems/defaults.rb @@ -20,7 +20,13 @@ def self.default_sources # specified in the environment def self.default_spec_cache_dir - File.join Gem.user_home, '.gem', 'specs' + default_spec_cache_dir = File.join Gem.user_home, '.gem', 'specs' + + unless File.exist?(default_spec_cache_dir) + default_spec_cache_dir = File.join Gem.data_home, 'gem', 'specs' + end + + default_spec_cache_dir end ## @@ -70,15 +76,91 @@ def self.default_specifications_dir File.join(Gem.default_dir, "specifications", "default") end + ## + # Finds the user's home directory. + #-- + # Some comments from the ruby-talk list regarding finding the home + # directory: + # + # I have HOME, USERPROFILE and HOMEDRIVE + HOMEPATH. Ruby seems + # to be depending on HOME in those code samples. I propose that + # it should fallback to USERPROFILE and HOMEDRIVE + HOMEPATH (at + # least on Win32). + #++ + #-- + # + #++ + + def self.find_home + Dir.home.dup + rescue + if Gem.win_platform? + File.expand_path File.join(ENV['HOMEDRIVE'] || ENV['SystemDrive'], '/') + else + File.expand_path "/" + end + end + + private_class_method :find_home + + ## + # The home directory for the user. + + def self.user_home + @user_home ||= find_home.tap(&Gem::UNTAINT) + end + ## # Path for gems in the user's home directory def self.user_dir - parts = [Gem.user_home, '.gem', ruby_engine] + gem_dir = File.join(Gem.user_home, ".gem") + gem_dir = File.join(Gem.data_home, "gem") unless File.exist?(gem_dir) + parts = [gem_dir, ruby_engine] parts << RbConfig::CONFIG['ruby_version'] unless RbConfig::CONFIG['ruby_version'].empty? File.join parts end + ## + # The path to standard location of the user's configuration directory. + + def self.config_home + @config_home ||= (ENV["XDG_CONFIG_HOME"] || File.join(Gem.user_home, '.config')) + end + + ## + # Finds the user's config file + + def self.find_config_file + gemrc = File.join Gem.user_home, '.gemrc' + if File.exist? gemrc + gemrc + else + File.join Gem.config_home, "gem", "gemrc" + end + end + + ## + # The path to standard location of the user's .gemrc file. + + def self.config_file + @config_file ||= find_config_file.tap(&Gem::UNTAINT) + end + + ## + # The path to standard location of the user's cache directory. + + def self.cache_home + @cache_home ||= (ENV["XDG_CACHE_HOME"] || File.join(Gem.user_home, '.cache')) + end + + ## + # The path to standard location of the user's data directory. + + def self.data_home + @data_home ||= (ENV["XDG_DATA_HOME"] || File.join(Gem.user_home, '.local', 'share')) + end + ## # How String Gem paths should be split. Overridable for esoteric platforms. @@ -130,14 +212,26 @@ def self.ruby_engine # The default signing key path def self.default_key_path - File.join Gem.user_home, ".gem", "gem-private_key.pem" + default_key_path = File.join Gem.user_home, ".gem", "gem-private_key.pem" + + unless File.exist?(default_key_path) + default_key_path = File.join Gem.data_home, "gem", "gem-private_key.pem" + end + + default_key_path end ## # The default signing certificate chain path def self.default_cert_path - File.join Gem.user_home, ".gem", "gem-public_cert.pem" + default_cert_path = File.join Gem.user_home, ".gem", "gem-public_cert.pem" + + unless File.exist?(default_cert_path) + default_cert_path = File.join Gem.data_home, "gem", "gem-public_cert.pem" + end + + default_cert_path end ## diff --git a/lib/rubygems/gemcutter_utilities.rb b/lib/rubygems/gemcutter_utilities.rb index 2950d94dc12077..bba92806918dc0 100644 --- a/lib/rubygems/gemcutter_utilities.rb +++ b/lib/rubygems/gemcutter_utilities.rb @@ -19,7 +19,7 @@ module Gem::GemcutterUtilities def add_key_option add_option('-k', '--key KEYNAME', Symbol, 'Use the given API key', - 'from ~/.gem/credentials') do |value,options| + "from #{Gem.configuration.credentials_path}") do |value,options| options[:key] = value end end diff --git a/lib/rubygems/test_case.rb b/lib/rubygems/test_case.rb index e56150caf9f240..960fe9efe059ff 100644 --- a/lib/rubygems/test_case.rb +++ b/lib/rubygems/test_case.rb @@ -363,7 +363,16 @@ def setup Dir.chdir @tempdir ENV['HOME'] = @userhome + FileUtils.mkdir_p File.join(@userhome, ".gem") + File.write File.join(@userhome, ".gemrc"), "--- {}" + temp_cred = File.join(@userhome, '.gem', 'credentials') + FileUtils.mkdir_p File.dirname(temp_cred) + File.write temp_cred, ':rubygems_api_key: 701229f217cdf23b1344c7b4b54ca97' + File.chmod 0600, temp_cred + Gem.instance_variable_set :@user_home, nil + Gem.instance_variable_set :@cache_home, nil + Gem.instance_variable_set :@data_home, nil Gem.instance_variable_set :@gemdeps, nil Gem.instance_variable_set :@env_requirements_by_name, nil Gem.send :remove_instance_variable, :@ruby_version if diff --git a/lib/uri/ldap.rb b/lib/uri/ldap.rb index a2043ccdf593f6..14e6163292dc50 100644 --- a/lib/uri/ldap.rb +++ b/lib/uri/ldap.rb @@ -118,6 +118,7 @@ def initialize(*arg) # Private method to cleanup +dn+ from using the +path+ component attribute. def parse_dn + raise InvalidURIError, 'bad LDAP URL' unless @path @dn = @path[1..-1] end private :parse_dn diff --git a/libexec/racc b/libexec/racc index 5656b25e421c0b..70e1032bfc5abc 100755 --- a/libexec/racc +++ b/libexec/racc @@ -88,7 +88,7 @@ def main debug_flags = Racc::DebugFlags.parse_option_string(flags) } #parser.on('--no-extensions', 'Run Racc without any Ruby extension.') { - # Racc.const_set :Racc_No_Extentions, true + # Racc.const_set :Racc_No_Extensions, true #} parser.on('--version', 'Prints version and quit.') { puts "racc version #{Racc::Version}" diff --git a/load.c b/load.c index 0cb0dd3cfa8dd7..f917a736f2aec2 100644 --- a/load.c +++ b/load.c @@ -1087,23 +1087,6 @@ ruby_require_internal(const char *fname, unsigned int len) return result == TAG_RETURN ? 1 : result ? -1 : 0; } -VALUE -rb_require_safe(VALUE fname, int safe) -{ - rb_warn("rb_require_safe will be removed in Ruby 3.0"); - rb_execution_context_t *ec = GET_EC(); - int result = require_internal(ec, fname, 1); - - if (result > TAG_RETURN) { - EC_JUMP_TAG(ec, result); - } - if (result < 0) { - load_failed(fname); - } - - return result ? Qtrue : Qfalse; -} - VALUE rb_require_string(VALUE fname) { diff --git a/misc/lldb_cruby.py b/misc/lldb_cruby.py index a582b7dde039c7..88765813e469f4 100755 --- a/misc/lldb_cruby.py +++ b/misc/lldb_cruby.py @@ -132,7 +132,10 @@ def lldb_inspect(debugger, target, result, val): result.write('T_STRING: %s' % flaginfo) tRString = target.FindFirstType("struct RString").GetPointerType() ptr, len = string2cstr(val.Cast(tRString)) - append_command_output(debugger, "print *(const char (*)[%d])%0#x" % (len, ptr), result) + if len == 0: + result.write("(empty)\n") + else: + append_command_output(debugger, "print *(const char (*)[%d])%0#x" % (len, ptr), result) elif flType == RUBY_T_SYMBOL: result.write('T_SYMBOL: %s' % flaginfo) tRSymbol = target.FindFirstType("struct RSymbol").GetPointerType() diff --git a/missing/explicit_bzero.c b/missing/explicit_bzero.c index 1804cdd42e69c4..1220e5f9ad7c23 100644 --- a/missing/explicit_bzero.c +++ b/missing/explicit_bzero.c @@ -17,9 +17,9 @@ /* OS support note: * BSDs have explicit_bzero(). - * OS-X has memset_s(). + * macOS has memset_s(). * Windows has SecureZeroMemory() since XP. - * Linux has none. *Sigh* + * Linux has explicit_bzero() since glibc 2.25, musl libc 1.1.20. */ /* diff --git a/mjit.c b/mjit.c index c394cd5ddb329f..2c2af0a2a678f5 100644 --- a/mjit.c +++ b/mjit.c @@ -191,7 +191,7 @@ free_list(struct rb_mjit_unit_list *list, bool close_handle_p) if (unit->handle && dlclose(unit->handle)) { mjit_warning("failed to close handle for u%d: %s", unit->id, dlerror()); } - clean_object_files(unit); + clean_temp_files(unit); free(unit); } else { @@ -362,11 +362,7 @@ unload_units(void) free_unit(worst); } - if (units_num == active_units.length && mjit_opts.wait) { - mjit_opts.max_cache_size++; // avoid infinite loop on `rb_mjit_wait_call`. Note that --jit-wait is just for testing. - verbose(1, "No units can be unloaded -- incremented max-cache-size to %d for --jit-wait", mjit_opts.max_cache_size); - } - else { + if (units_num > active_units.length) { verbose(1, "Too many JIT code -- %d units unloaded", units_num - active_units.length); } } @@ -389,8 +385,16 @@ mjit_add_iseq_to_process(const rb_iseq_t *iseq, const struct rb_mjit_compile_inf CRITICAL_SECTION_START(3, "in add_iseq_to_process"); add_to_list(iseq->body->jit_unit, &unit_queue); if (active_units.length >= mjit_opts.max_cache_size) { - RB_DEBUG_COUNTER_INC(mjit_unload_units); - unload_units(); + if (in_compact) { + verbose(1, "Too many JIT code, but skipped unloading units for JIT compaction"); + } else { + RB_DEBUG_COUNTER_INC(mjit_unload_units); + unload_units(); + } + if (active_units.length == mjit_opts.max_cache_size && mjit_opts.wait) { // Sometimes all methods may be in use + mjit_opts.max_cache_size++; // avoid infinite loop on `rb_mjit_wait_call`. Note that --jit-wait is just for testing. + verbose(1, "No units can be unloaded -- incremented max-cache-size to %d for --jit-wait", mjit_opts.max_cache_size); + } } verbose(3, "Sending wakeup signal to workers in mjit_add_iseq_to_process"); rb_native_cond_broadcast(&mjit_worker_wakeup); @@ -885,7 +889,7 @@ skip_cleaning_object_files(struct rb_mjit_unit_list *list) // No mutex for list, assuming MJIT worker does not exist yet since it's immediately after fork. list_for_each_safe(&list->head, unit, next, unode) { #ifndef _MSC_VER // Actually mswin does not reach here since it doesn't have fork - if (unit->o_file) unit->o_file_inherited_p = true; + if (unit->c_file) unit->c_file_inherited_p = true; #endif #if defined(_WIN32) // mswin doesn't reach here either. This is for MinGW. diff --git a/mjit.h b/mjit.h index 94e0b7bd8509df..5fe7b939bb1161 100644 --- a/mjit.h +++ b/mjit.h @@ -83,7 +83,7 @@ extern struct rb_mjit_compile_info* rb_mjit_iseq_compile_info(const struct rb_is extern void rb_mjit_recompile_iseq(const rb_iseq_t *iseq); RUBY_SYMBOL_EXPORT_END -extern bool mjit_compile(FILE *f, const rb_iseq_t *iseq, const char *funcname); +extern bool mjit_compile(FILE *f, const rb_iseq_t *iseq, const char *funcname, int id); extern void mjit_init(const struct mjit_options *opts); extern void mjit_gc_start_hook(void); extern void mjit_gc_exit_hook(void); diff --git a/mjit_compile.c b/mjit_compile.c index 4d0a6252fc8fff..b64cbb42b7c552 100644 --- a/mjit_compile.c +++ b/mjit_compile.c @@ -55,6 +55,7 @@ struct compile_status { int cc_entries_index; // A pointer to root (i.e. not inlined) iseq being compiled. const struct rb_iseq_constant_body *compiled_iseq; + int compiled_id; // Just a copy of compiled_iseq->jit_unit->id // Mutated optimization levels struct rb_mjit_compile_info *compile_info; // If `inlined_iseqs[pos]` is not NULL, `mjit_compile_body` tries to inline ISeq there. @@ -232,8 +233,8 @@ compile_inlined_cancel_handler(FILE *f, const struct rb_iseq_constant_body *body fprintf(f, " rb_mjit_recompile_iseq(original_iseq);\n"); // Swap pc/sp set on cancel with original pc/sp. - fprintf(f, " const VALUE current_pc = reg_cfp->pc;\n"); - fprintf(f, " const VALUE current_sp = reg_cfp->sp;\n"); + fprintf(f, " const VALUE *current_pc = reg_cfp->pc;\n"); + fprintf(f, " VALUE *current_sp = reg_cfp->sp;\n"); fprintf(f, " reg_cfp->pc = orig_pc;\n"); fprintf(f, " reg_cfp->sp = orig_sp;\n\n"); @@ -255,7 +256,7 @@ compile_inlined_cancel_handler(FILE *f, const struct rb_iseq_constant_body *body } // We're not just returning Qundef here so that caller's normal cancel handler can // push back `stack` to `cfp->sp`. - fprintf(f, " return vm_exec(ec, ec->cfp);\n"); + fprintf(f, " return vm_exec(ec, FALSE);\n"); } // Print the block to cancel JIT execution. @@ -395,6 +396,7 @@ inlinable_iseq_p(const struct rb_iseq_constant_body *body) alloca(sizeof(union iseq_inline_storage_entry) * body->is_size) : NULL, \ .cc_entries_index = (body->ci_size > 0) ? \ mjit_capture_cc_entries(status.compiled_iseq, body) : -1, \ + .compiled_id = status.compiled_id, \ .compiled_iseq = status.compiled_iseq, \ .compile_info = compile_root_p ? \ rb_mjit_iseq_compile_info(body) : alloca(sizeof(struct rb_mjit_compile_info)) \ @@ -439,7 +441,7 @@ precompile_inlinable_iseqs(FILE *f, const rb_iseq_t *iseq, struct compile_status RSTRING_PTR(child_iseq->body->location.label), RSTRING_PTR(rb_iseq_path(child_iseq)), FIX2INT(child_iseq->body->location.first_lineno)); - struct compile_status child_status = { .compiled_iseq = status->compiled_iseq }; + struct compile_status child_status = { .compiled_iseq = status->compiled_iseq, .compiled_id = status->compiled_id }; INIT_COMPILE_STATUS(child_status, child_iseq->body, false); child_status.inline_context = (struct inlined_call_context){ .orig_argc = vm_ci_argc(ci), @@ -452,12 +454,12 @@ precompile_inlinable_iseqs(FILE *f, const rb_iseq_t *iseq, struct compile_status return false; } - fprintf(f, "ALWAYS_INLINE(static VALUE _mjit_inlined_%d(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp, const VALUE orig_self, const rb_iseq_t *original_iseq));\n", pos); - fprintf(f, "static inline VALUE\n_mjit_inlined_%d(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp, const VALUE orig_self, const rb_iseq_t *original_iseq)\n{\n", pos); + fprintf(f, "ALWAYS_INLINE(static VALUE _mjit%d_inlined_%d(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp, const VALUE orig_self, const rb_iseq_t *original_iseq));\n", status->compiled_id, pos); + fprintf(f, "static inline VALUE\n_mjit%d_inlined_%d(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp, const VALUE orig_self, const rb_iseq_t *original_iseq)\n{\n", status->compiled_id, pos); fprintf(f, " const VALUE *orig_pc = reg_cfp->pc;\n"); - fprintf(f, " const VALUE *orig_sp = reg_cfp->sp;\n"); + fprintf(f, " VALUE *orig_sp = reg_cfp->sp;\n"); bool success = mjit_compile_body(f, child_iseq, &child_status); - fprintf(f, "\n} /* end of _mjit_inlined_%d */\n\n", pos); + fprintf(f, "\n} /* end of _mjit%d_inlined_%d */\n\n", status->compiled_id, pos); if (!success) return false; @@ -470,7 +472,7 @@ precompile_inlinable_iseqs(FILE *f, const rb_iseq_t *iseq, struct compile_status // Compile ISeq to C code in `f`. It returns true if it succeeds to compile. bool -mjit_compile(FILE *f, const rb_iseq_t *iseq, const char *funcname) +mjit_compile(FILE *f, const rb_iseq_t *iseq, const char *funcname, int id) { // For performance, we verify stack size only on compilation time (mjit_compile.inc.erb) without --jit-debug if (!mjit_opts.debug) { @@ -478,7 +480,7 @@ mjit_compile(FILE *f, const rb_iseq_t *iseq, const char *funcname) fprintf(f, "#define OPT_CHECKED_RUN 0\n\n"); } - struct compile_status status = { .compiled_iseq = iseq->body }; + struct compile_status status = { .compiled_iseq = iseq->body, .compiled_id = id }; INIT_COMPILE_STATUS(status, iseq->body, true); if ((iseq->body->ci_size > 0 && status.cc_entries_index == -1) || (status.is_entries != NULL && !mjit_copy_cache_from_main_thread(iseq, status.is_entries))) { diff --git a/mjit_worker.c b/mjit_worker.c index a2f62448e1e7a1..cebb9ce4f6e7b4 100644 --- a/mjit_worker.c +++ b/mjit_worker.c @@ -146,11 +146,11 @@ struct rb_mjit_unit { rb_iseq_t *iseq; #ifndef _MSC_VER // This value is always set for `compact_all_jit_code`. Also used for lazy deletion. - char *o_file; + char *c_file; // true if it's inherited from parent Ruby process and lazy deletion should be skipped. - // `o_file = NULL` can't be used to skip lazy deletion because `o_file` could be used + // `c_file = NULL` can't be used to skip lazy deletion because `c_file` could be used // by child for `compact_all_jit_code`. - bool o_file_inherited_p; + bool c_file_inherited_p; #endif #if defined(_WIN32) // DLL cannot be removed while loaded on Windows. If this is set, it'll be lazily deleted. @@ -221,9 +221,11 @@ static rb_nativethread_cond_t mjit_worker_wakeup; // A thread conditional to wake up workers if at the end of GC. static rb_nativethread_cond_t mjit_gc_wakeup; // True when GC is working. -static bool in_gc; +static bool in_gc = false; // True when JIT is working. -static bool in_jit; +static bool in_jit = false; +// True when JIT compaction is running. +static bool in_compact = false; // Set to true to stop worker. static bool stop_worker_p; // Set to true if worker is stopped. @@ -386,20 +388,20 @@ remove_file(const char *filename) } } -// Lazily delete .o and/or .so files. +// Lazily delete .c and/or .so files. static void -clean_object_files(struct rb_mjit_unit *unit) +clean_temp_files(struct rb_mjit_unit *unit) { #ifndef _MSC_VER - if (unit->o_file) { - char *o_file = unit->o_file; + if (unit->c_file) { + char *c_file = unit->c_file; - unit->o_file = NULL; - // For compaction, unit->o_file is always set when compilation succeeds. + unit->c_file = NULL; + // For compaction, unit->c_file is always set when compilation succeeds. // So save_temps needs to be checked here. - if (!mjit_opts.save_temps && !unit->o_file_inherited_p) - remove_file(o_file); - free(o_file); + if (!mjit_opts.save_temps && !unit->c_file_inherited_p) + remove_file(c_file); + free(c_file); } #endif @@ -437,7 +439,7 @@ free_unit(struct rb_mjit_unit *unit) if (unit->handle && dlclose(unit->handle)) { // handle is NULL if it's in queue mjit_warning("failed to close handle for u%d: %s", unit->id, dlerror()); } - clean_object_files(unit); + clean_temp_files(unit); free(unit); } @@ -681,7 +683,7 @@ remove_so_file(const char *so_file, struct rb_mjit_unit *unit) { #if defined(_WIN32) // Windows can't remove files while it's used. - unit->so_file = strdup(so_file); // lazily delete on `clean_object_files()` + unit->so_file = strdup(so_file); // lazily delete on `clean_temp_files()` if (unit->so_file == NULL) mjit_warning("failed to allocate memory to lazily remove '%s': %s", so_file, strerror(errno)); #else @@ -723,6 +725,12 @@ sprint_funcname(char *funcname, const struct rb_mjit_unit *unit) } } +static const int c_file_access_mode = +#ifdef O_BINARY + O_BINARY| +#endif + O_WRONLY|O_EXCL|O_CREAT; + #define append_str2(p, str, len) ((char *)memcpy((p), str, (len))+(len)) #define append_str(p, str) append_str2(p, str, sizeof(str)-1) #define append_lit(p, str) append_str2(p, str, rb_strlen_lit(str)) @@ -842,67 +850,86 @@ make_pch(void) CRITICAL_SECTION_FINISH(3, "in make_pch"); } -// Compile .c file to .o file. It returns true if it succeeds. (non-mswin) +// Compile .c file to .so file. It returns true if it succeeds. (non-mswin) +// Not compiling .c to .so directly because it fails on MinGW, and this helps +// to generate no .dSYM on macOS. static bool -compile_c_to_o(const char *c_file, const char *o_file) +compile_c_to_so(const char *c_file, const char *so_file) { - const char *files[] = { + char* o_file = alloca(strlen(c_file) + 1); + strcpy(o_file, c_file); + o_file[strlen(c_file) - 1] = 'o'; + + const char *o_args[] = { "-o", o_file, c_file, # ifdef __clang__ "-include-pch", pch_file, # endif "-c", NULL }; - - char **args = form_args(5, cc_common_args, CC_CODEFLAG_ARGS, cc_added_args, files, CC_LINKER_ARGS); - if (args == NULL) - return false; - + char **args = form_args(5, cc_common_args, CC_CODEFLAG_ARGS, cc_added_args, o_args, CC_LINKER_ARGS); + if (args == NULL) return false; int exit_code = exec_process(cc_path, args); free(args); + if (exit_code != 0) { + verbose(2, "compile_c_to_so: failed to compile .c to .o: %d", exit_code); + return false; + } - if (exit_code != 0) - verbose(2, "compile_c_to_o: compile error: %d", exit_code); - return exit_code == 0; -} - -// Link .o files to .so file. It returns true if it succeeds. (non-mswin) -static bool -link_o_to_so(const char **o_files, const char *so_file) -{ - const char *options[] = { + const char *so_args[] = { "-o", so_file, # ifdef _WIN32 libruby_pathflag, # endif - NULL + o_file, NULL }; + args = form_args(6, CC_LDSHARED_ARGS, CC_CODEFLAG_ARGS, so_args, CC_LIBS, CC_DLDFLAGS_ARGS, CC_LINKER_ARGS); + if (args == NULL) return false; + exit_code = exec_process(cc_path, args); + free(args); + if (!mjit_opts.save_temps) remove_file(o_file); + if (exit_code != 0) { + verbose(2, "compile_c_to_so: failed to link .o to .so: %d", exit_code); + } + return exit_code == 0; +} - char **args = form_args(7, CC_LDSHARED_ARGS, CC_CODEFLAG_ARGS, - options, o_files, CC_LIBS, CC_DLDFLAGS_ARGS, CC_LINKER_ARGS); - if (args == NULL) +static void compile_prelude(FILE *f); + +static bool +compile_compact_jit_code(char* c_file) +{ + FILE *f; + int fd = rb_cloexec_open(c_file, c_file_access_mode, 0600); + if (fd < 0 || (f = fdopen(fd, "w")) == NULL) { + int e = errno; + if (fd >= 0) (void)close(fd); + verbose(1, "Failed to fopen '%s', giving up JIT for it (%s)", c_file, strerror(e)); return false; + } - int exit_code = exec_process(cc_path, args); - free(args); + compile_prelude(f); - if (exit_code != 0) - verbose(2, "link_o_to_so: link error: %d", exit_code); - return exit_code == 0; + struct rb_mjit_unit *cur = 0; + list_for_each(&active_units.head, cur, unode) { + fprintf(f, "#include \"%s\"\n", cur->c_file); + } + + fclose(f); + return true; } -// Link all cached .o files and build a .so file. Reload all JIT func from it. This -// allows to avoid JIT code fragmentation and improve performance to call JIT-ed code. +// Compile all cached .c files and build a single .so file. Reload all JIT func from it. +// This improves the code locality for better performance in terms of iTLB and iCache. static void compact_all_jit_code(void) { # ifndef _WIN32 // This requires header transformation but we don't transform header on Windows for now struct rb_mjit_unit *unit, *cur = 0; double start_time, end_time; + static const char c_ext[] = ".c"; static const char so_ext[] = DLEXT; - char so_file[MAXPATHLEN]; - const char **o_files; - int i = 0; + char c_file[MAXPATHLEN], so_file[MAXPATHLEN]; // Abnormal use case of rb_mjit_unit that doesn't have ISeq unit = calloc(1, sizeof(struct rb_mjit_unit)); // To prevent GC, don't use ZALLOC @@ -910,24 +937,23 @@ compact_all_jit_code(void) unit->id = current_unit_num++; sprint_uniq_filename(so_file, (int)sizeof(so_file), unit->id, MJIT_TMP_PREFIX, so_ext); - // NULL-ending for form_args - o_files = alloca(sizeof(char *) * (active_units.length + 1)); - o_files[active_units.length] = NULL; - CRITICAL_SECTION_START(3, "in compact_all_jit_code to keep .o files"); - list_for_each(&active_units.head, cur, unode) { - o_files[i] = cur->o_file; - i++; - } + sprint_uniq_filename(c_file, (int)sizeof(c_file), unit->id, MJIT_TMP_PREFIX, c_ext); + CRITICAL_SECTION_START(3, "in compact_all_jit_code to guard .c files from unload_units"); + bool success = compile_compact_jit_code(c_file); + in_compact = true; + CRITICAL_SECTION_FINISH(3, "in compact_all_jit_code to guard .c files from unload_units"); start_time = real_ms_time(); - bool success = link_o_to_so(o_files, so_file); + if (success) { + success = compile_c_to_so(c_file, so_file); + if (!mjit_opts.save_temps) + remove_file(c_file); + } end_time = real_ms_time(); - // TODO: Shrink this big critical section. For now, this is needed to prevent failure by missing .o files. - // This assumes that o -> so link doesn't take long time because the bottleneck, which is compiler optimization, - // is already done. But actually it takes about 500ms for 5,000 methods on my Linux machine, so it's better to - // finish this critical section before link_o_to_so by disabling unload_units. - CRITICAL_SECTION_FINISH(3, "in compact_all_jit_code to keep .o files"); + CRITICAL_SECTION_START(3, "in compact_all_jit_code to release .c files"); + in_compact = false; + CRITICAL_SECTION_FINISH(3, "in compact_all_jit_code to release .c files"); if (success) { void *handle = dlopen(so_file, RTLD_NOW); @@ -961,7 +987,7 @@ compact_all_jit_code(void) } } CRITICAL_SECTION_FINISH(3, "in compact_all_jit_code to read list"); - verbose(1, "JIT compaction (%.1fms): Compacted %d methods -> %s", end_time - start_time, active_units.length, so_file); + verbose(1, "JIT compaction (%.1fms): Compacted %d methods %s -> %s", end_time - start_time, active_units.length, c_file, so_file); } else { free(unit); @@ -1013,6 +1039,10 @@ compile_prelude(FILE *f) const char *s = pch_file; const char *e = header_name_end(s); +# ifndef _MSC_VER // Visual Studio doesn't expect macro changes around headers. Anyway we don't support compaction there... + fprintf(f, "#ifndef MJIT_PCH\n"); + fprintf(f, "#define MJIT_PCH\n"); +# endif fprintf(f, "#include \""); // print pch_file except .gch for gcc, but keep .pch for mswin for (; s < e; s++) { @@ -1023,6 +1053,9 @@ compile_prelude(FILE *f) fputc(*s, f); } fprintf(f, "\"\n"); +# ifndef _MSC_VER + fprintf(f, "#endif\n"); +# endif #endif #ifdef _WIN32 @@ -1044,11 +1077,6 @@ convert_unit_to_func(struct rb_mjit_unit *unit) int c_file_len = (int)sizeof(c_file_buff); static const char c_ext[] = ".c"; static const char so_ext[] = DLEXT; - const int access_mode = -#ifdef O_BINARY - O_BINARY| -#endif - O_WRONLY|O_EXCL|O_CREAT; #ifndef _MSC_VER static const char o_ext[] = ".o"; char *o_file; @@ -1073,7 +1101,7 @@ convert_unit_to_func(struct rb_mjit_unit *unit) sprint_funcname(funcname, unit); - fd = rb_cloexec_open(c_file, access_mode, 0600); + fd = rb_cloexec_open(c_file, c_file_access_mode, 0600); if (fd < 0 || (f = fdopen(fd, "w")) == NULL) { int e = errno; if (fd >= 0) (void)close(fd); @@ -1118,7 +1146,7 @@ convert_unit_to_func(struct rb_mjit_unit *unit) verbose(2, "start compilation: %s@%s:%ld -> %s", iseq_label, iseq_path, iseq_lineno, c_file); fprintf(f, "/* %s@%s:%ld */\n\n", iseq_label, iseq_path, iseq_lineno); - bool success = mjit_compile(f, unit->iseq, funcname); + bool success = mjit_compile(f, unit->iseq, funcname, unit->id); // release blocking mjit_gc_start_hook CRITICAL_SECTION_START(3, "after mjit_compile to wakeup client for GC"); @@ -1136,25 +1164,23 @@ convert_unit_to_func(struct rb_mjit_unit *unit) } start_time = real_ms_time(); -#ifdef _MSC_VER success = compile_c_to_so(c_file, so_file); +#ifdef _MSC_VER + if (!mjit_opts.save_temps) + remove_file(c_file); #else - // splitting .c -> .o step and .o -> .so step, to cache .o files in the future - if ((success = compile_c_to_o(c_file, o_file)) != false) { - success = link_o_to_so((const char *[]){ o_file, NULL }, so_file); - - // Always set o_file for compaction. The value is also used for lazy deletion. - unit->o_file = strdup(o_file); - if (unit->o_file == NULL) { - mjit_warning("failed to allocate memory to remember '%s' (%s), removing it...", o_file, strerror(errno)); - remove_file(o_file); + if (success) { + // Always set c_file for compaction. The value is also used for lazy deletion. + unit->c_file = strdup(c_file); + if (unit->c_file == NULL) { + mjit_warning("failed to allocate memory to remember '%s' (%s), removing it...", c_file, strerror(errno)); } } + if (!mjit_opts.save_temps && unit->c_file == NULL) + remove_file(c_file); #endif end_time = real_ms_time(); - if (!mjit_opts.save_temps) - remove_file(c_file); if (!success) { verbose(2, "Failed to generate so: %s", so_file); return (mjit_func_t)NOT_COMPILED_JIT_ISEQ_FUNC; @@ -1293,6 +1319,11 @@ mjit_copy_cache_from_main_thread(const rb_iseq_t *iseq, union iseq_inline_storag void mjit_worker(void) { + // Allow only `max_cache_size / 10` times (default: 10) of compaction. + // Note: GC of compacted code has not been implemented yet. + int max_compact_size = mjit_opts.max_cache_size / 10; + if (max_compact_size < 10) max_compact_size = 10; + #ifndef _MSC_VER if (pch_status == PCH_NOT_READY) { make_pch(); @@ -1344,9 +1375,10 @@ mjit_worker(void) CRITICAL_SECTION_FINISH(3, "in jit func replace"); #ifndef _MSC_VER - // Combine .o files to one .so and reload all jit_func to improve memory locality - if ((!mjit_opts.wait && unit_queue.length == 0 && active_units.length > 1) - || active_units.length == mjit_opts.max_cache_size) { + // Combine .o files to one .so and reload all jit_func to improve memory locality. + if (compact_units.length < max_compact_size + && ((!mjit_opts.wait && unit_queue.length == 0 && active_units.length > 1) + || active_units.length == mjit_opts.max_cache_size)) { compact_all_jit_code(); } #endif diff --git a/node.h b/node.h index 40a5dd5de8eead..504153ab14d6c6 100644 --- a/node.h +++ b/node.h @@ -165,7 +165,7 @@ typedef struct RNode { long state; struct rb_global_entry *entry; struct rb_args_info *args; - struct rb_ary_pattern_info *apinfo; + struct rb_ary_pattern_info *apinfo; VALUE value; } u3; rb_code_location_t nd_loc; diff --git a/object.c b/object.c index dfe3d14e6e662a..d3e100d11f0338 100644 --- a/object.c +++ b/object.c @@ -137,11 +137,22 @@ rb_obj_setup(VALUE obj, VALUE klass, VALUE type) * Case Equality -- For class Object, effectively the same as calling * #==, but typically overridden by descendants to provide * meaningful semantics in +case+ statements. - *-- - * Same as \c Object#===, case equality. - *++ */ +#define case_equal rb_equal + /* The default implementation of #=== is + * to call #== with the rb_equal() optimization. */ +/*! + * This function is an optimized version of calling #==. + * It checks equality between two objects by first doing a fast + * identity check using using C's == (same as BasicObject#equal?). + * If that check fails, it calls #== dynamically. + * This optimization actually affects semantics, + * because when #== returns false for the same object obj, + * rb_equal(obj, obj) would still return true. + * This happens for Float::NAN, where Float::NAN == Float::NAN + * is false, but rb_equal(Float::NAN, Float::NAN) is true. + */ VALUE rb_equal(VALUE obj1, VALUE obj2) { @@ -1726,7 +1737,7 @@ rb_obj_not_match(VALUE obj1, VALUE obj2) static VALUE rb_obj_cmp(VALUE obj1, VALUE obj2) { - if (obj1 == obj2 || rb_equal(obj1, obj2)) + if (rb_equal(obj1, obj2)) return INT2FIX(0); return Qnil; } @@ -3813,32 +3824,11 @@ rb_Float(VALUE val) return rb_convert_to_float(val, TRUE); } -/* - * call-seq: - * Float(arg, exception: true) -> float or nil - * - * Returns arg converted to a float. Numeric types are - * converted directly, and with exception to String and - * nil the rest are converted using - * arg.to_f. Converting a String with invalid - * characters will result in a ArgumentError. Converting - * nil generates a TypeError. Exceptions can be - * suppressed by passing exception: false. - * - * Float(1) #=> 1.0 - * Float("123.456") #=> 123.456 - * Float("123.0_badstring") #=> ArgumentError: invalid value for Float(): "123.0_badstring" - * Float(nil) #=> TypeError: can't convert nil into Float - * Float("123.0_badstring", exception: false) #=> nil - */ - static VALUE -rb_f_float(int argc, VALUE *argv, VALUE obj) +rb_f_float(rb_execution_context_t *ec, VALUE obj, VALUE arg, VALUE opts) { - VALUE arg = Qnil, opts = Qnil; - - rb_scan_args(argc, argv, "1:", &arg, &opts); - return rb_convert_to_float(arg, opts_exception_p(opts)); + int exception = rb_bool_expected(opts, "exception"); + return rb_convert_to_float(arg, exception); } static VALUE @@ -4619,7 +4609,7 @@ InitVM_Object(void) rb_define_private_method(rb_cModule, "method_undefined", rb_obj_dummy1, 1); rb_define_method(rb_mKernel, "nil?", rb_false, 0); - rb_define_method(rb_mKernel, "===", rb_equal, 1); + rb_define_method(rb_mKernel, "===", case_equal, 1); rb_define_method(rb_mKernel, "=~", rb_obj_match, 1); rb_define_method(rb_mKernel, "!~", rb_obj_not_match, 1); rb_define_method(rb_mKernel, "eql?", rb_obj_equal, 1); @@ -4668,7 +4658,6 @@ InitVM_Object(void) rb_define_global_function("format", f_sprintf, -1); rb_define_global_function("Integer", rb_f_integer, -1); - rb_define_global_function("Float", rb_f_float, -1); rb_define_global_function("String", rb_f_string, 1); rb_define_global_function("Array", rb_f_array, 1); @@ -4687,16 +4676,11 @@ InitVM_Object(void) rb_define_method(rb_cNilClass, "&", false_and, 1); rb_define_method(rb_cNilClass, "|", false_or, 1); rb_define_method(rb_cNilClass, "^", false_xor, 1); - rb_define_method(rb_cNilClass, "===", rb_equal, 1); + rb_define_method(rb_cNilClass, "===", case_equal, 1); rb_define_method(rb_cNilClass, "nil?", rb_true, 0); rb_undef_alloc_func(rb_cNilClass); rb_undef_method(CLASS_OF(rb_cNilClass), "new"); - /* - * An obsolete alias of +nil+ - */ - rb_define_global_const("NIL", Qnil); - rb_deprecate_constant(rb_cObject, "NIL"); rb_define_method(rb_cModule, "freeze", rb_mod_freeze, 0); rb_define_method(rb_cModule, "===", rb_mod_eqq, 1); @@ -4778,14 +4762,9 @@ InitVM_Object(void) rb_define_method(rb_cTrueClass, "&", true_and, 1); rb_define_method(rb_cTrueClass, "|", true_or, 1); rb_define_method(rb_cTrueClass, "^", true_xor, 1); - rb_define_method(rb_cTrueClass, "===", rb_equal, 1); + rb_define_method(rb_cTrueClass, "===", case_equal, 1); rb_undef_alloc_func(rb_cTrueClass); rb_undef_method(CLASS_OF(rb_cTrueClass), "new"); - /* - * An obsolete alias of +true+ - */ - rb_define_global_const("TRUE", Qtrue); - rb_deprecate_constant(rb_cObject, "TRUE"); rb_cFalseClass = rb_define_class("FalseClass", rb_cObject); rb_cFalseClass_to_s = rb_fstring_enc_lit("false", rb_usascii_encoding()); @@ -4795,14 +4774,9 @@ InitVM_Object(void) rb_define_method(rb_cFalseClass, "&", false_and, 1); rb_define_method(rb_cFalseClass, "|", false_or, 1); rb_define_method(rb_cFalseClass, "^", false_xor, 1); - rb_define_method(rb_cFalseClass, "===", rb_equal, 1); + rb_define_method(rb_cFalseClass, "===", case_equal, 1); rb_undef_alloc_func(rb_cFalseClass); rb_undef_method(CLASS_OF(rb_cFalseClass), "new"); - /* - * An obsolete alias of +false+ - */ - rb_define_global_const("FALSE", Qfalse); - rb_deprecate_constant(rb_cObject, "FALSE"); } #include "kernel.rbinc" diff --git a/parse.y b/parse.y index 482751582070ff..9f6bda35bab2f5 100644 --- a/parse.y +++ b/parse.y @@ -1014,6 +1014,7 @@ static int looking_at_eol_p(struct parser_params *p); %expect 0 %define api.pure +%define parse.error verbose %lex-param {struct parser_params *p} %parse-param {struct parser_params *p} %initial-action @@ -1104,7 +1105,7 @@ static int looking_at_eol_p(struct parser_params *p); %type string_contents xstring_contents regexp_contents string_content %type words symbols symbol_list qwords qsymbols word_list qword_list qsym_list word %type literal numeric simple_numeric ssym dsym symbol cpath def_name defn_head defs_head -%type top_compstmt top_stmts top_stmt begin_block rassign arg_rassign +%type top_compstmt top_stmts top_stmt begin_block rassign %type bodystmt compstmt stmts stmt_or_begin stmt expr arg primary command command_call method_call %type expr_value expr_value_do arg_value primary_value fcall rel_expr %type if_tail opt_else case_body case_args cases opt_rescue exc_list exc_var opt_ensure @@ -1114,7 +1115,7 @@ static int looking_at_eol_p(struct parser_params *p); %type command_rhs arg_rhs %type command_asgn mrhs mrhs_arg superclass block_call block_command %type f_block_optarg f_block_opt -%type f_arglist f_arglist_opt f_args f_arg f_arg_item f_optarg f_marg f_marg_list f_margs f_rest_marg +%type f_arglist f_paren_args f_args f_arg f_arg_item f_optarg f_marg f_marg_list f_margs f_rest_marg %type assoc_list assocs assoc undef_list backref string_dvar for_var %type block_param opt_block_param block_param_def f_opt %type f_kwarg f_kw f_block_kwarg f_block_kw @@ -1195,7 +1196,6 @@ static int looking_at_eol_p(struct parser_params *p); %nonassoc tLOWEST %nonassoc tLBRACE_ARG -%left tASSOC %nonassoc modifier_if modifier_unless modifier_while modifier_until keyword_in %left keyword_or keyword_and @@ -1537,19 +1537,6 @@ rassign : arg_value tASSOC lhs } ; -arg_rassign : arg tASSOC lhs %prec tLOWEST - { - /*%%%*/ - $$ = node_assign(p, $3, $1, &@$); - /*% %*/ - /*% ripper: assign!($3, $1) %*/ - } - | arg %prec tLOWEST - { - $$ = $1; - } - ; - command_asgn : lhs '=' command_rhs { /*%%%*/ @@ -2459,7 +2446,7 @@ arg : lhs '=' arg_rhs /*% %*/ /*% ripper: ifop!($1, $3, $6) %*/ } - | defn_head f_arglist_opt '=' arg_rassign + | defn_head f_paren_args '=' arg { restore_defun(p, $1->nd_defn); /*%%%*/ @@ -2468,7 +2455,7 @@ arg : lhs '=' arg_rhs /*% ripper: def!(get_value($1), $2, $4) %*/ local_pop(p); } - | defs_head f_arglist_opt '=' arg_rassign + | defs_head f_paren_args '=' arg { restore_defun(p, $1->nd_defn); /*%%%*/ @@ -4902,18 +4889,7 @@ superclass : '<' } ; -f_arglist_opt : f_arglist - | /* none */ - { - /*%%%*/ - $$ = new_args_tail(p, Qnone, Qnone, Qnone, &@0); - $$ = new_args(p, Qnone, Qnone, Qnone, Qnone, $$, &@0); - /*% %*/ - /*% ripper: Qnil %*/ - } - ; - -f_arglist : '(' f_args rparen +f_paren_args : '(' f_args rparen { /*%%%*/ $$ = $2; @@ -4937,6 +4913,9 @@ f_arglist : '(' f_args rparen SET_LEX_STATE(EXPR_BEG); p->command_start = TRUE; } + ; + +f_arglist : f_paren_args | { $$ = p->ctxt; p->ctxt.in_kwarg = 1; diff --git a/proc.c b/proc.c index 50ebdbde6703a6..38d4fc6bf73e6d 100644 --- a/proc.c +++ b/proc.c @@ -2271,10 +2271,22 @@ method_clone(VALUE self) */ +/* Document-method: Method#[] + * + * call-seq: + * meth[args, ...] -> obj + * + * Invokes the meth with the specified arguments, returning the + * method's return value, like #call. + * + * m = 12.method("+") + * m[3] #=> 15 + * m[20] #=> 32 + */ + /* * call-seq: * meth.call(args, ...) -> obj - * meth[args, ...] -> obj * * Invokes the meth with the specified arguments, returning the * method's return value. @@ -3530,8 +3542,8 @@ rb_method_compose_to_left(VALUE self, VALUE g) * meth >> g -> a_proc * * Returns a proc that is the composition of this method and the given g. - * The returned proc takes a variable number of arguments, calls g with them - * then calls this method with the result. + * The returned proc takes a variable number of arguments, calls this method + * with them then calls g with the result. * * def f(x) * x * x diff --git a/process.c b/process.c index f13ec82ba033ca..e5cfed8cf20ea5 100644 --- a/process.c +++ b/process.c @@ -2325,7 +2325,7 @@ check_exec_env_i(st_data_t st_key, st_data_t st_val, st_data_t arg) k = StringValueCStr(key); if (strchr(k, '=')) - rb_raise(rb_eArgError, "environment name contains a equal : %s", k); + rb_raise(rb_eArgError, "environment name contains a equal : %"PRIsVALUE, key); if (!NIL_P(val)) StringValueCStr(val); @@ -3957,10 +3957,6 @@ disable_child_handler_fork_child(struct child_handler_disabler_state *old, char return 0; } -COMPILER_WARNING_PUSH -#ifdef __GNUC__ -COMPILER_WARNING_IGNORED(-Wdeprecated-declarations) -#endif static rb_pid_t retry_fork_async_signal_safe(int *status, int *ep, int (*chfunc)(void*, char *, size_t), void *charg, @@ -3985,9 +3981,9 @@ retry_fork_async_signal_safe(int *status, int *ep, if (!has_privilege()) pid = vfork(); else - pid = fork(); + pid = rb_fork(); #else - pid = fork(); + pid = rb_fork(); #endif if (pid == 0) {/* fork succeed, child process */ int ret; @@ -4021,7 +4017,6 @@ retry_fork_async_signal_safe(int *status, int *ep, return -1; } } -COMPILER_WARNING_POP static rb_pid_t fork_check_err(int *status, int (*chfunc)(void*, char *, size_t), void *charg, @@ -4075,10 +4070,6 @@ rb_fork_async_signal_safe(int *status, return fork_check_err(status, chfunc, charg, fds, errmsg, errmsg_buflen, 0); } -COMPILER_WARNING_PUSH -#ifdef __GNUC__ -COMPILER_WARNING_IGNORED(-Wdeprecated-declarations) -#endif rb_pid_t rb_fork_ruby(int *status) { @@ -4093,7 +4084,7 @@ rb_fork_ruby(int *status) if (mjit_enabled) mjit_pause(false); // Don't leave locked mutex to child. Note: child_handler must be enabled to pause MJIT. disable_child_handler_before_fork(&old); before_fork_ruby(); - pid = fork(); + pid = rb_fork(); err = errno; after_fork_ruby(); disable_child_handler_fork_parent(&old); /* yes, bad name */ @@ -4105,7 +4096,6 @@ rb_fork_ruby(int *status) return -1; } } -COMPILER_WARNING_POP #endif @@ -5585,7 +5575,7 @@ obj2uid(VALUE id #ifndef USE_GETPWNAM_R endpwent(); #endif - rb_raise(rb_eArgError, "can't find user for %s", usrname); + rb_raise(rb_eArgError, "can't find user for %"PRIsVALUE, id); } uid = pwptr->pw_uid; #ifndef USE_GETPWNAM_R @@ -5664,7 +5654,7 @@ obj2gid(VALUE id #if !defined(USE_GETGRNAM_R) && defined(HAVE_ENDGRENT) endgrent(); #endif - rb_raise(rb_eArgError, "can't find group for %s", grpname); + rb_raise(rb_eArgError, "can't find group for %"PRIsVALUE, id); } gid = grptr->gr_gid; #if !defined(USE_GETGRNAM_R) && defined(HAVE_ENDGRENT) diff --git a/random.c b/random.c index e5676656cccb0a..dc4ad760e4f980 100644 --- a/random.c +++ b/random.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #ifdef HAVE_UNISTD_H @@ -75,12 +76,22 @@ genrand_real(struct MT *mt) return int_pair_to_real_exclusive(a, b); } +static const double dbl_reduce_scale = /* 2**(-DBL_MANT_DIG) */ + (1.0 + / (double)(DBL_MANT_DIG > 2*31 ? (1ul<<31) : 1.0) + / (double)(DBL_MANT_DIG > 1*31 ? (1ul<<31) : 1.0) + / (double)(1ul<<(DBL_MANT_DIG%31))); + static double int_pair_to_real_exclusive(uint32_t a, uint32_t b) { - a >>= 5; - b >>= 6; - return(a*67108864.0+b)*(1.0/9007199254740992.0); + static const int a_shift = DBL_MANT_DIG < 64 ? + (64-DBL_MANT_DIG)/2 : 0; + static const int b_shift = DBL_MANT_DIG < 64 ? + (65-DBL_MANT_DIG)/2 : 0; + a >>= a_shift; + b >>= b_shift; + return (a*(double)(1ul<<(32-b_shift))+b)*dbl_reduce_scale; } /* generates a random number on [0,1] with 53-bit resolution*/ @@ -148,7 +159,7 @@ static double int_pair_to_real_inclusive(uint32_t a, uint32_t b) { double r; - enum {dig = 53}; + enum {dig = DBL_MANT_DIG}; enum {dig_u = dig-32, dig_r64 = 64-dig, bmask = ~(~0u<<(dig_r64))}; #if defined HAVE_UINT128_T const uint128_t m = ((uint128_t)1 << dig) | 1; @@ -163,7 +174,7 @@ int_pair_to_real_inclusive(uint32_t a, uint32_t b) b = (b >> dig_r64) + (((a >> dig_u) + (b & bmask)) >> dig_r64); r = (double)a * (1 << dig_u) + b; #endif - return ldexp(r, -dig); + return r * dbl_reduce_scale; } VALUE rb_cRandom; diff --git a/rational.c b/rational.c index b828ec1e39798f..f94bf921c7092c 100644 --- a/rational.c +++ b/rational.c @@ -20,6 +20,7 @@ #include #endif +#undef NDEBUG #define NDEBUG #include "id.h" #include "internal.h" diff --git a/ruby.c b/ruby.c index 405891f8737f33..f2577f51f1ebf0 100644 --- a/ruby.c +++ b/ruby.c @@ -56,6 +56,7 @@ #include "internal/missing.h" #include "internal/object.h" #include "internal/parse.h" +#include "internal/process.h" #include "internal/variable.h" #include "mjit.h" #include "ruby/encoding.h" @@ -1635,7 +1636,7 @@ process_options(int argc, char **argv, ruby_cmdline_options_t *opt) #ifdef HAVE_WORKING_FORK int fds[2]; if (rb_pipe(fds) == 0) { - rb_pid_t pid = fork(); + rb_pid_t pid = rb_fork(); if (pid > 0) { /* exec PAGER with reading from child */ dup2(fds[0], 0); diff --git a/ruby_atomic.h b/ruby_atomic.h index d4d56da4249270..fa888a1db02a73 100644 --- a/ruby_atomic.h +++ b/ruby_atomic.h @@ -1,12 +1,17 @@ #ifndef RUBY_ATOMIC_H #define RUBY_ATOMIC_H +/* + * - ATOMIC_CAS, ATOMIC_EXCHANGE, ATOMIC_FETCH_*: + * return the old * value. + * - ATOMIC_ADD, ATOMIC_SUB, ATOMIC_INC, ATOMIC_DEC, ATOMIC_OR, ATOMIC_SET: + * may be void. + */ #if 0 #elif defined HAVE_GCC_ATOMIC_BUILTINS typedef unsigned int rb_atomic_t; -# define ATOMIC_SET(var, val) (void)__atomic_exchange_n(&(var), (val), __ATOMIC_SEQ_CST) -# define ATOMIC_INC(var) __atomic_fetch_add(&(var), 1, __ATOMIC_SEQ_CST) -# define ATOMIC_DEC(var) __atomic_fetch_sub(&(var), 1, __ATOMIC_SEQ_CST) +# define ATOMIC_FETCH_ADD(var, val) __atomic_fetch_add(&(var), (val), __ATOMIC_SEQ_CST) +# define ATOMIC_FETCH_SUB(var, val) __atomic_fetch_sub(&(var), (val), __ATOMIC_SEQ_CST) # define ATOMIC_OR(var, val) __atomic_fetch_or(&(var), (val), __ATOMIC_SEQ_CST) # define ATOMIC_EXCHANGE(var, val) __atomic_exchange_n(&(var), (val), __ATOMIC_SEQ_CST) # define ATOMIC_CAS(var, oldval, newval) RB_GNUC_EXTENSION_BLOCK( \ @@ -14,9 +19,6 @@ typedef unsigned int rb_atomic_t; __atomic_compare_exchange_n(&(var), &oldvaldup, (newval), 0, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST); \ oldvaldup ) -# define ATOMIC_SIZE_ADD(var, val) __atomic_fetch_add(&(var), (val), __ATOMIC_SEQ_CST) -# define ATOMIC_SIZE_SUB(var, val) __atomic_fetch_sub(&(var), (val), __ATOMIC_SEQ_CST) - # define RUBY_ATOMIC_GENERIC_MACRO 1 #elif defined HAVE_GCC_SYNC_BUILTINS @@ -25,16 +27,12 @@ typedef unsigned int rb_atomic_t; * http://gcc.gnu.org/onlinedocs/gcc/Atomic-Builtins.html */ typedef unsigned int rb_atomic_t; /* Anything OK */ -# define ATOMIC_SET(var, val) (void)__sync_lock_test_and_set(&(var), (val)) -# define ATOMIC_INC(var) __sync_fetch_and_add(&(var), 1) -# define ATOMIC_DEC(var) __sync_fetch_and_sub(&(var), 1) +# define ATOMIC_FETCH_ADD(var, val) __sync_fetch_and_add(&(var), (val)) +# define ATOMIC_FETCH_SUB(var, var) __sync_fetch_and_sub(&(var), (val)) # define ATOMIC_OR(var, val) __sync_fetch_and_or(&(var), (val)) # define ATOMIC_EXCHANGE(var, val) __sync_lock_test_and_set(&(var), (val)) # define ATOMIC_CAS(var, oldval, newval) __sync_val_compare_and_swap(&(var), (oldval), (newval)) -# define ATOMIC_SIZE_ADD(var, val) __sync_fetch_and_add(&(var), (val)) -# define ATOMIC_SIZE_SUB(var, val) __sync_fetch_and_sub(&(var), (val)) - # define RUBY_ATOMIC_GENERIC_MACRO 1 #elif defined _WIN32 @@ -46,6 +44,8 @@ typedef LONG rb_atomic_t; # define ATOMIC_SET(var, val) InterlockedExchange(&(var), (val)) # define ATOMIC_INC(var) InterlockedIncrement(&(var)) # define ATOMIC_DEC(var) InterlockedDecrement(&(var)) +# define ATOMIC_FETCH_ADD(var, val) InterlockedExchangeAdd(&(var), (val)) +# define ATOMIC_FETCH_SUB(var, val) InterlockedExchangeAdd(&(var), -(LONG)(val)) #if defined __GNUC__ # define ATOMIC_OR(var, val) __asm__("lock\n\t" "orl\t%1, %0" : "=m"(var) : "Ir"(val)) #elif MSC_VERSION_BEFORE(1300) @@ -98,13 +98,28 @@ rb_w32_atomic_cas(volatile rb_atomic_t *var, rb_atomic_t oldval, rb_atomic_t new #include typedef unsigned int rb_atomic_t; -# define ATOMIC_SET(var, val) (void)atomic_swap_uint(&(var), (val)) # define ATOMIC_INC(var) atomic_inc_uint(&(var)) # define ATOMIC_DEC(var) atomic_dec_uint(&(var)) +# define ATOMIC_FETCH_ADD(var, val) rb_atomic_fetch_add(&(var), (val)) +# define ATOMIC_FETCH_SUB(var, val) rb_atomic_fetch_sub(&(var), (val)) +# define ATOMIC_ADD(var, val) atomic_add_uint(&(var), (val)) +# define ATOMIC_SUB(var, val) atomic_sub_uint(&(var), (val)) # define ATOMIC_OR(var, val) atomic_or_uint(&(var), (val)) # define ATOMIC_EXCHANGE(var, val) atomic_swap_uint(&(var), (val)) # define ATOMIC_CAS(var, oldval, newval) atomic_cas_uint(&(var), (oldval), (newval)) +static inline rb_atomic_t +rb_atomic_fetch_add(volatile rb_atomic_t *var, rb_atomic_t val) +{ + return atomic_add_int_nv(var, val) - val; +} + +static inline rb_atomic_t +rb_atomic_fetch_sub(volatile rb_atomic_t *var, rb_atomic_t val) +{ + return atomic_add_int_nv(var, (rb_atomic_t)(-(int)val)) + val; +} + # if defined(_LP64) || defined(_I32LPx) # define ATOMIC_SIZE_ADD(var, val) atomic_add_long(&(var), (val)) # define ATOMIC_SIZE_SUB(var, val) atomic_add_long(&(var), -(val)) @@ -121,30 +136,27 @@ typedef unsigned int rb_atomic_t; # endif #else -typedef int rb_atomic_t; -#define NEED_RUBY_ATOMIC_OPS -extern rb_atomic_t ruby_atomic_exchange(rb_atomic_t *ptr, rb_atomic_t val); -extern rb_atomic_t ruby_atomic_compare_and_swap(rb_atomic_t *ptr, - rb_atomic_t cmp, - rb_atomic_t newval); - -# define ATOMIC_SET(var, val) (void)((var) = (val)) -# define ATOMIC_INC(var) ((var)++) -# define ATOMIC_DEC(var) ((var)--) -# define ATOMIC_OR(var, val) ((var) |= (val)) -# define ATOMIC_EXCHANGE(var, val) ruby_atomic_exchange(&(var), (val)) -# define ATOMIC_CAS(var, oldval, newval) ruby_atomic_compare_and_swap(&(var), (oldval), (newval)) - -# define ATOMIC_SIZE_ADD(var, val) (void)((var) += (val)) -# define ATOMIC_SIZE_SUB(var, val) (void)((var) -= (val)) -# define ATOMIC_SIZE_EXCHANGE(var, val) ruby_atomic_size_exchange(&(var), (val)) -static inline size_t -ruby_atomic_size_exchange(size_t *ptr, size_t val) -{ - size_t old = *ptr; - *ptr = val; - return old; -} +# error No atomic operation found +#endif + +#ifndef ATOMIC_SET +# define ATOMIC_SET(var, val) (void)ATOMIC_EXCHANGE(var, val) +#endif + +#ifndef ATOMIC_ADD +# define ATOMIC_ADD(var, val) (void)ATOMIC_FETCH_ADD(var, val) +#endif + +#ifndef ATOMIC_SUB +# define ATOMIC_SUB(var, val) (void)ATOMIC_FETCH_SUB(var, val) +#endif + +#ifndef ATOMIC_INC +# define ATOMIC_INC(var) ATOMIC_ADD(var, 1) +#endif + +#ifndef ATOMIC_DEC +# define ATOMIC_DEC(var) ATOMIC_SUB(var, 1) #endif #ifndef ATOMIC_SIZE_INC @@ -163,6 +175,14 @@ ruby_atomic_size_exchange(size_t *ptr, size_t val) # define ATOMIC_SIZE_CAS(var, oldval, val) ATOMIC_CAS(var, oldval, val) #endif +#ifndef ATOMIC_SIZE_ADD +# define ATOMIC_SIZE_ADD(var, val) ATOMIC_ADD(var, val) +#endif + +#ifndef ATOMIC_SIZE_SUB +# define ATOMIC_SIZE_SUB(var, val) ATOMIC_SUB(var, val) +#endif + #if RUBY_ATOMIC_GENERIC_MACRO # ifndef ATOMIC_PTR_EXCHANGE # define ATOMIC_PTR_EXCHANGE(var, val) ATOMIC_EXCHANGE(var, val) @@ -185,14 +205,7 @@ ruby_atomic_size_exchange(size_t *ptr, size_t val) # if SIZEOF_VOIDP == SIZEOF_SIZE_T # define ATOMIC_PTR_EXCHANGE(var, val) (void *)ATOMIC_SIZE_EXCHANGE(*(size_t *)&(var), (size_t)(val)) # else -# define ATOMIC_PTR_EXCHANGE(var, val) ruby_atomic_ptr_exchange((const void **)&(var), (val)) -static inline void * -ruby_atomic_ptr_exchange(const void **ptr, const void *val) -{ - const void *const old = *ptr; - *ptr = val; - return (void *)old; -} +# error No atomic exchange for void* # endif #endif @@ -200,14 +213,7 @@ ruby_atomic_ptr_exchange(const void **ptr, const void *val) # if SIZEOF_VOIDP == SIZEOF_SIZE_T # define ATOMIC_PTR_CAS(var, oldval, val) (void *)ATOMIC_SIZE_CAS(*(size_t *)&(var), (size_t)(oldval), (size_t)(val)) # else -# define ATOMIC_PTR_CAS(var, oldval, val) ruby_atomic_ptr_cas(&(var), (oldval), (val)) -static inline void * -ruby_atomic_ptr_cas(const void **ptr, const void *oldval, const void *val) -{ - const void *const old = *ptr; - if (old == oldval) *ptr = val; - return (void *)old; -} +# error No atomic compare-and-set for void* # endif #endif @@ -215,14 +221,7 @@ ruby_atomic_ptr_cas(const void **ptr, const void *oldval, const void *val) # if SIZEOF_VALUE == SIZEOF_SIZE_T # define ATOMIC_VALUE_EXCHANGE(var, val) ATOMIC_SIZE_EXCHANGE(*(size_t *)&(var), (size_t)(val)) # else -# define ATOMIC_VALUE_EXCHANGE(var, val) ruby_atomic_value_exchange(&(var), (val)) -static inline VALUE -ruby_atomic_value_exchange(VALUE *ptr, VALUE val) -{ - const VALUE old = *ptr; - *ptr = val; - return old; -} +# error No atomic exchange for VALUE # endif #endif @@ -230,14 +229,7 @@ ruby_atomic_value_exchange(VALUE *ptr, VALUE val) # if SIZEOF_VALUE == SIZEOF_SIZE_T # define ATOMIC_VALUE_CAS(var, oldval, val) ATOMIC_SIZE_CAS(*(size_t *)&(var), (size_t)(oldval), (size_t)(val)) # else -# define ATOMIC_VALUE_CAS(var, oldval, val) ruby_atomic_value_cas(&(var), (oldval), (val)) -static inline VALUE -ruby_atomic_value_cas(VALUE *ptr, VALUE oldval, VALUE val) -{ - const VALUE old = *ptr; - if (old == oldval) *ptr = val; - return old; -} +# error No atomic compare-and-set for VALUE # endif #endif diff --git a/spec/bundler/bundler/env_spec.rb b/spec/bundler/bundler/env_spec.rb index 7686fe386a8397..9631a109bd706b 100644 --- a/spec/bundler/bundler/env_spec.rb +++ b/spec/bundler/bundler/env_spec.rb @@ -41,9 +41,15 @@ end it "prints user path" do - with_clear_paths("HOME", "/a/b/c") do + if Gem::VERSION >= "3.2.0.pre.1" + allow(Gem).to receive(:data_home) { "/a/b/c/.local/share" } out = described_class.report - expect(out).to include("User Path /a/b/c/.gem") + expect(out).to include("User Path /a/b/c/.local/share/gem") + else + with_clear_paths("HOME", "/a/b/c") do + out = described_class.report + expect(out).to include("User Path /a/b/c/.gem") + end end end diff --git a/spec/bundler/bundler/friendly_errors_spec.rb b/spec/bundler/bundler/friendly_errors_spec.rb index e9189b0514148b..8df653c0f14f1a 100644 --- a/spec/bundler/bundler/friendly_errors_spec.rb +++ b/spec/bundler/bundler/friendly_errors_spec.rb @@ -6,7 +6,10 @@ RSpec.describe Bundler, "friendly errors" do context "with invalid YAML in .gemrc" do + let(:config_home) { File.dirname(Gem.configuration.config_file_name) } + before do + FileUtils.mkdir_p config_home File.open(Gem.configuration.config_file_name, "w") do |f| f.write "invalid: yaml: hah" end @@ -24,7 +27,11 @@ bundle :install, :env => { "DEBUG" => "true" } - expect(err).to include("Failed to load #{home(".gemrc")}") + if Gem::VERSION >= "3.2.0.pre.1" + expect(err).to include("Failed to load #{File.join(config_home, "gemrc")}") + else + expect(err).to include("Failed to load #{home(".gemrc")}") + end expect(exitstatus).to eq(0) if exitstatus end end diff --git a/spec/mspec/lib/mspec/helpers/ruby_exe.rb b/spec/mspec/lib/mspec/helpers/ruby_exe.rb index 6d5470bbb5731b..075a8aaef52997 100644 --- a/spec/mspec/lib/mspec/helpers/ruby_exe.rb +++ b/spec/mspec/lib/mspec/helpers/ruby_exe.rb @@ -153,5 +153,7 @@ def ruby_cmd(code, opts = {}) body = "-e #{code.inspect}" end - [RUBY_EXE, opts[:options], body, opts[:args]].compact.join(' ') + command = [RUBY_EXE, opts[:options], body, opts[:args]].compact.join(' ') + STDERR.puts "\nruby_cmd: #{command}" if ENV["DEBUG_MSPEC_RUBY_CMD"] == "true" + command end diff --git a/spec/mspec/lib/mspec/helpers/tmp.rb b/spec/mspec/lib/mspec/helpers/tmp.rb index 5062991d6354b1..b2a38ee983ea94 100644 --- a/spec/mspec/lib/mspec/helpers/tmp.rb +++ b/spec/mspec/lib/mspec/helpers/tmp.rb @@ -4,7 +4,14 @@ # directory is empty when the process exits. SPEC_TEMP_DIR_PID = Process.pid -SPEC_TEMP_DIR = File.expand_path(ENV["SPEC_TEMP_DIR"] || "rubyspec_temp/#{SPEC_TEMP_DIR_PID}") + +if spec_temp_dir = ENV["SPEC_TEMP_DIR"] + spec_temp_dir = File.realdirpath(spec_temp_dir) +else + spec_temp_dir = "#{File.realpath(Dir.pwd)}/rubyspec_temp/#{SPEC_TEMP_DIR_PID}" +end +SPEC_TEMP_DIR = spec_temp_dir + SPEC_TEMP_UNIQUIFIER = "0" at_exit do diff --git a/spec/mspec/lib/mspec/runner/formatters.rb b/spec/mspec/lib/mspec/runner/formatters.rb index d085031a1246a8..66f515ddffc314 100644 --- a/spec/mspec/lib/mspec/runner/formatters.rb +++ b/spec/mspec/lib/mspec/runner/formatters.rb @@ -7,6 +7,7 @@ require 'mspec/runner/formatters/unit' require 'mspec/runner/formatters/spinner' require 'mspec/runner/formatters/method' +require 'mspec/runner/formatters/stats' require 'mspec/runner/formatters/yaml' require 'mspec/runner/formatters/profile' require 'mspec/runner/formatters/junit' diff --git a/spec/mspec/lib/mspec/runner/formatters/stats.rb b/spec/mspec/lib/mspec/runner/formatters/stats.rb new file mode 100644 index 00000000000000..8cff96d145ae3f --- /dev/null +++ b/spec/mspec/lib/mspec/runner/formatters/stats.rb @@ -0,0 +1,57 @@ +require 'mspec/runner/formatters/base' + +class StatsPerFileFormatter < BaseFormatter + def initialize(out = nil) + super(out) + @data = {} + @root = File.expand_path(MSpecScript.get(:prefix) || '.') + end + + def register + super + MSpec.register :load, self + MSpec.register :unload, self + end + + # Resets the tallies so the counts are only for this file. + def load + tally.counter.examples = 0 + tally.counter.errors = 0 + tally.counter.failures = 0 + tally.counter.tagged = 0 + end + + def unload + file = format_file MSpec.file + + raise if @data.key?(file) + @data[file] = { + examples: tally.counter.examples, + errors: tally.counter.errors, + failures: tally.counter.failures, + tagged: tally.counter.tagged, + } + end + + def finish + width = @data.keys.max_by(&:size).size + f = "%3d" + @data.each_pair do |file, data| + total = data[:examples] + passing = total - data[:errors] - data[:failures] - data[:tagged] + puts "#{file.ljust(width)} #{f % passing}/#{f % total}" + end + + require 'yaml' + yaml = YAML.dump(@data) + File.write "results-#{RUBY_ENGINE}-#{RUBY_ENGINE_VERSION}.yml", yaml + end + + private def format_file(file) + if file.start_with?(@root) + file[@root.size+1..-1] + else + raise file + end + end +end diff --git a/spec/mspec/lib/mspec/utils/options.rb b/spec/mspec/lib/mspec/utils/options.rb index 886707e0c488ae..cb466f6a83cee1 100644 --- a/spec/mspec/lib/mspec/utils/options.rb +++ b/spec/mspec/lib/mspec/utils/options.rb @@ -274,6 +274,8 @@ def formatters config[:formatter] = SpinnerFormatter when 't', 'method' config[:formatter] = MethodFormatter + when 'e', 'stats' + config[:formatter] = StatsPerFileFormatter when 'y', 'yaml' config[:formatter] = YamlFormatter when 'p', 'profile' @@ -300,6 +302,7 @@ def formatters doc " m, summary SummaryFormatter" doc " a, *, spin SpinnerFormatter" doc " t, method MethodFormatter" + doc " e, stats StatsPerFileFormatter" doc " y, yaml YamlFormatter" doc " p, profile ProfileFormatter" doc " j, junit JUnitFormatter\n" @@ -467,8 +470,6 @@ def debug end def all - # Generated with: - # puts File.read(__FILE__).scan(/def (\w+).*\n\s*on\(/) configure {} targets formatters @@ -481,6 +482,7 @@ def all repeat verbose interrupt + timeout verify action_filters actions diff --git a/spec/mspec/spec/fixtures/my_ruby b/spec/mspec/spec/fixtures/my_ruby index 4d552f27fb45ca..eeda3eeeece08e 100755 --- a/spec/mspec/spec/fixtures/my_ruby +++ b/spec/mspec/spec/fixtures/my_ruby @@ -1,4 +1,4 @@ #!/usr/bin/env bash echo $RUBY_EXE -ruby "$@" +exec ruby "$@" diff --git a/spec/mspec/spec/utils/options_spec.rb b/spec/mspec/spec/utils/options_spec.rb index ef85c412465ddb..f3a704652640aa 100644 --- a/spec/mspec/spec/utils/options_spec.rb +++ b/spec/mspec/spec/utils/options_spec.rb @@ -1283,3 +1283,22 @@ end end end + +describe "MSpecOptions#all" do + it "includes all options" do + meth = MSpecOptions.instance_method(:all) + file, line = meth.source_location + contents = File.read(file) + lines = contents.lines + + from = line + to = from + to += 1 until /^\s*end\s*$/ =~ lines[to] + calls = lines[from...to].map(&:strip) + + option_methods = contents.scan(/def (\w+).*\n\s*on\(/).map(&:first) + option_methods[0].sub!("configure", "configure {}") + + calls.should == option_methods + end +end diff --git a/spec/mspec/tool/sync/sync-rubyspec.rb b/spec/mspec/tool/sync/sync-rubyspec.rb index c1218bb02ca4a0..8a66217e4e0c18 100644 --- a/spec/mspec/tool/sync/sync-rubyspec.rb +++ b/spec/mspec/tool/sync/sync-rubyspec.rb @@ -18,7 +18,7 @@ MSPEC = ARGV.delete('--mspec') CHECK_LAST_MERGE = ENV['CHECK_LAST_MERGE'] != 'false' -TEST_TRUNK = ENV['TEST_TRUNK'] != 'false' +TEST_MASTER = ENV['TEST_MASTER'] != 'false' MSPEC_REPO = File.expand_path("../../..", __FILE__) raise MSPEC_REPO if !Dir.exist?(MSPEC_REPO) or !Dir.exist?("#{MSPEC_REPO}/.git") @@ -172,7 +172,7 @@ def test_new_specs run_test[min_version] run_test[max_version] - run_test["trunk"] if TEST_TRUNK + run_test["master"] if TEST_MASTER end end diff --git a/spec/ruby/command_line/error_message_spec.rb b/spec/ruby/command_line/error_message_spec.rb index 5fee3ead44976e..f3f7de4fd4aa60 100644 --- a/spec/ruby/command_line/error_message_spec.rb +++ b/spec/ruby/command_line/error_message_spec.rb @@ -3,9 +3,9 @@ describe "The error message caused by an exception" do it "is not printed to stdout" do out = ruby_exe("this_does_not_exist", args: "2> #{File::NULL}") - out.chomp.empty?.should == true + out.chomp.should.empty? out = ruby_exe("end #syntax error", args: "2> #{File::NULL}") - out.chomp.empty?.should == true + out.chomp.should.empty? end end diff --git a/spec/ruby/core/argf/binmode_spec.rb b/spec/ruby/core/argf/binmode_spec.rb index bdcc6aa30ab197..e083a30a27aed1 100644 --- a/spec/ruby/core/argf/binmode_spec.rb +++ b/spec/ruby/core/argf/binmode_spec.rb @@ -34,7 +34,7 @@ it "sets the file's encoding to BINARY" do argf [@bin_file, @file1] do @argf.binmode - @argf.binmode?.should == true + @argf.should.binmode? @argf.gets.encoding.should == Encoding::BINARY @argf.skip @argf.read.encoding.should == Encoding::BINARY diff --git a/spec/ruby/core/array/any_spec.rb b/spec/ruby/core/array/any_spec.rb index 2fa5353e9925f5..09d949fe6e89d7 100644 --- a/spec/ruby/core/array/any_spec.rb +++ b/spec/ruby/core/array/any_spec.rb @@ -4,17 +4,17 @@ describe 'with no block given (a default block of { |x| x } is implicit)' do it "is false if the array is empty" do empty_array = [] - empty_array.any?.should == false + empty_array.should_not.any? end it "is false if the array is not empty, but all the members of the array are falsy" do falsy_array = [false, nil, false] - falsy_array.any?.should == false + falsy_array.should_not.any? end it "is true if the array has any truthy members" do not_empty_array = ['anything', nil] - not_empty_array.any?.should == true + not_empty_array.should.any? end end diff --git a/spec/ruby/core/array/clear_spec.rb b/spec/ruby/core/array/clear_spec.rb index 5c7a934d75b30e..bddc672d3b8f74 100644 --- a/spec/ruby/core/array/clear_spec.rb +++ b/spec/ruby/core/array/clear_spec.rb @@ -16,7 +16,7 @@ it "leaves the Array empty" do a = [1] a.clear - a.empty?.should == true + a.should.empty? a.size.should == 0 end diff --git a/spec/ruby/core/array/clone_spec.rb b/spec/ruby/core/array/clone_spec.rb index 803e746e029c42..e22a6c6d536795 100644 --- a/spec/ruby/core/array/clone_spec.rb +++ b/spec/ruby/core/array/clone_spec.rb @@ -12,8 +12,8 @@ aa = a.clone bb = b.clone - aa.frozen?.should == true - bb.frozen?.should == false + aa.should.frozen? + bb.should_not.frozen? end it "copies singleton methods" do diff --git a/spec/ruby/core/array/empty_spec.rb b/spec/ruby/core/array/empty_spec.rb index b5f3e8ed48f2b5..f70b1b6ebe03ac 100644 --- a/spec/ruby/core/array/empty_spec.rb +++ b/spec/ruby/core/array/empty_spec.rb @@ -3,8 +3,8 @@ describe "Array#empty?" do it "returns true if the array has no elements" do - [].empty?.should == true - [1].empty?.should == false - [1, 2].empty?.should == false + [].should.empty? + [1].should_not.empty? + [1, 2].should_not.empty? end end diff --git a/spec/ruby/core/array/frozen_spec.rb b/spec/ruby/core/array/frozen_spec.rb index bb4b2b4067654c..3ba54be46bb61f 100644 --- a/spec/ruby/core/array/frozen_spec.rb +++ b/spec/ruby/core/array/frozen_spec.rb @@ -4,13 +4,13 @@ describe "Array#frozen?" do it "returns true if array is frozen" do a = [1, 2, 3] - a.frozen?.should == false + a.should_not.frozen? a.freeze - a.frozen?.should == true + a.should.frozen? end it "returns false for an array being sorted by #sort" do a = [1, 2, 3] - a.sort { |x,y| a.frozen?.should == false; x <=> y } + a.sort { |x,y| a.should_not.frozen?; x <=> y } end end diff --git a/spec/ruby/core/array/multiply_spec.rb b/spec/ruby/core/array/multiply_spec.rb index 4060666d4b9613..8ccec13d429363 100644 --- a/spec/ruby/core/array/multiply_spec.rb +++ b/spec/ruby/core/array/multiply_spec.rb @@ -92,39 +92,39 @@ def obj.to_str() "2" end it "copies the taint status of the original array even if the passed count is 0" do ary = [1, 2, 3] ary.taint - (ary * 0).tainted?.should == true + (ary * 0).should.tainted? end it "copies the taint status of the original array even if the array is empty" do ary = [] ary.taint - (ary * 3).tainted?.should == true + (ary * 3).should.tainted? end it "copies the taint status of the original array if the passed count is not 0" do ary = [1, 2, 3] ary.taint - (ary * 1).tainted?.should == true - (ary * 2).tainted?.should == true + (ary * 1).should.tainted? + (ary * 2).should.tainted? end it "copies the untrusted status of the original array even if the passed count is 0" do ary = [1, 2, 3] ary.untrust - (ary * 0).untrusted?.should == true + (ary * 0).should.untrusted? end it "copies the untrusted status of the original array even if the array is empty" do ary = [] ary.untrust - (ary * 3).untrusted?.should == true + (ary * 3).should.untrusted? end it "copies the untrusted status of the original array if the passed count is not 0" do ary = [1, 2, 3] ary.untrust - (ary * 1).untrusted?.should == true - (ary * 2).untrusted?.should == true + (ary * 1).should.untrusted? + (ary * 2).should.untrusted? end end end diff --git a/spec/ruby/core/array/shared/clone.rb b/spec/ruby/core/array/shared/clone.rb index f6f581b17c2197..3c17b1f10fb02a 100644 --- a/spec/ruby/core/array/shared/clone.rb +++ b/spec/ruby/core/array/shared/clone.rb @@ -26,8 +26,8 @@ aa = a.send @method bb = b.send @method - aa.tainted?.should == true - bb.tainted?.should == false + aa.should.tainted? + bb.should_not.tainted? end it "copies untrusted status from the original" do @@ -37,8 +37,8 @@ aa = a.send @method bb = b.send @method - aa.untrusted?.should == true - bb.untrusted?.should == false + aa.should.untrusted? + bb.should_not.untrusted? end end end diff --git a/spec/ruby/core/array/sort_spec.rb b/spec/ruby/core/array/sort_spec.rb index 541f3a5964c3c7..0c5ecdcbbf6698 100644 --- a/spec/ruby/core/array/sort_spec.rb +++ b/spec/ruby/core/array/sort_spec.rb @@ -58,9 +58,9 @@ b = ArraySpecs::MockForCompared.new c = ArraySpecs::MockForCompared.new - ArraySpecs::MockForCompared.compared?.should == false + ArraySpecs::MockForCompared.should_not.compared? [a, b, c].sort.should == [c, b, a] - ArraySpecs::MockForCompared.compared?.should == true + ArraySpecs::MockForCompared.should.compared? end it "does not deal with exceptions raised by unimplemented or incorrect #<=>" do @@ -104,7 +104,7 @@ it "does not freezes self during being sorted" do a = [1, 2, 3] - a.sort { |x,y| a.frozen?.should == false; x <=> y } + a.sort { |x,y| a.should_not.frozen?; x <=> y } end it "returns the specified value when it would break in the given block" do @@ -207,9 +207,9 @@ class Bignum b = ArraySpecs::MockForCompared.new c = ArraySpecs::MockForCompared.new - ArraySpecs::MockForCompared.compared?.should == false + ArraySpecs::MockForCompared.should_not.compared? [a, b, c].sort!.should == [c, b, a] - ArraySpecs::MockForCompared.compared?.should == true + ArraySpecs::MockForCompared.should.compared? end it "does not call #<=> on contained objects when invoked with a block" do diff --git a/spec/ruby/core/array/uniq_spec.rb b/spec/ruby/core/array/uniq_spec.rb index 38e1878f10e142..fd604987c1a93b 100644 --- a/spec/ruby/core/array/uniq_spec.rb +++ b/spec/ruby/core/array/uniq_spec.rb @@ -87,8 +87,8 @@ def obj.eql?(o) end a.uniq.should == a - a[0].tainted?.should == true - a[1].tainted?.should == true + a[0].should.tainted? + a[1].should.tainted? a = Array.new(2) do obj = mock('0') @@ -106,8 +106,8 @@ def obj.eql?(o) end a.uniq.size.should == 1 - a[0].tainted?.should == true - a[1].tainted?.should == true + a[0].should.tainted? + a[1].should.tainted? end end diff --git a/spec/ruby/core/class/allocate_spec.rb b/spec/ruby/core/class/allocate_spec.rb index c426c38ff9ac34..b39622e06a4ade 100644 --- a/spec/ruby/core/class/allocate_spec.rb +++ b/spec/ruby/core/class/allocate_spec.rb @@ -30,7 +30,7 @@ def initialized? end end - klass.allocate.initialized?.should == false + klass.allocate.should_not.initialized? end it "raises TypeError for #superclass" do diff --git a/spec/ruby/core/class/new_spec.rb b/spec/ruby/core/class/new_spec.rb index 8191ce6a375df8..989d674558f20c 100644 --- a/spec/ruby/core/class/new_spec.rb +++ b/spec/ruby/core/class/new_spec.rb @@ -126,7 +126,7 @@ def initialized? end end - klass.new.initialized?.should == true + klass.new.should.initialized? klass.new(1, 2, 3).args.should == [1, 2, 3] end diff --git a/spec/ruby/core/complex/finite_spec.rb b/spec/ruby/core/complex/finite_spec.rb index 718848390cfa38..7d9f82404e7cbd 100644 --- a/spec/ruby/core/complex/finite_spec.rb +++ b/spec/ruby/core/complex/finite_spec.rb @@ -2,31 +2,31 @@ describe "Complex#finite?" do it "returns true if magnitude is finite" do - (1+1i).finite?.should == true + (1+1i).should.finite? end it "returns false for positive infinity" do value = Complex(Float::INFINITY, 42) - value.finite?.should == false + value.should_not.finite? end it "returns false for positive complex with infinite imaginary" do value = Complex(1, Float::INFINITY) - value.finite?.should == false + value.should_not.finite? end it "returns false for negative infinity" do value = -Complex(Float::INFINITY, 42) - value.finite?.should == false + value.should_not.finite? end it "returns false for negative complex with infinite imaginary" do value = -Complex(1, Float::INFINITY) - value.finite?.should == false + value.should_not.finite? end it "returns false for NaN" do value = Complex(Float::NAN, Float::NAN) - value.finite?.should == false + value.should_not.finite? end end diff --git a/spec/ruby/core/dir/fixtures/common.rb b/spec/ruby/core/dir/fixtures/common.rb index f6708b04f78a2d..96dba56c93b690 100644 --- a/spec/ruby/core/dir/fixtures/common.rb +++ b/spec/ruby/core/dir/fixtures/common.rb @@ -22,7 +22,7 @@ def self.clear_dirs [0xe9].pack('U') ].each do |dir| begin - Dir.rmdir dir + Dir.rmdir mock_dir(dir) rescue end end diff --git a/spec/ruby/core/dir/glob_spec.rb b/spec/ruby/core/dir/glob_spec.rb index 4b437b0e242c1e..d4888ee14704ae 100644 --- a/spec/ruby/core/dir/glob_spec.rb +++ b/spec/ruby/core/dir/glob_spec.rb @@ -119,7 +119,7 @@ end it "handles infinite directory wildcards" do - Dir.glob('**/**/**').empty?.should == false + Dir.glob('**/**/**').should_not.empty? end it "handles simple filename patterns" do diff --git a/spec/ruby/core/dir/home_spec.rb b/spec/ruby/core/dir/home_spec.rb index 73deca2cfdfcb5..713ba9db9ad443 100644 --- a/spec/ruby/core/dir/home_spec.rb +++ b/spec/ruby/core/dir/home_spec.rb @@ -17,7 +17,7 @@ end it "returns a non-frozen string" do - Dir.home.frozen?.should == false + Dir.home.should_not.frozen? end end @@ -35,7 +35,7 @@ end it "returns a non-frozen string" do - Dir.home(ENV['USER']).frozen?.should == false + Dir.home(ENV['USER']).should_not.frozen? end end diff --git a/spec/ruby/core/dir/mkdir_spec.rb b/spec/ruby/core/dir/mkdir_spec.rb index c6e2f164e2f633..0ed28f5a99dc79 100644 --- a/spec/ruby/core/dir/mkdir_spec.rb +++ b/spec/ruby/core/dir/mkdir_spec.rb @@ -13,29 +13,33 @@ it "creates the named directory with the given permissions" do DirSpecs.clear_dirs + nonexisting = DirSpecs.mock_dir('nonexisting') + default_perms = DirSpecs.mock_dir('default_perms') + reduced = DirSpecs.mock_dir('reduced') begin - File.should_not.exist?('nonexisting') - Dir.mkdir 'nonexisting' - File.should.exist?('nonexisting') + File.should_not.exist?(nonexisting) + Dir.mkdir nonexisting + File.should.exist?(nonexisting) platform_is_not :windows do - Dir.mkdir 'default_perms' - a = File.stat('default_perms').mode - Dir.mkdir 'reduced', (a - 1) - File.stat('reduced').mode.should_not == a + Dir.mkdir default_perms + a = File.stat(default_perms).mode + Dir.mkdir reduced, (a - 1) + File.stat(reduced).mode.should_not == a end platform_is :windows do - Dir.mkdir 'default_perms', 0666 - a = File.stat('default_perms').mode - Dir.mkdir 'reduced', 0444 - File.stat('reduced').mode.should_not == a + Dir.mkdir default_perms, 0666 + a = File.stat(default_perms).mode + Dir.mkdir reduced, 0444 + File.stat(reduced).mode.should_not == a end - Dir.mkdir('always_returns_0').should == 0 + always_returns_0 = DirSpecs.mock_dir('always_returns_0') + Dir.mkdir(always_returns_0).should == 0 platform_is_not(:windows) do - File.chmod(0777, "nonexisting","default_perms","reduced","always_returns_0") + File.chmod(0777, nonexisting, default_perms, reduced, always_returns_0) end platform_is_not(:windows) do - File.chmod(0644, "nonexisting","default_perms","reduced","always_returns_0") + File.chmod(0644, nonexisting, default_perms, reduced, always_returns_0) end ensure DirSpecs.clear_dirs @@ -45,7 +49,7 @@ it "calls #to_path on non-String arguments" do DirSpecs.clear_dirs p = mock('path') - p.should_receive(:to_path).and_return('nonexisting') + p.should_receive(:to_path).and_return(DirSpecs.mock_dir('nonexisting')) Dir.mkdir(p) DirSpecs.clear_dirs end diff --git a/spec/ruby/core/dir/shared/open.rb b/spec/ruby/core/dir/shared/open.rb index 76b08dc288adef..920845cba18b3d 100644 --- a/spec/ruby/core/dir/shared/open.rb +++ b/spec/ruby/core/dir/shared/open.rb @@ -66,7 +66,7 @@ Dir.send(@method, DirSpecs.mock_dir) do |dir| io = IO.for_fd(dir.fileno) io.autoclose = false - io.close_on_exec?.should == true + io.should.close_on_exec? end end end diff --git a/spec/ruby/core/enumerable/all_spec.rb b/spec/ruby/core/enumerable/all_spec.rb index ae255c662c9473..7e9726fe87054e 100644 --- a/spec/ruby/core/enumerable/all_spec.rb +++ b/spec/ruby/core/enumerable/all_spec.rb @@ -10,13 +10,13 @@ end it "always returns true on empty enumeration" do - @empty.all?.should == true + @empty.should.all? @empty.all? { nil }.should == true - [].all?.should == true + [].should.all? [].all? { false }.should == true - {}.all?.should == true + {}.should.all? {}.all? { nil }.should == true end @@ -38,24 +38,24 @@ describe "with no block" do it "returns true if no elements are false or nil" do - @enum.all?.should == true - @enum1.all?.should == true - @enum2.all?.should == false + @enum.should.all? + @enum1.should.all? + @enum2.should_not.all? - EnumerableSpecs::Numerous.new('a','b','c').all?.should == true - EnumerableSpecs::Numerous.new(0, "x", true).all?.should == true + EnumerableSpecs::Numerous.new('a','b','c').should.all? + EnumerableSpecs::Numerous.new(0, "x", true).should.all? end it "returns false if there are false or nil elements" do - EnumerableSpecs::Numerous.new(false).all?.should == false - EnumerableSpecs::Numerous.new(false, false).all?.should == false + EnumerableSpecs::Numerous.new(false).should_not.all? + EnumerableSpecs::Numerous.new(false, false).should_not.all? - EnumerableSpecs::Numerous.new(nil).all?.should == false - EnumerableSpecs::Numerous.new(nil, nil).all?.should == false + EnumerableSpecs::Numerous.new(nil).should_not.all? + EnumerableSpecs::Numerous.new(nil, nil).should_not.all? - EnumerableSpecs::Numerous.new(1, nil, 2).all?.should == false - EnumerableSpecs::Numerous.new(0, "x", false, true).all?.should == false - @enum2.all?.should == false + EnumerableSpecs::Numerous.new(1, nil, 2).should_not.all? + EnumerableSpecs::Numerous.new(0, "x", false, true).should_not.all? + @enum2.should_not.all? end it "gathers whole arrays as elements when each yields multiple" do diff --git a/spec/ruby/core/enumerable/any_spec.rb b/spec/ruby/core/enumerable/any_spec.rb index 0202506d10b1d1..64e3159963c5dd 100644 --- a/spec/ruby/core/enumerable/any_spec.rb +++ b/spec/ruby/core/enumerable/any_spec.rb @@ -10,13 +10,13 @@ end it "always returns false on empty enumeration" do - @empty.any?.should == false + @empty.should_not.any? @empty.any? { nil }.should == false - [].any?.should == false + [].should_not.any? [].any? { false }.should == false - {}.any?.should == false + {}.should_not.any? {}.any? { nil }.should == false end @@ -38,24 +38,24 @@ describe "with no block" do it "returns true if any element is not false or nil" do - @enum.any?.should == true - @enum1.any?.should == true - @enum2.any?.should == true - EnumerableSpecs::Numerous.new(true).any?.should == true - EnumerableSpecs::Numerous.new('a','b','c').any?.should == true - EnumerableSpecs::Numerous.new('a','b','c', nil).any?.should == true - EnumerableSpecs::Numerous.new(1, nil, 2).any?.should == true - EnumerableSpecs::Numerous.new(1, false).any?.should == true - EnumerableSpecs::Numerous.new(false, nil, 1, false).any?.should == true - EnumerableSpecs::Numerous.new(false, 0, nil).any?.should == true + @enum.should.any? + @enum1.should.any? + @enum2.should.any? + EnumerableSpecs::Numerous.new(true).should.any? + EnumerableSpecs::Numerous.new('a','b','c').should.any? + EnumerableSpecs::Numerous.new('a','b','c', nil).should.any? + EnumerableSpecs::Numerous.new(1, nil, 2).should.any? + EnumerableSpecs::Numerous.new(1, false).should.any? + EnumerableSpecs::Numerous.new(false, nil, 1, false).should.any? + EnumerableSpecs::Numerous.new(false, 0, nil).should.any? end it "returns false if all elements are false or nil" do - EnumerableSpecs::Numerous.new(false).any?.should == false - EnumerableSpecs::Numerous.new(false, false).any?.should == false - EnumerableSpecs::Numerous.new(nil).any?.should == false - EnumerableSpecs::Numerous.new(nil, nil).any?.should == false - EnumerableSpecs::Numerous.new(nil, false, nil).any?.should == false + EnumerableSpecs::Numerous.new(false).should_not.any? + EnumerableSpecs::Numerous.new(false, false).should_not.any? + EnumerableSpecs::Numerous.new(nil).should_not.any? + EnumerableSpecs::Numerous.new(nil, nil).should_not.any? + EnumerableSpecs::Numerous.new(nil, false, nil).should_not.any? end it "gathers whole arrays as elements when each yields multiple" do diff --git a/spec/ruby/core/enumerable/none_spec.rb b/spec/ruby/core/enumerable/none_spec.rb index 8c886736ab4e29..ec48eaf0a73008 100644 --- a/spec/ruby/core/enumerable/none_spec.rb +++ b/spec/ruby/core/enumerable/none_spec.rb @@ -10,7 +10,7 @@ end it "always returns true on empty enumeration" do - @empty.none?.should == true + @empty.should.none? @empty.none? { true }.should == true end diff --git a/spec/ruby/core/enumerable/one_spec.rb b/spec/ruby/core/enumerable/one_spec.rb index 46a10d68ebe51c..6489c84742e7fc 100644 --- a/spec/ruby/core/enumerable/one_spec.rb +++ b/spec/ruby/core/enumerable/one_spec.rb @@ -10,7 +10,7 @@ end it "always returns false on empty enumeration" do - @empty.one?.should == false + @empty.should_not.one? @empty.one? { true }.should == false end diff --git a/spec/ruby/core/enumerable/uniq_spec.rb b/spec/ruby/core/enumerable/uniq_spec.rb index 82c041d4ef1af5..e58dd3636641ff 100644 --- a/spec/ruby/core/enumerable/uniq_spec.rb +++ b/spec/ruby/core/enumerable/uniq_spec.rb @@ -79,8 +79,8 @@ def obj.eql?(o) end a.uniq.should == a - a[0].tainted?.should == true - a[1].tainted?.should == true + a[0].should.tainted? + a[1].should.tainted? a = Array.new(2) do obj = mock('0') @@ -98,8 +98,8 @@ def obj.eql?(o) end a.to_enum.uniq.size.should == 1 - a[0].tainted?.should == true - a[1].tainted?.should == true + a[0].should.tainted? + a[1].should.tainted? end end diff --git a/spec/ruby/core/enumerator/arithmetic_sequence/exclude_end_spec.rb b/spec/ruby/core/enumerator/arithmetic_sequence/exclude_end_spec.rb index 8ce0ce0cd961c6..5be189e9934500 100644 --- a/spec/ruby/core/enumerator/arithmetic_sequence/exclude_end_spec.rb +++ b/spec/ruby/core/enumerator/arithmetic_sequence/exclude_end_spec.rb @@ -4,15 +4,15 @@ describe "Enumerator::ArithmeticSequence#exclude_end?" do context "when created using Numeric#step" do it "always returns false" do - 1.step(10).exclude_end?.should == false - 10.step(1).exclude_end?.should == false + 1.step(10).should_not.exclude_end? + 10.step(1).should_not.exclude_end? end end context "when created using Range#step" do it "mirrors range.exclude_end?" do - (1...10).step.exclude_end?.should == true - (1..10).step.exclude_end?.should == false + (1...10).step.should.exclude_end? + (1..10).step.should_not.exclude_end? end end end diff --git a/spec/ruby/core/enumerator/next_spec.rb b/spec/ruby/core/enumerator/next_spec.rb index 3e9ed8b015017e..a5e01a399d41c2 100644 --- a/spec/ruby/core/enumerator/next_spec.rb +++ b/spec/ruby/core/enumerator/next_spec.rb @@ -24,4 +24,15 @@ @enum.rewind @enum.next.should == 1 end + + it "restarts the enumerator if an exception terminated a previous iteration" do + exception = StandardError.new + enum = Enumerator.new do + raise exception + end + + result = 2.times.map { enum.next rescue $! } + + result.should == [exception, exception] + end end diff --git a/spec/ruby/core/env/element_reference_spec.rb b/spec/ruby/core/env/element_reference_spec.rb index 7d2a2d78e32770..1cd58ace5442a9 100644 --- a/spec/ruby/core/env/element_reference_spec.rb +++ b/spec/ruby/core/env/element_reference_spec.rb @@ -16,7 +16,7 @@ it "returns only frozen values" do ENV[@variable] = "a non-frozen string" - ENV[@variable].frozen?.should == true + ENV[@variable].should.frozen? end it "coerces a non-string name with #to_str" do diff --git a/spec/ruby/core/env/empty_spec.rb b/spec/ruby/core/env/empty_spec.rb index 7ef17d244ff615..afeb406a9e5c5e 100644 --- a/spec/ruby/core/env/empty_spec.rb +++ b/spec/ruby/core/env/empty_spec.rb @@ -4,12 +4,12 @@ it "returns true if the Environment is empty" do if ENV.keys.size > 0 - ENV.empty?.should == false + ENV.should_not.empty? end orig = ENV.to_hash begin ENV.clear - ENV.empty?.should == true + ENV.should.empty? ensure ENV.replace orig end @@ -17,7 +17,7 @@ it "returns false if not empty" do if ENV.keys.size > 0 - ENV.empty?.should == false + ENV.should_not.empty? end end end diff --git a/spec/ruby/core/env/shift_spec.rb b/spec/ruby/core/env/shift_spec.rb index c03b5d50c59e2d..0fe08d4f6dd6c5 100644 --- a/spec/ruby/core/env/shift_spec.rb +++ b/spec/ruby/core/env/shift_spec.rb @@ -2,7 +2,7 @@ describe "ENV.shift" do it "returns a pair and deletes it" do - ENV.empty?.should == false + ENV.should_not.empty? orig = ENV.to_hash begin pair = ENV.shift diff --git a/spec/ruby/core/exception/key_error_spec.rb b/spec/ruby/core/exception/key_error_spec.rb index ad280279d8902e..71bf2b46ff50d4 100644 --- a/spec/ruby/core/exception/key_error_spec.rb +++ b/spec/ruby/core/exception/key_error_spec.rb @@ -10,6 +10,12 @@ error.receiver.should == receiver error.key.should == key + + error = KeyError.new("message", receiver: receiver, key: key) + + error.message.should == "message" + error.receiver.should == receiver + error.key.should == key end end end diff --git a/spec/ruby/core/exception/success_spec.rb b/spec/ruby/core/exception/success_spec.rb index 70af9c74eb56e5..6f217433401360 100644 --- a/spec/ruby/core/exception/success_spec.rb +++ b/spec/ruby/core/exception/success_spec.rb @@ -3,13 +3,13 @@ describe "SystemExit#success?" do it "returns true if the process exited successfully" do -> { exit 0 }.should raise_error(SystemExit) { |e| - e.success?.should == true + e.should.success? } end it "returns false if the process exited unsuccessfully" do -> { exit(-1) }.should raise_error(SystemExit) { |e| - e.success?.should == false + e.should_not.success? } end end diff --git a/spec/ruby/core/false/to_s_spec.rb b/spec/ruby/core/false/to_s_spec.rb index c996d87000536e..4cae27889132dd 100644 --- a/spec/ruby/core/false/to_s_spec.rb +++ b/spec/ruby/core/false/to_s_spec.rb @@ -7,7 +7,7 @@ ruby_version_is "2.7" do it "returns a frozen string" do - false.to_s.frozen?.should == true + false.to_s.should.frozen? end it "always returns the same string" do diff --git a/spec/ruby/core/file/expand_path_spec.rb b/spec/ruby/core/file/expand_path_spec.rb index 88078645abaf2d..c31f885b92f2d2 100644 --- a/spec/ruby/core/file/expand_path_spec.rb +++ b/spec/ruby/core/file/expand_path_spec.rb @@ -203,9 +203,9 @@ it "does not return a frozen string" do home = "/rubyspec_home" - File.expand_path('~').frozen?.should == false - File.expand_path('~', '/tmp/gumby/ddd').frozen?.should == false - File.expand_path('~/a', '/tmp/gumby/ddd').frozen?.should == false + File.expand_path('~').should_not.frozen? + File.expand_path('~', '/tmp/gumby/ddd').should_not.frozen? + File.expand_path('~/a', '/tmp/gumby/ddd').should_not.frozen? end end diff --git a/spec/ruby/core/file/join_spec.rb b/spec/ruby/core/file/join_spec.rb index f1eab02de01d5a..0feedbae93c499 100644 --- a/spec/ruby/core/file/join_spec.rb +++ b/spec/ruby/core/file/join_spec.rb @@ -136,4 +136,13 @@ File.join(bin).should == "bin" File.join("usr", bin).should == "usr/bin" end + + it "raises errors for null bytes" do + -> { File.join("\x00x", "metadata.gz") }.should raise_error(ArgumentError) { |e| + e.message.should == 'string contains null byte' + } + -> { File.join("metadata.gz", "\x00x") }.should raise_error(ArgumentError) { |e| + e.message.should == 'string contains null byte' + } + end end diff --git a/spec/ruby/core/file/lchmod_spec.rb b/spec/ruby/core/file/lchmod_spec.rb index bab362980a3d58..4abe42526d2b04 100644 --- a/spec/ruby/core/file/lchmod_spec.rb +++ b/spec/ruby/core/file/lchmod_spec.rb @@ -20,13 +20,13 @@ File.chmod(0222, @lname).should == 1 File.lchmod(0755, @lname).should == 1 - File.lstat(@lname).executable?.should == true - File.lstat(@lname).readable?.should == true - File.lstat(@lname).writable?.should == true + File.lstat(@lname).should.executable? + File.lstat(@lname).should.readable? + File.lstat(@lname).should.writable? - File.stat(@lname).executable?.should == false - File.stat(@lname).readable?.should == false - File.stat(@lname).writable?.should == true + File.stat(@lname).should_not.executable? + File.stat(@lname).should_not.readable? + File.stat(@lname).should.writable? end end diff --git a/spec/ruby/core/file/lstat_spec.rb b/spec/ruby/core/file/lstat_spec.rb index 918ed02163b6ca..a5ea9d15a55c21 100644 --- a/spec/ruby/core/file/lstat_spec.rb +++ b/spec/ruby/core/file/lstat_spec.rb @@ -22,8 +22,8 @@ it "returns a File::Stat object with symlink properties for a symlink" do st = File.lstat(@link) - st.symlink?.should == true - st.file?.should == false + st.should.symlink? + st.should_not.file? end end end diff --git a/spec/ruby/core/file/open_spec.rb b/spec/ruby/core/file/open_spec.rb index 7ceeb47dd83730..8faa31173eac0e 100644 --- a/spec/ruby/core/file/open_spec.rb +++ b/spec/ruby/core/file/open_spec.rb @@ -28,7 +28,7 @@ describe "with a block" do it "does not raise error when file is closed inside the block" do @fh = File.open(@file) { |fh| fh.close; fh } - @fh.closed?.should == true + @fh.should.closed? end it "invokes close on an opened file when exiting the block" do @@ -485,7 +485,7 @@ File.size(@file).should > 0 File.open(@file, "w+") do |f| f.pos.should == 0 - f.eof?.should == true + f.should.eof? end File.size(@file).should == 0 end @@ -495,7 +495,7 @@ File.size(@file).should > 0 File.open(@file, "rb+") do |f| f.pos.should == 0 - f.eof?.should == false + f.should_not.eof? end end @@ -504,7 +504,7 @@ File.size(@file).should > 0 File.open(@file, "wb+") do |f| f.pos.should == 0 - f.eof?.should == true + f.should.eof? end File.size(@file).should == 0 end diff --git a/spec/ruby/core/file/stat/owned_spec.rb b/spec/ruby/core/file/stat/owned_spec.rb index fbd473c4d7f5c6..a23ad850c5dc81 100644 --- a/spec/ruby/core/file/stat/owned_spec.rb +++ b/spec/ruby/core/file/stat/owned_spec.rb @@ -18,7 +18,7 @@ it "returns true if the file is owned by the user" do st = File.stat(@file) - st.owned?.should == true + st.should.owned? end platform_is_not :windows, :android do @@ -26,7 +26,7 @@ it "returns false if the file is not owned by the user" do system_file = '/etc/passwd' st = File.stat(system_file) - st.owned?.should == false + st.should_not.owned? end end end diff --git a/spec/ruby/core/file/stat/pipe_spec.rb b/spec/ruby/core/file/stat/pipe_spec.rb index 7abb6c742a2670..692dfbf42a4aeb 100644 --- a/spec/ruby/core/file/stat/pipe_spec.rb +++ b/spec/ruby/core/file/stat/pipe_spec.rb @@ -12,7 +12,7 @@ touch(filename) st = File.stat(filename) - st.pipe?.should == false + st.should_not.pipe? rm_r filename end @@ -23,7 +23,7 @@ File.mkfifo(filename) st = File.stat(filename) - st.pipe?.should == true + st.should.pipe? rm_r filename end diff --git a/spec/ruby/core/file/stat_spec.rb b/spec/ruby/core/file/stat_spec.rb index 76b0becbf0fc4a..63655000573bd6 100644 --- a/spec/ruby/core/file/stat_spec.rb +++ b/spec/ruby/core/file/stat_spec.rb @@ -23,8 +23,8 @@ st = f.stat - st.file?.should == true - st.zero?.should == false + st.should.file? + st.should_not.zero? st.size.should == 8 st.size?.should == 8 st.blksize.should >= 0 @@ -38,15 +38,16 @@ File.symlink(@file, @link) st = File.stat(@link) - st.file?.should == true - st.symlink?.should == false + st.should.file? + st.should_not.symlink? end it "returns an error when given missing non-ASCII path" do - missing_path = "/missingfilepath\xE3E4".force_encoding("ASCII-8BIT") + missing_path = "/missingfilepath\xE3E4".b -> { File.stat(missing_path) - }.should raise_error(Errno::ENOENT) { |e| + }.should raise_error(SystemCallError) { |e| + [Errno::ENOENT, Errno::EILSEQ].should include(e.class) e.message.should include(missing_path) } end diff --git a/spec/ruby/core/file/truncate_spec.rb b/spec/ruby/core/file/truncate_spec.rb index 43b86b73821991..b4a2e3e57728c9 100644 --- a/spec/ruby/core/file/truncate_spec.rb +++ b/spec/ruby/core/file/truncate_spec.rb @@ -18,7 +18,7 @@ File.open(@name, "r") do |f| f.read(99).should == "12345" - f.eof?.should == true + f.should.eof? end end @@ -120,7 +120,7 @@ File.size(@name).should == 5 File.open(@name, "r") do |f| f.read(99).should == "12345" - f.eof?.should == true + f.should.eof? end end @@ -161,7 +161,7 @@ it "raises an IOError if file is closed" do @file.close - @file.closed?.should == true + @file.should.closed? -> { @file.truncate(42) }.should raise_error(IOError) end diff --git a/spec/ruby/core/float/finite_spec.rb b/spec/ruby/core/float/finite_spec.rb index c5fb3df849c230..d839b30e321b0a 100644 --- a/spec/ruby/core/float/finite_spec.rb +++ b/spec/ruby/core/float/finite_spec.rb @@ -2,18 +2,18 @@ describe "Float#finite?" do it "returns true for finite values" do - 3.14159.finite?.should == true + 3.14159.should.finite? end it "returns false for positive infinity" do - infinity_value.finite?.should == false + infinity_value.should_not.finite? end it "returns false for negative infinity" do - (-infinity_value).finite?.should == false + (-infinity_value).should_not.finite? end it "returns false for NaN" do - nan_value.finite?.should == false + nan_value.should_not.finite? end end diff --git a/spec/ruby/core/float/nan_spec.rb b/spec/ruby/core/float/nan_spec.rb index d09d25153ce3f1..c1043ef21b18cd 100644 --- a/spec/ruby/core/float/nan_spec.rb +++ b/spec/ruby/core/float/nan_spec.rb @@ -2,8 +2,8 @@ describe "Float#nan?" do it "returns true if self is not a valid IEEE floating-point number" do - 0.0.nan?.should == false - -1.5.nan?.should == false - nan_value.nan?.should == true + 0.0.should_not.nan? + -1.5.should_not.nan? + nan_value.should.nan? end end diff --git a/spec/ruby/core/float/next_float_spec.rb b/spec/ruby/core/float/next_float_spec.rb index 2f0eff605a58d4..29e2d311463e0a 100644 --- a/spec/ruby/core/float/next_float_spec.rb +++ b/spec/ruby/core/float/next_float_spec.rb @@ -44,6 +44,6 @@ end it "returns NAN if NAN was the receiver" do - Float::NAN.next_float.nan?.should == true + Float::NAN.next_float.should.nan? end end diff --git a/spec/ruby/core/float/prev_float_spec.rb b/spec/ruby/core/float/prev_float_spec.rb index 40fcc25a6df03b..5e50269da76055 100644 --- a/spec/ruby/core/float/prev_float_spec.rb +++ b/spec/ruby/core/float/prev_float_spec.rb @@ -44,6 +44,6 @@ end it "returns NAN if NAN was the receiver" do - Float::NAN.prev_float.nan?.should == true + Float::NAN.prev_float.should.nan? end end diff --git a/spec/ruby/core/float/uminus_spec.rb b/spec/ruby/core/float/uminus_spec.rb index e676a26ada28a7..57bae0fb4be9c5 100644 --- a/spec/ruby/core/float/uminus_spec.rb +++ b/spec/ruby/core/float/uminus_spec.rb @@ -23,6 +23,6 @@ end it "returns NaN for NaN" do - nan_value.send(:-@).nan?.should == true + nan_value.send(:-@).should.nan? end end diff --git a/spec/ruby/core/float/zero_spec.rb b/spec/ruby/core/float/zero_spec.rb index e70edc422adffb..1f3de2779352bb 100644 --- a/spec/ruby/core/float/zero_spec.rb +++ b/spec/ruby/core/float/zero_spec.rb @@ -2,8 +2,8 @@ describe "Float#zero?" do it "returns true if self is 0.0" do - 0.0.zero?.should == true - 1.0.zero?.should == false - -1.0.zero?.should == false + 0.0.should.zero? + 1.0.should_not.zero? + -1.0.should_not.zero? end end diff --git a/spec/ruby/core/gc/profiler/disable_spec.rb b/spec/ruby/core/gc/profiler/disable_spec.rb index 321a207deb5c79..74089693eb56b0 100644 --- a/spec/ruby/core/gc/profiler/disable_spec.rb +++ b/spec/ruby/core/gc/profiler/disable_spec.rb @@ -11,6 +11,6 @@ it "disables the profiler" do GC::Profiler.disable - GC::Profiler.enabled?.should == false + GC::Profiler.should_not.enabled? end end diff --git a/spec/ruby/core/gc/profiler/enable_spec.rb b/spec/ruby/core/gc/profiler/enable_spec.rb index 159451167521f9..313ca3d949d81a 100644 --- a/spec/ruby/core/gc/profiler/enable_spec.rb +++ b/spec/ruby/core/gc/profiler/enable_spec.rb @@ -12,6 +12,6 @@ it "enables the profiler" do GC::Profiler.enable - GC::Profiler.enabled?.should == true + GC::Profiler.should.enabled? end end diff --git a/spec/ruby/core/hash/any_spec.rb b/spec/ruby/core/hash/any_spec.rb index bd33e8cd8fa8df..c26dfabde68ebc 100644 --- a/spec/ruby/core/hash/any_spec.rb +++ b/spec/ruby/core/hash/any_spec.rb @@ -4,10 +4,10 @@ describe 'with no block given' do it "checks if there are any members of a Hash" do empty_hash = {} - empty_hash.any?.should == false + empty_hash.should_not.any? hash_with_members = { 'key' => 'value' } - hash_with_members.any?.should == true + hash_with_members.should.any? end end diff --git a/spec/ruby/core/hash/compare_by_identity_spec.rb b/spec/ruby/core/hash/compare_by_identity_spec.rb index 0fd41a4d581775..874cd46eb7cc7f 100644 --- a/spec/ruby/core/hash/compare_by_identity_spec.rb +++ b/spec/ruby/core/hash/compare_by_identity_spec.rb @@ -33,7 +33,7 @@ def o.hash; 123; end it "has no effect on an already compare_by_identity hash" do @idh[:foo] = :bar @idh.compare_by_identity.should equal @idh - @idh.compare_by_identity?.should == true + @idh.should.compare_by_identity? @idh[:foo].should == :bar end diff --git a/spec/ruby/core/hash/empty_spec.rb b/spec/ruby/core/hash/empty_spec.rb index e9be44bab0238e..881e1cc34b677c 100644 --- a/spec/ruby/core/hash/empty_spec.rb +++ b/spec/ruby/core/hash/empty_spec.rb @@ -3,13 +3,13 @@ describe "Hash#empty?" do it "returns true if the hash has no entries" do - {}.empty?.should == true - { 1 => 1 }.empty?.should == false + {}.should.empty? + { 1 => 1 }.should_not.empty? end it "returns true if the hash has no entries and has a default value" do - Hash.new(5).empty?.should == true - Hash.new { 5 }.empty?.should == true - Hash.new { |hsh, k| hsh[k] = k }.empty?.should == true + Hash.new(5).should.empty? + Hash.new { 5 }.should.empty? + Hash.new { |hsh, k| hsh[k] = k }.should.empty? end end diff --git a/spec/ruby/core/hash/reject_spec.rb b/spec/ruby/core/hash/reject_spec.rb index 38589fd880ff97..397000ab677992 100644 --- a/spec/ruby/core/hash/reject_spec.rb +++ b/spec/ruby/core/hash/reject_spec.rb @@ -35,7 +35,7 @@ def h.to_a() end ruby_version_is ''...'2.7' do it "does not taint the resulting hash" do h = { a: 1 }.taint - h.reject {false}.tainted?.should == false + h.reject {false}.should_not.tainted? end end end diff --git a/spec/ruby/core/hash/shared/store.rb b/spec/ruby/core/hash/shared/store.rb index 6e2557eb284e91..84ffb41e33fea0 100644 --- a/spec/ruby/core/hash/shared/store.rb +++ b/spec/ruby/core/hash/shared/store.rb @@ -50,7 +50,7 @@ def key.reverse() "bar" end key << "bar" h.should == { "foo" => 0 } - h.keys[0].frozen?.should == true + h.keys[0].should.frozen? end it "doesn't duplicate and freeze already frozen string keys" do diff --git a/spec/ruby/core/hash/to_proc_spec.rb b/spec/ruby/core/hash/to_proc_spec.rb index 700621f162ce91..8b7ddd5e001aef 100644 --- a/spec/ruby/core/hash/to_proc_spec.rb +++ b/spec/ruby/core/hash/to_proc_spec.rb @@ -21,13 +21,13 @@ ruby_version_is ""..."2.8" do it "is not a lambda" do - @proc.lambda?.should == false + @proc.should_not.lambda? end end ruby_version_is "2.8" do it "is a lambda" do - @proc.lambda?.should == true + @proc.should.lambda? end end diff --git a/spec/ruby/core/integer/integer_spec.rb b/spec/ruby/core/integer/integer_spec.rb index f8067cda06dc4f..2d5d2e3e92dc2c 100644 --- a/spec/ruby/core/integer/integer_spec.rb +++ b/spec/ruby/core/integer/integer_spec.rb @@ -13,8 +13,8 @@ describe "Integer#integer?" do it "returns true for Integers" do - 0.integer?.should == true - -1.integer?.should == true - bignum_value.integer?.should == true + 0.should.integer? + -1.should.integer? + bignum_value.should.integer? end end diff --git a/spec/ruby/core/io/close_on_exec_spec.rb b/spec/ruby/core/io/close_on_exec_spec.rb index f837bb56afd40e..91bd3c8c40f792 100644 --- a/spec/ruby/core/io/close_on_exec_spec.rb +++ b/spec/ruby/core/io/close_on_exec_spec.rb @@ -14,24 +14,24 @@ guard -> { platform_is_not :windows } do it "sets the close-on-exec flag if true" do @io.close_on_exec = true - @io.close_on_exec?.should == true + @io.should.close_on_exec? end it "sets the close-on-exec flag if non-false" do @io.close_on_exec = :true - @io.close_on_exec?.should == true + @io.should.close_on_exec? end it "unsets the close-on-exec flag if false" do @io.close_on_exec = true @io.close_on_exec = false - @io.close_on_exec?.should == false + @io.should_not.close_on_exec? end it "unsets the close-on-exec flag if nil" do @io.close_on_exec = true @io.close_on_exec = nil - @io.close_on_exec?.should == false + @io.should_not.close_on_exec? end it "ensures the IO's file descriptor is closed in exec'ed processes" do @@ -64,12 +64,12 @@ guard -> { platform_is_not :windows } do it "returns true by default" do - @io.close_on_exec?.should == true + @io.should.close_on_exec? end it "returns true if set" do @io.close_on_exec = true - @io.close_on_exec?.should == true + @io.should.close_on_exec? end it "raises IOError if called on a closed IO" do diff --git a/spec/ruby/core/io/close_read_spec.rb b/spec/ruby/core/io/close_read_spec.rb index 6fa4fc8ff84ec6..26454bfddd1635 100644 --- a/spec/ruby/core/io/close_read_spec.rb +++ b/spec/ruby/core/io/close_read_spec.rb @@ -49,7 +49,7 @@ io.close_read - io.closed?.should == true + io.should.closed? end it "does nothing on closed stream" do diff --git a/spec/ruby/core/io/close_spec.rb b/spec/ruby/core/io/close_spec.rb index 37c8ab5a122897..dda82b34de2e42 100644 --- a/spec/ruby/core/io/close_spec.rb +++ b/spec/ruby/core/io/close_spec.rb @@ -14,7 +14,7 @@ it "closes the stream" do @io.close - @io.closed?.should == true + @io.should.closed? end it "returns nil" do diff --git a/spec/ruby/core/io/close_write_spec.rb b/spec/ruby/core/io/close_write_spec.rb index 75e1577654e574..14835e4e2c08bf 100644 --- a/spec/ruby/core/io/close_write_spec.rb +++ b/spec/ruby/core/io/close_write_spec.rb @@ -45,7 +45,7 @@ io.close_write - io.closed?.should == true + io.should.closed? end it "flushes and closes the write stream" do diff --git a/spec/ruby/core/io/copy_stream_spec.rb b/spec/ruby/core/io/copy_stream_spec.rb index c541e96e14c80f..df9c5c7390e446 100644 --- a/spec/ruby/core/io/copy_stream_spec.rb +++ b/spec/ruby/core/io/copy_stream_spec.rb @@ -279,4 +279,44 @@ end end + + + describe "with a destination that does partial reads" do + before do + @from_out, @from_in = IO.pipe + @to_out, @to_in = IO.pipe + end + + after do + [@from_out, @from_in, @to_out, @to_in].each {|io| io.close rescue nil} + end + + it "calls #write repeatedly on the destination Object" do + @from_in.write "1234" + @from_in.close + + th = Thread.new do + IO.copy_stream(@from_out, @to_in) + end + + copied = "" + 4.times do + copied += @to_out.read(1) + end + + th.join + + copied.should == "1234" + end + + end +end + +describe "IO.copy_stream" do + it "does not use buffering when writing to STDOUT" do + IO.popen([*ruby_exe, fixture(__FILE__ , "copy_in_out.rb")], "r+") do |io| + io.write("bar") + io.read(3).should == "bar" + end + end end diff --git a/spec/ruby/core/io/dup_spec.rb b/spec/ruby/core/io/dup_spec.rb index de32c5e3478993..8cadaee118cd4b 100644 --- a/spec/ruby/core/io/dup_spec.rb +++ b/spec/ruby/core/io/dup_spec.rb @@ -51,16 +51,16 @@ @i.close -> { @f.gets }.should_not raise_error(Exception) - @i.closed?.should == true - @f.closed?.should == false + @i.should.closed? + @f.should_not.closed? end it "allows closing the original IO without affecting the new one" do @f.close -> { @i.gets }.should_not raise_error(Exception) - @i.closed?.should == false - @f.closed?.should == true + @i.should_not.closed? + @f.should.closed? end it "raises IOError on closed stream" do @@ -71,7 +71,7 @@ @f.close_on_exec = true dup = @f.dup begin - dup.close_on_exec?.should == true + dup.should.close_on_exec? ensure dup.close end @@ -79,7 +79,7 @@ @f.close_on_exec = false dup = @f.dup begin - dup.close_on_exec?.should == true + dup.should.close_on_exec? ensure dup.close end diff --git a/spec/ruby/core/io/eof_spec.rb b/spec/ruby/core/io/eof_spec.rb index 8fd3c3713235bd..315345d942ab27 100644 --- a/spec/ruby/core/io/eof_spec.rb +++ b/spec/ruby/core/io/eof_spec.rb @@ -12,7 +12,7 @@ end it "returns true on an empty stream that has just been opened" do - File.open(@name) { |empty| empty.eof?.should == true } + File.open(@name) { |empty| empty.should.eof? } end it "raises IOError on stream not opened for reading" do @@ -34,35 +34,35 @@ it "returns false when not at end of file" do @io.read 1 - @io.eof?.should == false + @io.should_not.eof? end it "returns true after reading with read with no parameters" do @io.read() - @io.eof?.should == true + @io.should.eof? end it "returns true after reading with read" do @io.read(File.size(@name)) - @io.eof?.should == true + @io.should.eof? end it "returns true after reading with sysread" do @io.sysread(File.size(@name)) - @io.eof?.should == true + @io.should.eof? end it "returns true after reading with readlines" do @io.readlines - @io.eof?.should == true + @io.should.eof? end it "returns false on just opened non-empty stream" do - @io.eof?.should == false + @io.should_not.eof? end it "does not consume the data from the stream" do - @io.eof?.should == false + @io.should_not.eof? @io.getc.should == 'V' end @@ -78,7 +78,7 @@ it "returns true on one-byte stream after single-byte read" do File.open(File.dirname(__FILE__) + '/fixtures/one_byte.txt') { |one_byte| one_byte.read(1) - one_byte.eof?.should == true + one_byte.should.eof? } end end @@ -92,16 +92,16 @@ it "returns true on receiving side of Pipe when writing side is closed" do @r, @w = IO.pipe @w.close - @r.eof?.should == true + @r.should.eof? end it "returns false on receiving side of Pipe when writing side wrote some data" do @r, @w = IO.pipe @w.puts "hello" - @r.eof?.should == false + @r.should_not.eof? @w.close - @r.eof?.should == false + @r.should_not.eof? @r.read - @r.eof?.should == true + @r.should.eof? end end diff --git a/spec/ruby/core/io/fixtures/classes.rb b/spec/ruby/core/io/fixtures/classes.rb index 460dd62387f748..5cc42c9b44e835 100644 --- a/spec/ruby/core/io/fixtures/classes.rb +++ b/spec/ruby/core/io/fixtures/classes.rb @@ -164,7 +164,7 @@ def initialize(io) @io = io end - def read(size, buf=nil) + def read(size, buf) @io.read size, buf end @@ -178,7 +178,7 @@ def initialize(io) @io = io end - def readpartial(size, buf=nil) + def readpartial(size, buf) @io.readpartial size, buf end diff --git a/spec/ruby/core/io/fixtures/copy_in_out.rb b/spec/ruby/core/io/fixtures/copy_in_out.rb new file mode 100644 index 00000000000000..b9d4085a47e976 --- /dev/null +++ b/spec/ruby/core/io/fixtures/copy_in_out.rb @@ -0,0 +1,2 @@ +STDOUT.sync = false +IO.copy_stream(STDIN, STDOUT) diff --git a/spec/ruby/core/io/gets_spec.rb b/spec/ruby/core/io/gets_spec.rb index 39b2108476d22c..a3cd180b66c930 100644 --- a/spec/ruby/core/io/gets_spec.rb +++ b/spec/ruby/core/io/gets_spec.rb @@ -41,7 +41,7 @@ ruby_version_is ''...'2.7' do it "returns tainted strings" do while line = @io.gets - line.tainted?.should == true + line.should.tainted? end end end @@ -67,7 +67,7 @@ ruby_version_is ''...'2.7' do it "returns tainted strings" do while line = @io.gets(nil) - line.tainted?.should == true + line.should.tainted? end end end @@ -103,7 +103,7 @@ ruby_version_is ''...'2.7' do it "returns tainted strings" do while line = @io.gets("") - line.tainted?.should == true + line.should.tainted? end end end @@ -129,7 +129,7 @@ ruby_version_is ''...'2.7' do it "returns tainted strings" do while line = @io.gets("la") - line.tainted?.should == true + line.should.tainted? end end end diff --git a/spec/ruby/core/io/pipe_spec.rb b/spec/ruby/core/io/pipe_spec.rb index a7dcb7fab8329d..2f2cf06f4d32c1 100644 --- a/spec/ruby/core/io/pipe_spec.rb +++ b/spec/ruby/core/io/pipe_spec.rb @@ -44,8 +44,8 @@ r, w = IO.pipe do |_r, _w| [_r, _w] end - r.closed?.should == true - w.closed?.should == true + r.should.closed? + w.should.closed? end it "closes both IO objects when the block raises" do @@ -57,8 +57,8 @@ raise RuntimeError end end.should raise_error(RuntimeError) - r.closed?.should == true - w.closed?.should == true + r.should.closed? + w.should.closed? end it "allows IO objects to be closed within the block" do @@ -67,8 +67,8 @@ _w.close [_r, _w] end - r.closed?.should == true - w.closed?.should == true + r.should.closed? + w.should.closed? end end end diff --git a/spec/ruby/core/io/popen_spec.rb b/spec/ruby/core/io/popen_spec.rb index 4f873e61cd715c..e9d32c5c7dcc6a 100644 --- a/spec/ruby/core/io/popen_spec.rb +++ b/spec/ruby/core/io/popen_spec.rb @@ -77,10 +77,10 @@ Process.kill "KILL", pid @io.close platform_is_not :windows do - $?.signaled?.should == true + $?.should.signaled? end platform_is :windows do - $?.exited?.should == true + $?.should.exited? end end diff --git a/spec/ruby/core/io/read_nonblock_spec.rb b/spec/ruby/core/io/read_nonblock_spec.rb index 63ccab5a44d124..e50531d336cee2 100644 --- a/spec/ruby/core/io/read_nonblock_spec.rb +++ b/spec/ruby/core/io/read_nonblock_spec.rb @@ -46,7 +46,7 @@ require 'io/nonblock' @write.write "abc" @read.read_nonblock(1).should == "a" - @read.nonblock?.should == true + @read.should.nonblock? end end diff --git a/spec/ruby/core/io/read_spec.rb b/spec/ruby/core/io/read_spec.rb index 1e9a8d2a4f8828..841e693f373c47 100644 --- a/spec/ruby/core/io/read_spec.rb +++ b/spec/ruby/core/io/read_spec.rb @@ -216,7 +216,7 @@ it "is at end-of-file when everything has been read" do @io.read - @io.eof?.should == true + @io.should.eof? end it "reads the contents of a file" do diff --git a/spec/ruby/core/io/reopen_spec.rb b/spec/ruby/core/io/reopen_spec.rb index faef80f51398b9..8ff0f217f4410a 100644 --- a/spec/ruby/core/io/reopen_spec.rb +++ b/spec/ruby/core/io/reopen_spec.rb @@ -150,11 +150,11 @@ @io.close_on_exec = true @io.reopen @other_name - @io.close_on_exec?.should == true + @io.should.close_on_exec? @io.close_on_exec = false @io.reopen @other_name - @io.close_on_exec?.should == true + @io.should.close_on_exec? end it "creates the file if it doesn't exist if the IO is opened in write mode" do @@ -293,12 +293,12 @@ def @io.to_io; flunk; end @other_io.close_on_exec = true @io.close_on_exec = true @io.reopen @other_io - @io.close_on_exec?.should == true + @io.should.close_on_exec? @other_io.close_on_exec = false @io.close_on_exec = false @io.reopen @other_io - @io.close_on_exec?.should == true + @io.should.close_on_exec? end it "may change the class of the instance" do diff --git a/spec/ruby/core/io/rewind_spec.rb b/spec/ruby/core/io/rewind_spec.rb index 954d56d30c1f74..649041afafba0b 100644 --- a/spec/ruby/core/io/rewind_spec.rb +++ b/spec/ruby/core/io/rewind_spec.rb @@ -21,7 +21,7 @@ it "positions the instance to the beginning of input and clears EOF" do value = @io.read @io.rewind - @io.eof?.should == false + @io.should_not.eof? value.should == @io.read end diff --git a/spec/ruby/core/io/seek_spec.rb b/spec/ruby/core/io/seek_spec.rb index 7e9c308272293d..2fa4a73ac9e661 100644 --- a/spec/ruby/core/io/seek_spec.rb +++ b/spec/ruby/core/io/seek_spec.rb @@ -44,21 +44,21 @@ it "moves the read position and clears EOF with SEEK_SET" do value = @io.read @io.seek(0, IO::SEEK_SET) - @io.eof?.should == false + @io.should_not.eof? value.should == @io.read end it "moves the read position and clears EOF with SEEK_CUR" do value = @io.read @io.seek(-1, IO::SEEK_CUR) - @io.eof?.should == false + @io.should_not.eof? value[-1].should == @io.read[0] end it "moves the read position and clears EOF with SEEK_END" do value = @io.read @io.seek(-1, IO::SEEK_END) - @io.eof?.should == false + @io.should_not.eof? value[-1].should == @io.read[0] end diff --git a/spec/ruby/core/io/shared/new.rb b/spec/ruby/core/io/shared/new.rb index 27d32f97eda6d8..87f30018626567 100644 --- a/spec/ruby/core/io/shared/new.rb +++ b/spec/ruby/core/io/shared/new.rb @@ -148,22 +148,22 @@ it "sets binmode from mode string" do @io = IO.send(@method, @fd, 'wb') - @io.binmode?.should == true + @io.should.binmode? end it "does not set binmode without being asked" do @io = IO.send(@method, @fd, 'w') - @io.binmode?.should == false + @io.should_not.binmode? end it "sets binmode from :binmode option" do @io = IO.send(@method, @fd, 'w', binmode: true) - @io.binmode?.should == true + @io.should.binmode? end it "does not set binmode from false :binmode" do @io = IO.send(@method, @fd, 'w', binmode: false) - @io.binmode?.should == false + @io.should_not.binmode? end it "sets external encoding to binary with binmode in mode string" do @@ -270,13 +270,13 @@ it "accepts an :autoclose option" do @io = IO.send(@method, @fd, 'w', autoclose: false) - @io.autoclose?.should == false + @io.should_not.autoclose? @io.autoclose = true end it "accepts any truthy option :autoclose" do @io = IO.send(@method, @fd, 'w', autoclose: 42) - @io.autoclose?.should == true + @io.should.autoclose? end end diff --git a/spec/ruby/core/io/shared/pos.rb b/spec/ruby/core/io/shared/pos.rb index fb6d8087bc9afe..0b4d1e13b31cd3 100644 --- a/spec/ruby/core/io/shared/pos.rb +++ b/spec/ruby/core/io/shared/pos.rb @@ -27,7 +27,7 @@ io.read 1 io.read 1 io.send(@method) - io.eof?.should == false + io.should_not.eof? end end end diff --git a/spec/ruby/core/io/ungetc_spec.rb b/spec/ruby/core/io/ungetc_spec.rb index 4be0e3aa8ba533..85c15b5a71d093 100644 --- a/spec/ruby/core/io/ungetc_spec.rb +++ b/spec/ruby/core/io/ungetc_spec.rb @@ -74,10 +74,10 @@ touch(@empty) File.open(@empty) { |empty| - empty.eof?.should == true + empty.should.eof? empty.getc.should == nil empty.ungetc(100) - empty.eof?.should == false + empty.should_not.eof? } end diff --git a/spec/ruby/core/io/write_nonblock_spec.rb b/spec/ruby/core/io/write_nonblock_spec.rb index 5474e5c6cedf87..a8b9ce0a36234f 100644 --- a/spec/ruby/core/io/write_nonblock_spec.rb +++ b/spec/ruby/core/io/write_nonblock_spec.rb @@ -79,7 +79,7 @@ it 'sets the IO in nonblock mode' do require 'io/nonblock' @write.write_nonblock('a') - @write.nonblock?.should == true + @write.should.nonblock? end end end diff --git a/spec/ruby/core/kernel/backtick_spec.rb b/spec/ruby/core/kernel/backtick_spec.rb index 5ab0fb0eea8dad..391583b5390739 100644 --- a/spec/ruby/core/kernel/backtick_spec.rb +++ b/spec/ruby/core/kernel/backtick_spec.rb @@ -40,16 +40,16 @@ ip = 'world' `echo disc #{ip}` $?.should be_kind_of(Process::Status) - $?.stopped?.should == false - $?.exited?.should == true + $?.should_not.stopped? + $?.should.exited? $?.exitstatus.should == 0 - $?.success?.should == true + $?.should.success? `echo disc #{ip}; exit 99` $?.should be_kind_of(Process::Status) - $?.stopped?.should == false - $?.exited?.should == true + $?.should_not.stopped? + $?.should.exited? $?.exitstatus.should == 99 - $?.success?.should == false + $?.should_not.success? end end @@ -58,16 +58,16 @@ ip = 'world' `echo disc #{ip}` $?.should be_kind_of(Process::Status) - $?.stopped?.should == false - $?.exited?.should == true + $?.should_not.stopped? + $?.should.exited? $?.exitstatus.should == 0 - $?.success?.should == true + $?.should.success? `echo disc #{ip}& exit 99` $?.should be_kind_of(Process::Status) - $?.stopped?.should == false - $?.exited?.should == true + $?.should_not.stopped? + $?.should.exited? $?.exitstatus.should == 99 - $?.success?.should == false + $?.should_not.success? end end end diff --git a/spec/ruby/core/kernel/caller_locations_spec.rb b/spec/ruby/core/kernel/caller_locations_spec.rb index cb344e16a0faee..c4e008408592b5 100644 --- a/spec/ruby/core/kernel/caller_locations_spec.rb +++ b/spec/ruby/core/kernel/caller_locations_spec.rb @@ -7,7 +7,7 @@ end it 'returns an Array of caller locations' do - KernelSpecs::CallerLocationsTest.locations.empty?.should == false + KernelSpecs::CallerLocationsTest.locations.should_not.empty? end it 'returns an Array of caller locations using a custom offset' do diff --git a/spec/ruby/core/kernel/caller_spec.rb b/spec/ruby/core/kernel/caller_spec.rb index e943e36dc29058..b71060770c5bc7 100644 --- a/spec/ruby/core/kernel/caller_spec.rb +++ b/spec/ruby/core/kernel/caller_spec.rb @@ -7,7 +7,7 @@ end it 'returns an Array of caller locations' do - KernelSpecs::CallerTest.locations.empty?.should == false + KernelSpecs::CallerTest.locations.should_not.empty? end it 'returns an Array of caller locations using a custom offset' do diff --git a/spec/ruby/core/kernel/clone_spec.rb b/spec/ruby/core/kernel/clone_spec.rb index 1bbef64f852ebf..6aeb57f55b2b01 100644 --- a/spec/ruby/core/kernel/clone_spec.rb +++ b/spec/ruby/core/kernel/clone_spec.rb @@ -33,22 +33,22 @@ def klass.allocate @obj.freeze o3 = @obj.clone - o2.frozen?.should == false - o3.frozen?.should == true + o2.should_not.frozen? + o3.should.frozen? end ruby_version_is '2.8' do it 'takes an freeze: true option to frozen copy' do - @obj.clone(freeze: true).frozen?.should == true + @obj.clone(freeze: true).should.frozen? @obj.freeze - @obj.clone(freeze: true).frozen?.should == true + @obj.clone(freeze: true).should.frozen? end end it 'takes an freeze: false option to not return frozen copy' do - @obj.clone(freeze: false).frozen?.should == false + @obj.clone(freeze: false).should_not.frozen? @obj.freeze - @obj.clone(freeze: false).frozen?.should == false + @obj.clone(freeze: false).should_not.frozen? end it "copies instance variables" do diff --git a/spec/ruby/core/kernel/dup_spec.rb b/spec/ruby/core/kernel/dup_spec.rb index fe0a269d69d161..70198abdb7554b 100644 --- a/spec/ruby/core/kernel/dup_spec.rb +++ b/spec/ruby/core/kernel/dup_spec.rb @@ -32,7 +32,7 @@ def klass.allocate @obj.freeze dup = @obj.dup - dup.frozen?.should == false + dup.should_not.frozen? end it "copies instance variables" do diff --git a/spec/ruby/core/kernel/frozen_spec.rb b/spec/ruby/core/kernel/frozen_spec.rb index 54edae15b15e51..a4cec4263db472 100644 --- a/spec/ruby/core/kernel/frozen_spec.rb +++ b/spec/ruby/core/kernel/frozen_spec.rb @@ -6,8 +6,8 @@ o = mock('o') p = mock('p') p.freeze - o.frozen?.should == false - p.frozen?.should == true + o.should_not.frozen? + p.should.frozen? end describe "on true, false and nil" do diff --git a/spec/ruby/core/kernel/require_relative_spec.rb b/spec/ruby/core/kernel/require_relative_spec.rb index b292a46c638e4f..d4146eb3c8befb 100644 --- a/spec/ruby/core/kernel/require_relative_spec.rb +++ b/spec/ruby/core/kernel/require_relative_spec.rb @@ -90,6 +90,16 @@ ScratchPad.recorded.should == [] end + it "raises a LoadError that includes the missing path" do + missing_path = "#{@dir}/nonexistent.rb" + expanded_missing_path = File.expand_path(missing_path, File.dirname(__FILE__)) + -> { require_relative(missing_path) }.should raise_error(LoadError) { |e| + e.message.should include(expanded_missing_path) + e.path.should == expanded_missing_path + } + ScratchPad.recorded.should == [] + end + it "raises a LoadError if basepath does not exist" do -> { eval("require_relative('#{@dir}/nonexistent.rb')") }.should raise_error(LoadError) end diff --git a/spec/ruby/core/kernel/shared/dup_clone.rb b/spec/ruby/core/kernel/shared/dup_clone.rb index 968efd80f3d230..84ad49cbde59d7 100644 --- a/spec/ruby/core/kernel/shared/dup_clone.rb +++ b/spec/ruby/core/kernel/shared/dup_clone.rb @@ -59,8 +59,8 @@ def initialize_copy(original) o.taint o3 = o.send(@method) - o2.tainted?.should == false - o3.tainted?.should == true + o2.should_not.tainted? + o3.should.tainted? end end @@ -78,8 +78,8 @@ def initialize_copy(original) o.untrust o3 = o.send(@method) - o2.untrusted?.should == false - o3.untrusted?.should == true + o2.should_not.untrusted? + o3.should.untrusted? end end diff --git a/spec/ruby/core/kernel/system_spec.rb b/spec/ruby/core/kernel/system_spec.rb index 96c0496dd6fde4..696e6ae3d7c38c 100644 --- a/spec/ruby/core/kernel/system_spec.rb +++ b/spec/ruby/core/kernel/system_spec.rb @@ -6,14 +6,14 @@ -> { @object.system("echo a") }.should output_to_fd("a\n") $?.should be_an_instance_of Process::Status - $?.success?.should == true + $?.should.success? end it "returns true when the command exits with a zero exit status" do @object.system(ruby_cmd('exit 0')).should == true $?.should be_an_instance_of Process::Status - $?.success?.should == true + $?.should.success? $?.exitstatus.should == 0 end @@ -21,7 +21,7 @@ @object.system(ruby_cmd('exit 1')).should == false $?.should be_an_instance_of Process::Status - $?.success?.should == false + $?.should_not.success? $?.exitstatus.should == 1 end @@ -40,7 +40,7 @@ $?.should be_an_instance_of Process::Status $?.pid.should be_kind_of(Integer) - $?.exitstatus.should == 127 + $?.should_not.success? end it "does not write to stderr when command execution fails" do diff --git a/spec/ruby/core/kernel/taint_spec.rb b/spec/ruby/core/kernel/taint_spec.rb index 2d2b34d0d04c2d..060e73963e09a8 100644 --- a/spec/ruby/core/kernel/taint_spec.rb +++ b/spec/ruby/core/kernel/taint_spec.rb @@ -11,7 +11,7 @@ it "sets the tainted bit" do o = Object.new o.taint - o.tainted?.should == true + o.should.tainted? end it "raises FrozenError on an untainted, frozen object" do @@ -27,20 +27,20 @@ it "has no effect on immediate values" do [nil, true, false].each do |v| v.taint - v.tainted?.should == false + v.should_not.tainted? end end it "no raises a RuntimeError on symbols" do v = :sym -> { v.taint }.should_not raise_error(RuntimeError) - v.tainted?.should == false + v.should_not.tainted? end it "no raises error on fixnum values" do [1].each do |v| -> { v.taint }.should_not raise_error(RuntimeError) - v.tainted?.should == false + v.should_not.tainted? end end end diff --git a/spec/ruby/core/kernel/tainted_spec.rb b/spec/ruby/core/kernel/tainted_spec.rb index 72ce346dda3314..dbd6bc939ac17e 100644 --- a/spec/ruby/core/kernel/tainted_spec.rb +++ b/spec/ruby/core/kernel/tainted_spec.rb @@ -7,8 +7,8 @@ o = mock('o') p = mock('p') p.taint - o.tainted?.should == false - p.tainted?.should == true + o.should_not.tainted? + p.should.tainted? end end end diff --git a/spec/ruby/core/kernel/trust_spec.rb b/spec/ruby/core/kernel/trust_spec.rb index dbc05b45d42a1a..1d209ea1dc450e 100644 --- a/spec/ruby/core/kernel/trust_spec.rb +++ b/spec/ruby/core/kernel/trust_spec.rb @@ -11,7 +11,7 @@ it "clears the untrusted bit" do o = Object.new.untrust o.trust - o.untrusted?.should == false + o.should_not.untrusted? end it "raises FrozenError on an untrusted, frozen object" do diff --git a/spec/ruby/core/kernel/untaint_spec.rb b/spec/ruby/core/kernel/untaint_spec.rb index df9e3144a0432b..171d32b35694ca 100644 --- a/spec/ruby/core/kernel/untaint_spec.rb +++ b/spec/ruby/core/kernel/untaint_spec.rb @@ -11,7 +11,7 @@ it "clears the tainted bit" do o = Object.new.taint o.untaint - o.tainted?.should == false + o.should_not.tainted? end it "raises FrozenError on a tainted, frozen object" do diff --git a/spec/ruby/core/kernel/untrust_spec.rb b/spec/ruby/core/kernel/untrust_spec.rb index c5a36e1a1d302f..fca7c9ea4727fa 100644 --- a/spec/ruby/core/kernel/untrust_spec.rb +++ b/spec/ruby/core/kernel/untrust_spec.rb @@ -11,7 +11,7 @@ it "sets the untrusted bit" do o = Object.new o.untrust - o.untrusted?.should == true + o.should.untrusted? end it "raises FrozenError on a trusted, frozen object" do diff --git a/spec/ruby/core/kernel/untrusted_spec.rb b/spec/ruby/core/kernel/untrusted_spec.rb index ccebfe38bea8a2..65cbffa3add483 100644 --- a/spec/ruby/core/kernel/untrusted_spec.rb +++ b/spec/ruby/core/kernel/untrusted_spec.rb @@ -5,9 +5,9 @@ ruby_version_is ''...'2.7' do it "returns the untrusted status of an object" do o = mock('o') - o.untrusted?.should == false + o.should_not.untrusted? o.untrust - o.untrusted?.should == true + o.should.untrusted? end it "has no effect on immediate values" do @@ -17,9 +17,9 @@ a.untrust b.untrust c.untrust - a.untrusted?.should == false - b.untrusted?.should == false - c.untrusted?.should == false + a.should_not.untrusted? + b.should_not.untrusted? + c.should_not.untrusted? end it "has effect on immediate values" do diff --git a/spec/ruby/core/matchdata/string_spec.rb b/spec/ruby/core/matchdata/string_spec.rb index db0d5dfbdca301..420233e1f39b2a 100644 --- a/spec/ruby/core/matchdata/string_spec.rb +++ b/spec/ruby/core/matchdata/string_spec.rb @@ -9,7 +9,7 @@ it "returns a frozen copy of the match string" do str = /(.)(.)(\d+)(\d)/.match("THX1138.").string str.should == "THX1138." - str.frozen?.should == true + str.should.frozen? end it "returns the same frozen string for every call" do @@ -20,6 +20,6 @@ it "returns a frozen copy of the matched string for gsub(String)" do 'he[[o'.gsub!('[', ']') $~.string.should == 'he[[o' - $~.string.frozen?.should == true + $~.string.should.frozen? end end diff --git a/spec/ruby/core/math/tan_spec.rb b/spec/ruby/core/math/tan_spec.rb index c7b188cd810670..67307f1e6e3be7 100644 --- a/spec/ruby/core/math/tan_spec.rb +++ b/spec/ruby/core/math/tan_spec.rb @@ -14,8 +14,8 @@ end it "returns NaN if called with +-Infinity" do - Math.tan(infinity_value).nan?.should == true - Math.tan(-infinity_value).nan?.should == true + Math.tan(infinity_value).should.nan? + Math.tan(-infinity_value).should.nan? end it "raises a TypeError if the argument cannot be coerced with Float()" do diff --git a/spec/ruby/core/method/compose_spec.rb b/spec/ruby/core/method/compose_spec.rb index 2cf5b21670fa25..0e2a0eeea2315b 100644 --- a/spec/ruby/core/method/compose_spec.rb +++ b/spec/ruby/core/method/compose_spec.rb @@ -39,8 +39,8 @@ def double.call(n); n * 2; end double = proc { |x| x + x } (pow_2 << double).is_a?(Proc).should == true - ruby_version_is(''...'2.8') { (pow_2 << double).lambda?.should == true } - ruby_version_is('2.8') { (pow_2 << double).lambda?.should == false } + ruby_version_is(''...'2.8') { (pow_2 << double).should.lambda? } + ruby_version_is('2.8') { (pow_2 << double).should_not.lambda? } end it "may accept multiple arguments" do @@ -88,7 +88,7 @@ def double.call(n); n * 2; end double = proc { |x| x + x } (pow_2 >> double).is_a?(Proc).should == true - (pow_2 >> double).lambda?.should == true + (pow_2 >> double).should.lambda? end it "may accept multiple arguments" do diff --git a/spec/ruby/core/module/included_spec.rb b/spec/ruby/core/module/included_spec.rb index f8dbad1d31c6b9..2fdd4325f2ddd7 100644 --- a/spec/ruby/core/module/included_spec.rb +++ b/spec/ruby/core/module/included_spec.rb @@ -39,6 +39,6 @@ def test it "works with super using a singleton class" do ModuleSpecs::SingletonOnModuleCase::Bar.include ModuleSpecs::SingletonOnModuleCase::Foo - ModuleSpecs::SingletonOnModuleCase::Bar.included_called?.should == true + ModuleSpecs::SingletonOnModuleCase::Bar.should.included_called? end end diff --git a/spec/ruby/core/module/name_spec.rb b/spec/ruby/core/module/name_spec.rb index 9a4730313fe961..ae8037555bb348 100644 --- a/spec/ruby/core/module/name_spec.rb +++ b/spec/ruby/core/module/name_spec.rb @@ -122,7 +122,7 @@ module ModuleSpecs::Anonymous ruby_version_is "2.7" do it "returns a frozen String" do - ModuleSpecs.name.frozen?.should == true + ModuleSpecs.name.should.frozen? end it "always returns the same String for a given Module" do diff --git a/spec/ruby/core/module/singleton_class_spec.rb b/spec/ruby/core/module/singleton_class_spec.rb index b9f78eeb21cdca..052755b73b3d24 100644 --- a/spec/ruby/core/module/singleton_class_spec.rb +++ b/spec/ruby/core/module/singleton_class_spec.rb @@ -3,25 +3,25 @@ describe "Module#singleton_class?" do it "returns true for singleton classes" do xs = self.singleton_class - xs.singleton_class?.should == true + xs.should.singleton_class? end it "returns false for other classes" do c = Class.new - c.singleton_class?.should == false + c.should_not.singleton_class? end describe "with singleton values" do it "returns false for nil's singleton class" do - NilClass.singleton_class?.should == false + NilClass.should_not.singleton_class? end it "returns false for true's singleton class" do - TrueClass.singleton_class?.should == false + TrueClass.should_not.singleton_class? end it "returns false for false's singleton class" do - FalseClass.singleton_class?.should == false + FalseClass.should_not.singleton_class? end end end diff --git a/spec/ruby/core/module/using_spec.rb b/spec/ruby/core/module/using_spec.rb index 533d87d0809fa2..4781b99bb7b483 100644 --- a/spec/ruby/core/module/using_spec.rb +++ b/spec/ruby/core/module/using_spec.rb @@ -243,6 +243,96 @@ def self.call_foo(c) mod.call_foo(c).should == "foo from refinement" end + it "is active for module defined via Module.new {}" do + refinement = Module.new do + refine Integer do + def foo; "foo from refinement"; end + end + end + + result = nil + + Module.new do + using refinement + + Module.new do + result = 1.foo + end + end + + result.should == "foo from refinement" + end + + it "is active for class defined via Class.new {}" do + refinement = Module.new do + refine Integer do + def foo; "foo from refinement"; end + end + end + + result = nil + + Module.new do + using refinement + + Class.new do + result = 1.foo + end + end + + result.should == "foo from refinement" + end + + it "is active for block called via instance_exec" do + refinement = Module.new do + refine Integer do + def foo; "foo from refinement"; end + end + end + + c = Class.new do + using refinement + + def abc + block = -> { + 1.foo + } + + self.instance_exec(&block) + end + end + + c.new.abc.should == "foo from refinement" + end + + it "is active for block called via instance_eval" do + refinement = Module.new do + refine String do + def foo; "foo from refinement"; end + end + end + + c = Class.new do + using refinement + + def initialize + @a = "1703" + + @a.instance_eval do + def abc + "#{self}: #{self.foo}" + end + end + end + + def abc + @a.abc + end + end + + c.new.abc.should == "1703: foo from refinement" + end + it "is not active if `using` call is not evaluated" do result = nil diff --git a/spec/ruby/core/nil/nil_spec.rb b/spec/ruby/core/nil/nil_spec.rb index 47db0c5cf0b2a0..2cf97621c6ce15 100644 --- a/spec/ruby/core/nil/nil_spec.rb +++ b/spec/ruby/core/nil/nil_spec.rb @@ -2,6 +2,6 @@ describe "NilClass#nil?" do it "returns true" do - nil.nil?.should == true + nil.should.nil? end end diff --git a/spec/ruby/core/nil/to_s_spec.rb b/spec/ruby/core/nil/to_s_spec.rb index 4b61f589f7c4e0..283d26477a3119 100644 --- a/spec/ruby/core/nil/to_s_spec.rb +++ b/spec/ruby/core/nil/to_s_spec.rb @@ -7,7 +7,7 @@ ruby_version_is "2.7" do it "returns a frozen string" do - nil.to_s.frozen?.should == true + nil.to_s.should.frozen? end it "always returns the same string" do diff --git a/spec/ruby/core/numeric/integer_spec.rb b/spec/ruby/core/numeric/integer_spec.rb index 5d4bf003609bcf..adbac4d7aac1ff 100644 --- a/spec/ruby/core/numeric/integer_spec.rb +++ b/spec/ruby/core/numeric/integer_spec.rb @@ -3,6 +3,6 @@ describe "Numeric#integer?" do it "returns false" do - NumericSpecs::Subclass.new.integer?.should == false + NumericSpecs::Subclass.new.should_not.integer? end end diff --git a/spec/ruby/core/numeric/negative_spec.rb b/spec/ruby/core/numeric/negative_spec.rb index da464a90949a16..9c6f95fd873f55 100644 --- a/spec/ruby/core/numeric/negative_spec.rb +++ b/spec/ruby/core/numeric/negative_spec.rb @@ -31,11 +31,11 @@ it "returns true if self is less than 0" do @obj.should_receive(:<).with(0).and_return(true) - @obj.negative?.should == true + @obj.should.negative? end it "returns false if self is greater than 0" do @obj.should_receive(:<).with(0).and_return(false) - @obj.negative?.should == false + @obj.should_not.negative? end end diff --git a/spec/ruby/core/numeric/positive_spec.rb b/spec/ruby/core/numeric/positive_spec.rb index 8f98fbfa26a141..3b831b4d3417b2 100644 --- a/spec/ruby/core/numeric/positive_spec.rb +++ b/spec/ruby/core/numeric/positive_spec.rb @@ -31,11 +31,11 @@ it "returns true if self is greater than 0" do @obj.should_receive(:>).with(0).and_return(true) - @obj.positive?.should == true + @obj.should.positive? end it "returns false if self is less than 0" do @obj.should_receive(:>).with(0).and_return(false) - @obj.positive?.should == false + @obj.should_not.positive? end end diff --git a/spec/ruby/core/numeric/real_spec.rb b/spec/ruby/core/numeric/real_spec.rb index caa8dcec6de121..2d2499bcce5193 100644 --- a/spec/ruby/core/numeric/real_spec.rb +++ b/spec/ruby/core/numeric/real_spec.rb @@ -32,6 +32,6 @@ describe "Numeric#real?" do it "returns true" do - NumericSpecs::Subclass.new.real?.should == true + NumericSpecs::Subclass.new.should.real? end end diff --git a/spec/ruby/core/numeric/zero_spec.rb b/spec/ruby/core/numeric/zero_spec.rb index 9de71d1dc973b4..0fb7619bcdc3d8 100644 --- a/spec/ruby/core/numeric/zero_spec.rb +++ b/spec/ruby/core/numeric/zero_spec.rb @@ -8,11 +8,11 @@ it "returns true if self is 0" do @obj.should_receive(:==).with(0).and_return(true) - @obj.zero?.should == true + @obj.should.zero? end it "returns false if self is not 0" do @obj.should_receive(:==).with(0).and_return(false) - @obj.zero?.should == false + @obj.should_not.zero? end end diff --git a/spec/ruby/core/objectspace/weakmap/each_key_spec.rb b/spec/ruby/core/objectspace/weakmap/each_key_spec.rb new file mode 100644 index 00000000000000..df971deeb9ce79 --- /dev/null +++ b/spec/ruby/core/objectspace/weakmap/each_key_spec.rb @@ -0,0 +1,11 @@ +require_relative '../../../spec_helper' +require_relative 'shared/members' +require_relative 'shared/each' + +describe "ObjectSpace::WeakMap#each_key" do + it_behaves_like :weakmap_members, -> map { a = []; map.each_key{ |k| a << k }; a }, %w[A B] +end + +describe "ObjectSpace::WeakMap#each_key" do + it_behaves_like :weakmap_each, :each_key +end diff --git a/spec/ruby/core/objectspace/weakmap/each_pair_spec.rb b/spec/ruby/core/objectspace/weakmap/each_pair_spec.rb new file mode 100644 index 00000000000000..ea29edbd2fee92 --- /dev/null +++ b/spec/ruby/core/objectspace/weakmap/each_pair_spec.rb @@ -0,0 +1,11 @@ +require_relative '../../../spec_helper' +require_relative 'shared/members' +require_relative 'shared/each' + +describe "ObjectSpace::WeakMap#each_pair" do + it_behaves_like :weakmap_members, -> map { a = []; map.each_pair{ |k,v| a << "#{k}#{v}" }; a }, %w[Ax By] +end + +describe "ObjectSpace::WeakMap#each_key" do + it_behaves_like :weakmap_each, :each_pair +end diff --git a/spec/ruby/core/objectspace/weakmap/each_spec.rb b/spec/ruby/core/objectspace/weakmap/each_spec.rb new file mode 100644 index 00000000000000..46fcb66a6f5b42 --- /dev/null +++ b/spec/ruby/core/objectspace/weakmap/each_spec.rb @@ -0,0 +1,11 @@ +require_relative '../../../spec_helper' +require_relative 'shared/members' +require_relative 'shared/each' + +describe "ObjectSpace::WeakMap#each" do + it_behaves_like :weakmap_members, -> map { a = []; map.each{ |k,v| a << "#{k}#{v}" }; a }, %w[Ax By] +end + +describe "ObjectSpace::WeakMap#each_key" do + it_behaves_like :weakmap_each, :each +end diff --git a/spec/ruby/core/objectspace/weakmap/each_value_spec.rb b/spec/ruby/core/objectspace/weakmap/each_value_spec.rb new file mode 100644 index 00000000000000..65a1a7f6fe6283 --- /dev/null +++ b/spec/ruby/core/objectspace/weakmap/each_value_spec.rb @@ -0,0 +1,11 @@ +require_relative '../../../spec_helper' +require_relative 'shared/members' +require_relative 'shared/each' + +describe "ObjectSpace::WeakMap#each_value" do + it_behaves_like :weakmap_members, -> map { a = []; map.each_value{ |k| a << k }; a }, %w[x y] +end + +describe "ObjectSpace::WeakMap#each_key" do + it_behaves_like :weakmap_each, :each_value +end diff --git a/spec/ruby/core/objectspace/weakmap/element_reference_spec.rb b/spec/ruby/core/objectspace/weakmap/element_reference_spec.rb new file mode 100644 index 00000000000000..cb3174cbfa589a --- /dev/null +++ b/spec/ruby/core/objectspace/weakmap/element_reference_spec.rb @@ -0,0 +1,24 @@ +require_relative '../../../spec_helper' + +describe "ObjectSpace::WeakMap#[]" do + it "is faithful to the map's content" do + map = ObjectSpace::WeakMap.new + key1, key2 = %w[a b].map(&:upcase) + ref1, ref2 = %w[x y] + map[key1] = ref1 + map[key1].should == ref1 + map[key1] = ref1 + map[key1].should == ref1 + map[key2] = ref2 + map[key1].should == ref1 + map[key2].should == ref2 + end + + it "matches using identity semantics" do + map = ObjectSpace::WeakMap.new + key1, key2 = %w[a a].map(&:upcase) + ref = "x" + map[key1] = ref + map[key2].should == nil + end +end diff --git a/spec/ruby/core/objectspace/weakmap/element_set_spec.rb b/spec/ruby/core/objectspace/weakmap/element_set_spec.rb new file mode 100644 index 00000000000000..2b536501482f85 --- /dev/null +++ b/spec/ruby/core/objectspace/weakmap/element_set_spec.rb @@ -0,0 +1,61 @@ +require_relative '../../../spec_helper' + +describe "ObjectSpace::WeakMap#[]=" do + def should_accept(map, key, value) + (map[key] = value).should == value + map.should.key?(key) + map[key].should == value + end + + it "is correct" do + map = ObjectSpace::WeakMap.new + key1, key2 = %w[a b].map(&:upcase) + ref1, ref2 = %w[x y] + should_accept(map, key1, ref1) + should_accept(map, key1, ref1) + should_accept(map, key2, ref2) + map[key1].should == ref1 + end + + ruby_version_is ""..."2.7" do + it "does not accept primitive or frozen keys or values" do + map = ObjectSpace::WeakMap.new + x = Object.new + -> { map[true] = x }.should raise_error(ArgumentError) + -> { map[false] = x }.should raise_error(ArgumentError) + -> { map[nil] = x }.should raise_error(ArgumentError) + -> { map[42] = x }.should raise_error(ArgumentError) + -> { map[:foo] = x }.should raise_error(ArgumentError) + -> { map[x] = true }.should raise_error(ArgumentError) + -> { map[x] = false }.should raise_error(ArgumentError) + -> { map[x] = nil }.should raise_error(ArgumentError) + -> { map[x] = 42 }.should raise_error(ArgumentError) + -> { map[x] = :foo }.should raise_error(ArgumentError) + + y = Object.new.freeze + -> { map[x] = y}.should raise_error(FrozenError) + -> { map[y] = x}.should raise_error(FrozenError) + end + end + + ruby_version_is "2.7" do + it "accepts primitive or frozen keys or values" do + map = ObjectSpace::WeakMap.new + x = Object.new + should_accept(map, true, x) + should_accept(map, false, x) + should_accept(map, nil, x) + should_accept(map, 42, x) + should_accept(map, :foo, x) + + should_accept(map, x, true) + should_accept(map, x, false) + should_accept(map, x, 42) + should_accept(map, x, :foo) + + y = Object.new.freeze + should_accept(map, x, y) + should_accept(map, y, x) + end + end +end diff --git a/spec/ruby/core/objectspace/weakmap/include_spec.rb b/spec/ruby/core/objectspace/weakmap/include_spec.rb new file mode 100644 index 00000000000000..54ca6b303080ad --- /dev/null +++ b/spec/ruby/core/objectspace/weakmap/include_spec.rb @@ -0,0 +1,6 @@ +require_relative '../../../spec_helper' +require_relative 'shared/include' + +describe "ObjectSpace::WeakMap#include?" do + it_behaves_like :weakmap_include?, :include? +end diff --git a/spec/ruby/core/objectspace/weakmap/inspect_spec.rb b/spec/ruby/core/objectspace/weakmap/inspect_spec.rb new file mode 100644 index 00000000000000..f064f6e3eaa637 --- /dev/null +++ b/spec/ruby/core/objectspace/weakmap/inspect_spec.rb @@ -0,0 +1,25 @@ +require_relative '../../../spec_helper' + +describe "ObjectSpace::WeakMap#inspect" do + it "displays object pointers in output" do + map = ObjectSpace::WeakMap.new + # important to test with BasicObject (without Kernel) here to test edge cases + key1, key2 = [BasicObject.new, Object.new] + ref1, ref2 = [BasicObject.new, Object.new] + map.inspect.should =~ /\A\#\z/ + map[key1] = ref1 + map.inspect.should =~ /\A\# => \#>\z/ + map[key1] = ref1 + map.inspect.should =~ /\A\# => \#>\z/ + map[key2] = ref2 + + regexp1 = /\A\# => \#, \# => \#>\z/ + regexp2 = /\A\# => \#, \# => \#>\z/ + str = map.inspect + if str =~ regexp1 + str.should =~ regexp1 + else + str.should =~ regexp2 + end + end +end diff --git a/spec/ruby/core/objectspace/weakmap/key_spec.rb b/spec/ruby/core/objectspace/weakmap/key_spec.rb new file mode 100644 index 00000000000000..999685ff951cab --- /dev/null +++ b/spec/ruby/core/objectspace/weakmap/key_spec.rb @@ -0,0 +1,6 @@ +require_relative '../../../spec_helper' +require_relative 'shared/include' + +describe "ObjectSpace::WeakMap#key?" do + it_behaves_like :weakmap_include?, :key? +end diff --git a/spec/ruby/core/objectspace/weakmap/keys_spec.rb b/spec/ruby/core/objectspace/weakmap/keys_spec.rb new file mode 100644 index 00000000000000..7b1494bdd7c68a --- /dev/null +++ b/spec/ruby/core/objectspace/weakmap/keys_spec.rb @@ -0,0 +1,6 @@ +require_relative '../../../spec_helper' +require_relative 'shared/members' + +describe "ObjectSpace::WeakMap#keys" do + it_behaves_like :weakmap_members, -> map { map.keys }, %w[A B] +end diff --git a/spec/ruby/core/objectspace/weakmap/length_spec.rb b/spec/ruby/core/objectspace/weakmap/length_spec.rb new file mode 100644 index 00000000000000..3a935648b14306 --- /dev/null +++ b/spec/ruby/core/objectspace/weakmap/length_spec.rb @@ -0,0 +1,6 @@ +require_relative '../../../spec_helper' +require_relative 'shared/size' + +describe "ObjectSpace::WeakMap#length" do + it_behaves_like :weakmap_size, :length +end diff --git a/spec/ruby/core/objectspace/weakmap/member_spec.rb b/spec/ruby/core/objectspace/weakmap/member_spec.rb new file mode 100644 index 00000000000000..cefb190ce7cfd7 --- /dev/null +++ b/spec/ruby/core/objectspace/weakmap/member_spec.rb @@ -0,0 +1,6 @@ +require_relative '../../../spec_helper' +require_relative 'shared/include' + +describe "ObjectSpace::WeakMap#member?" do + it_behaves_like :weakmap_include?, :member? +end diff --git a/spec/ruby/core/objectspace/weakmap/shared/each.rb b/spec/ruby/core/objectspace/weakmap/shared/each.rb new file mode 100644 index 00000000000000..3d43a19347971a --- /dev/null +++ b/spec/ruby/core/objectspace/weakmap/shared/each.rb @@ -0,0 +1,10 @@ +describe :weakmap_each, shared: true do + it "must take a block, except when empty" do + map = ObjectSpace::WeakMap.new + key = "a".upcase + ref = "x" + map.send(@method).should == map + map[key] = ref + -> { map.send(@method) }.should raise_error(LocalJumpError) + end +end diff --git a/spec/ruby/core/objectspace/weakmap/shared/include.rb b/spec/ruby/core/objectspace/weakmap/shared/include.rb new file mode 100644 index 00000000000000..f9c174b6d14692 --- /dev/null +++ b/spec/ruby/core/objectspace/weakmap/shared/include.rb @@ -0,0 +1,34 @@ +describe :weakmap_include?, shared: true do + it "recognizes keys in use" do + map = ObjectSpace::WeakMap.new + key1, key2 = %w[a b].map(&:upcase) + ref1, ref2 = %w[x y] + + map[key1] = ref1 + map.send(@method, key1).should == true + map[key1] = ref1 + map.send(@method, key1).should == true + map[key2] = ref2 + map.send(@method, key2).should == true + end + + it "matches using identity semantics" do + map = ObjectSpace::WeakMap.new + key1, key2 = %w[a a].map(&:upcase) + ref = "x" + map[key1] = ref + map.send(@method, key2).should == false + end + + ruby_version_is "2.7" do + ruby_bug "#16826", "2.7.0"..."2.7.2" do + it "reports true if the pair exists and the value is nil" do + map = ObjectSpace::WeakMap.new + key = Object.new + map[key] = nil + map.size.should == 1 + map.send(@method, key).should == true + end + end + end +end diff --git a/spec/ruby/core/objectspace/weakmap/shared/members.rb b/spec/ruby/core/objectspace/weakmap/shared/members.rb new file mode 100644 index 00000000000000..57226c8d7a0b6c --- /dev/null +++ b/spec/ruby/core/objectspace/weakmap/shared/members.rb @@ -0,0 +1,14 @@ +describe :weakmap_members, shared: true do + it "is correct" do + map = ObjectSpace::WeakMap.new + key1, key2 = %w[a b].map(&:upcase) + ref1, ref2 = %w[x y] + @method.call(map).should == [] + map[key1] = ref1 + @method.call(map).should == @object[0..0] + map[key1] = ref1 + @method.call(map).should == @object[0..0] + map[key2] = ref2 + @method.call(map).sort.should == @object + end +end diff --git a/spec/ruby/core/objectspace/weakmap/shared/size.rb b/spec/ruby/core/objectspace/weakmap/shared/size.rb new file mode 100644 index 00000000000000..1064f99d1b987b --- /dev/null +++ b/spec/ruby/core/objectspace/weakmap/shared/size.rb @@ -0,0 +1,14 @@ +describe :weakmap_size, shared: true do + it "is correct" do + map = ObjectSpace::WeakMap.new + key1, key2 = %w[a b].map(&:upcase) + ref1, ref2 = %w[x y] + map.send(@method).should == 0 + map[key1] = ref1 + map.send(@method).should == 1 + map[key1] = ref1 + map.send(@method).should == 1 + map[key2] = ref2 + map.send(@method).should == 2 + end +end diff --git a/spec/ruby/core/objectspace/weakmap/size_spec.rb b/spec/ruby/core/objectspace/weakmap/size_spec.rb new file mode 100644 index 00000000000000..1446abaa24d661 --- /dev/null +++ b/spec/ruby/core/objectspace/weakmap/size_spec.rb @@ -0,0 +1,6 @@ +require_relative '../../../spec_helper' +require_relative 'shared/size' + +describe "ObjectSpace::WeakMap#size" do + it_behaves_like :weakmap_size, :size +end diff --git a/spec/ruby/core/objectspace/weakmap/values_spec.rb b/spec/ruby/core/objectspace/weakmap/values_spec.rb new file mode 100644 index 00000000000000..6f6f90d0ba3509 --- /dev/null +++ b/spec/ruby/core/objectspace/weakmap/values_spec.rb @@ -0,0 +1,6 @@ +require_relative '../../../spec_helper' +require_relative 'shared/members' + +describe "ObjectSpace::WeakMap#values" do + it_behaves_like :weakmap_members, -> map { map.values }, %w[x y] +end diff --git a/spec/ruby/core/objectspace/weakmap_spec.rb b/spec/ruby/core/objectspace/weakmap_spec.rb new file mode 100644 index 00000000000000..2f3f93c291fced --- /dev/null +++ b/spec/ruby/core/objectspace/weakmap_spec.rb @@ -0,0 +1,12 @@ +require_relative '../../spec_helper' + +describe "ObjectSpace::WeakMap" do + + # Note that we can't really spec the most important aspect of this class: that entries get removed when the values + # become unreachable. This is because Ruby does not offer a way to reliable invoke GC (GC.start is not enough, neither + # on MRI or on alternative implementations). + + it "includes Enumerable" do + ObjectSpace::WeakMap.include?(Enumerable).should == true + end +end diff --git a/spec/ruby/core/proc/compose_spec.rb b/spec/ruby/core/proc/compose_spec.rb index ef9c125ae9df43..efdbdeacf44ef5 100644 --- a/spec/ruby/core/proc/compose_spec.rb +++ b/spec/ruby/core/proc/compose_spec.rb @@ -35,7 +35,7 @@ def double.call(n); n * 2; end g = proc { |x| x + x } (f << g).is_a?(Proc).should == true - (f << g).lambda?.should == false + (f << g).should_not.lambda? end ruby_version_is(''...'2.8') do @@ -44,7 +44,7 @@ def double.call(n); n * 2; end g = -> x { x + x } (f << g).is_a?(Proc).should == true - (f << g).lambda?.should == false + (f << g).should_not.lambda? end it "is a lambda when self is lambda" do @@ -52,7 +52,7 @@ def double.call(n); n * 2; end g = proc { |x| x + x } (f << g).is_a?(Proc).should == true - (f << g).lambda?.should == true + (f << g).should.lambda? end end @@ -63,8 +63,8 @@ def double.call(n); n * 2; end lambda_proc = -> x { x } (f << g).is_a?(Proc).should == true - (f << g).lambda?.should == false - (f << lambda_proc).lambda?.should == true + (f << g).should_not.lambda? + (f << lambda_proc).should.lambda? end end @@ -118,7 +118,7 @@ def double.call(n); n * 2; end g = proc { |x| x + x } (f >> g).is_a?(Proc).should == true - (f >> g).lambda?.should == false + (f >> g).should_not.lambda? end it "is a Proc when other is lambda" do @@ -126,7 +126,7 @@ def double.call(n); n * 2; end g = -> x { x + x } (f >> g).is_a?(Proc).should == true - (f >> g).lambda?.should == false + (f >> g).should_not.lambda? end it "is a lambda when self is lambda" do @@ -134,7 +134,7 @@ def double.call(n); n * 2; end g = proc { |x| x + x } (f >> g).is_a?(Proc).should == true - (f >> g).lambda?.should == true + (f >> g).should.lambda? end it "may accept multiple arguments" do diff --git a/spec/ruby/core/process/clock_getres_spec.rb b/spec/ruby/core/process/clock_getres_spec.rb index 90f775e764e1da..85aa2b25f16b68 100644 --- a/spec/ruby/core/process/clock_getres_spec.rb +++ b/spec/ruby/core/process/clock_getres_spec.rb @@ -19,15 +19,15 @@ # These are observed - platform_is_not :solaris, :aix, :openbsd do - it "with Process::CLOCK_REALTIME reports at least 1 microsecond" do - Process.clock_getres(Process::CLOCK_REALTIME, :nanosecond).should <= 1_000 + platform_is :linux, :darwin, :windows do + it "with Process::CLOCK_REALTIME reports at least 10 millisecond" do + Process.clock_getres(Process::CLOCK_REALTIME, :nanosecond).should <= 10_000_000 end end - platform_is_not :aix, :openbsd do - it "with Process::CLOCK_MONOTONIC reports at least 1 microsecond" do - Process.clock_getres(Process::CLOCK_MONOTONIC, :nanosecond).should <= 1_000 + platform_is :linux, :darwin, :windows do + it "with Process::CLOCK_MONOTONIC reports at least 10 millisecond" do + Process.clock_getres(Process::CLOCK_MONOTONIC, :nanosecond).should <= 10_000_000 end end end diff --git a/spec/ruby/core/range/dup_spec.rb b/spec/ruby/core/range/dup_spec.rb index d1c029c6b73cb4..6c9d0c954a177e 100644 --- a/spec/ruby/core/range/dup_spec.rb +++ b/spec/ruby/core/range/dup_spec.rb @@ -5,11 +5,11 @@ copy = (1..3).dup copy.begin.should == 1 copy.end.should == 3 - copy.exclude_end?.should == false + copy.should_not.exclude_end? copy = ("a"..."z").dup copy.begin.should == "a" copy.end.should == "z" - copy.exclude_end?.should == true + copy.should.exclude_end? end end diff --git a/spec/ruby/core/range/exclude_end_spec.rb b/spec/ruby/core/range/exclude_end_spec.rb index a209603d18eb50..c4006fea78afaf 100644 --- a/spec/ruby/core/range/exclude_end_spec.rb +++ b/spec/ruby/core/range/exclude_end_spec.rb @@ -2,18 +2,18 @@ describe "Range#exclude_end?" do it "returns false if the range does not exclude the end value" do - (-2..2).exclude_end?.should == false - ('A'..'B').exclude_end?.should == false - (0.5..2.4).exclude_end?.should == false - (0xfffd..0xffff).exclude_end?.should == false - Range.new(0, 1).exclude_end?.should == false + (-2..2).should_not.exclude_end? + ('A'..'B').should_not.exclude_end? + (0.5..2.4).should_not.exclude_end? + (0xfffd..0xffff).should_not.exclude_end? + Range.new(0, 1).should_not.exclude_end? end it "returns true if the range excludes the end value" do - (0...5).exclude_end?.should == true - ('A'...'B').exclude_end?.should == true - (0.5...2.4).exclude_end?.should == true - (0xfffd...0xffff).exclude_end?.should == true - Range.new(0, 1, true).exclude_end?.should == true + (0...5).should.exclude_end? + ('A'...'B').should.exclude_end? + (0.5...2.4).should.exclude_end? + (0xfffd...0xffff).should.exclude_end? + Range.new(0, 1, true).should.exclude_end? end end diff --git a/spec/ruby/core/regexp/casefold_spec.rb b/spec/ruby/core/regexp/casefold_spec.rb index d84a2d63c9027b..d36467a9897ca4 100644 --- a/spec/ruby/core/regexp/casefold_spec.rb +++ b/spec/ruby/core/regexp/casefold_spec.rb @@ -2,7 +2,7 @@ describe "Regexp#casefold?" do it "returns the value of the case-insensitive flag" do - /abc/i.casefold?.should == true - /xyz/.casefold?.should == false + /abc/i.should.casefold? + /xyz/.should_not.casefold? end end diff --git a/spec/ruby/core/signal/trap_spec.rb b/spec/ruby/core/signal/trap_spec.rb index 91ce1f1348496e..831a5ee23e44fc 100644 --- a/spec/ruby/core/signal/trap_spec.rb +++ b/spec/ruby/core/signal/trap_spec.rb @@ -155,7 +155,7 @@ out = ruby_exe(code) status = $? out.should == "nil\n" - status.signaled?.should == true + status.should.signaled? status.termsig.should be_kind_of(Integer) Signal.signame(status.termsig).should == "PIPE" end diff --git a/spec/ruby/core/string/capitalize_spec.rb b/spec/ruby/core/string/capitalize_spec.rb index 66d3b75f48d3cd..e6cf365ac32f39 100644 --- a/spec/ruby/core/string/capitalize_spec.rb +++ b/spec/ruby/core/string/capitalize_spec.rb @@ -14,8 +14,8 @@ ruby_version_is ''...'2.7' do it "taints resulting string when self is tainted" do - "".taint.capitalize.tainted?.should == true - "hello".taint.capitalize.tainted?.should == true + "".taint.capitalize.should.tainted? + "hello".taint.capitalize.should.tainted? end end diff --git a/spec/ruby/core/string/center_spec.rb b/spec/ruby/core/string/center_spec.rb index 0284fc28dc48e8..8a4be0a81e538e 100644 --- a/spec/ruby/core/string/center_spec.rb +++ b/spec/ruby/core/string/center_spec.rb @@ -49,11 +49,11 @@ ruby_version_is ''...'2.7' do it "taints result when self or padstr is tainted" do - "x".taint.center(4).tainted?.should == true - "x".taint.center(0).tainted?.should == true - "".taint.center(0).tainted?.should == true - "x".taint.center(4, "*").tainted?.should == true - "x".center(4, "*".taint).tainted?.should == true + "x".taint.center(4).should.tainted? + "x".taint.center(0).should.tainted? + "".taint.center(0).should.tainted? + "x".taint.center(4, "*").should.tainted? + "x".center(4, "*".taint).should.tainted? end end diff --git a/spec/ruby/core/string/chop_spec.rb b/spec/ruby/core/string/chop_spec.rb index e9cd8f51d24436..582d3c58c5ce50 100644 --- a/spec/ruby/core/string/chop_spec.rb +++ b/spec/ruby/core/string/chop_spec.rb @@ -51,13 +51,13 @@ ruby_version_is ''...'2.7' do it "taints result when self is tainted" do - "hello".taint.chop.tainted?.should == true - "".taint.chop.tainted?.should == true + "hello".taint.chop.should.tainted? + "".taint.chop.should.tainted? end it "untrusts result when self is untrusted" do - "hello".untrust.chop.untrusted?.should == true - "".untrust.chop.untrusted?.should == true + "hello".untrust.chop.should.untrusted? + "".untrust.chop.should.untrusted? end end diff --git a/spec/ruby/core/string/crypt_spec.rb b/spec/ruby/core/string/crypt_spec.rb index 6a9a4ae2357b82..b947702492899e 100644 --- a/spec/ruby/core/string/crypt_spec.rb +++ b/spec/ruby/core/string/crypt_spec.rb @@ -33,10 +33,10 @@ tainted_salt.taint tainted_str.taint - "mypassword".crypt("$2a$04$0WVaz0pV3jzfZ5G5tpmHWu").tainted?.should == false - tainted_str.crypt("$2a$04$0WVaz0pV3jzfZ5G5tpmHWu").tainted?.should == true - "mypassword".crypt(tainted_salt).tainted?.should == true - tainted_str.crypt(tainted_salt).tainted?.should == true + "mypassword".crypt("$2a$04$0WVaz0pV3jzfZ5G5tpmHWu").should_not.tainted? + tainted_str.crypt("$2a$04$0WVaz0pV3jzfZ5G5tpmHWu").should.tainted? + "mypassword".crypt(tainted_salt).should.tainted? + tainted_str.crypt(tainted_salt).should.tainted? end end @@ -93,10 +93,10 @@ tainted_salt.taint tainted_str.taint - "hello".crypt("aa").tainted?.should == false - tainted_str.crypt("aa").tainted?.should == true - "hello".crypt(tainted_salt).tainted?.should == true - tainted_str.crypt(tainted_salt).tainted?.should == true + "hello".crypt("aa").should_not.tainted? + tainted_str.crypt("aa").should.tainted? + "hello".crypt(tainted_salt).should.tainted? + tainted_str.crypt(tainted_salt).should.tainted? end end diff --git a/spec/ruby/core/string/delete_prefix_spec.rb b/spec/ruby/core/string/delete_prefix_spec.rb index fb00d808b24987..bd5b56a312bff4 100644 --- a/spec/ruby/core/string/delete_prefix_spec.rb +++ b/spec/ruby/core/string/delete_prefix_spec.rb @@ -23,8 +23,8 @@ ruby_version_is ''...'2.7' do it "taints resulting strings when other is tainted" do - 'hello'.taint.delete_prefix('hell').tainted?.should == true - 'hello'.taint.delete_prefix('').tainted?.should == true + 'hello'.taint.delete_prefix('hell').should.tainted? + 'hello'.taint.delete_prefix('').should.tainted? end end diff --git a/spec/ruby/core/string/delete_spec.rb b/spec/ruby/core/string/delete_spec.rb index ded63f1719dff6..b6e54f8386b619 100644 --- a/spec/ruby/core/string/delete_spec.rb +++ b/spec/ruby/core/string/delete_spec.rb @@ -70,10 +70,10 @@ ruby_version_is ''...'2.7' do it "taints result when self is tainted" do - "hello".taint.delete("e").tainted?.should == true - "hello".taint.delete("a-z").tainted?.should == true + "hello".taint.delete("e").should.tainted? + "hello".taint.delete("a-z").should.tainted? - "hello".delete("e".taint).tainted?.should == false + "hello".delete("e".taint).should_not.tainted? end end diff --git a/spec/ruby/core/string/delete_suffix_spec.rb b/spec/ruby/core/string/delete_suffix_spec.rb index d5b6880193608f..dbb5f9df9e5d94 100644 --- a/spec/ruby/core/string/delete_suffix_spec.rb +++ b/spec/ruby/core/string/delete_suffix_spec.rb @@ -23,8 +23,8 @@ ruby_version_is ''...'2.7' do it "taints resulting strings when other is tainted" do - 'hello'.taint.delete_suffix('ello').tainted?.should == true - 'hello'.taint.delete_suffix('').tainted?.should == true + 'hello'.taint.delete_suffix('ello').should.tainted? + 'hello'.taint.delete_suffix('').should.tainted? end end diff --git a/spec/ruby/core/string/downcase_spec.rb b/spec/ruby/core/string/downcase_spec.rb index 32e04e8a2c8003..8c840bdcc4e17e 100644 --- a/spec/ruby/core/string/downcase_spec.rb +++ b/spec/ruby/core/string/downcase_spec.rb @@ -70,9 +70,9 @@ ruby_version_is ''...'2.7' do it "taints result when self is tainted" do - "".taint.downcase.tainted?.should == true - "x".taint.downcase.tainted?.should == true - "X".taint.downcase.tainted?.should == true + "".taint.downcase.should.tainted? + "x".taint.downcase.should.tainted? + "X".taint.downcase.should.tainted? end end diff --git a/spec/ruby/core/string/dump_spec.rb b/spec/ruby/core/string/dump_spec.rb index 260ee37adbf02e..ebdd0167aa5db5 100644 --- a/spec/ruby/core/string/dump_spec.rb +++ b/spec/ruby/core/string/dump_spec.rb @@ -5,18 +5,18 @@ describe "String#dump" do ruby_version_is ''...'2.7' do it "taints the result if self is tainted" do - "foo".taint.dump.tainted?.should == true - "foo\n".taint.dump.tainted?.should == true + "foo".taint.dump.should.tainted? + "foo\n".taint.dump.should.tainted? end it "untrusts the result if self is untrusted" do - "foo".untrust.dump.untrusted?.should == true - "foo\n".untrust.dump.untrusted?.should == true + "foo".untrust.dump.should.untrusted? + "foo\n".untrust.dump.should.untrusted? end end it "does not take into account if a string is frozen" do - "foo".freeze.dump.frozen?.should == false + "foo".freeze.dump.should_not.frozen? end it "returns a subclass instance" do diff --git a/spec/ruby/core/string/element_set_spec.rb b/spec/ruby/core/string/element_set_spec.rb index e375b4570ebc8b..641d46bc911e06 100644 --- a/spec/ruby/core/string/element_set_spec.rb +++ b/spec/ruby/core/string/element_set_spec.rb @@ -18,11 +18,11 @@ it "taints self if other_str is tainted" do a = "hello" a[0] = "".taint - a.tainted?.should == true + a.should.tainted? a = "hello" a[0] = "x".taint - a.tainted?.should == true + a.should.tainted? end end @@ -491,11 +491,11 @@ it "taints self if other_str is tainted" do a = "hello" a[0, 0] = "".taint - a.tainted?.should == true + a.should.tainted? a = "hello" a[1, 4] = "x".taint - a.tainted?.should == true + a.should.tainted? end end diff --git a/spec/ruby/core/string/empty_spec.rb b/spec/ruby/core/string/empty_spec.rb index fb52070723e40b..8e53a16afc2909 100644 --- a/spec/ruby/core/string/empty_spec.rb +++ b/spec/ruby/core/string/empty_spec.rb @@ -3,10 +3,10 @@ describe "String#empty?" do it "returns true if the string has a length of zero" do - "hello".empty?.should == false - " ".empty?.should == false - "\x00".empty?.should == false - "".empty?.should == true - StringSpecs::MyString.new("").empty?.should == true + "hello".should_not.empty? + " ".should_not.empty? + "\x00".should_not.empty? + "".should.empty? + StringSpecs::MyString.new("").should.empty? end end diff --git a/spec/ruby/core/string/gsub_spec.rb b/spec/ruby/core/string/gsub_spec.rb index 8193464d48abfb..23e0ad2260fa7a 100644 --- a/spec/ruby/core/string/gsub_spec.rb +++ b/spec/ruby/core/string/gsub_spec.rb @@ -171,14 +171,14 @@ hello_t.taint; a_t.taint; empty_t.taint - hello_t.gsub(/./, a).tainted?.should == true - hello_t.gsub(/./, empty).tainted?.should == true + hello_t.gsub(/./, a).should.tainted? + hello_t.gsub(/./, empty).should.tainted? - hello.gsub(/./, a_t).tainted?.should == true - hello.gsub(/./, empty_t).tainted?.should == true - hello.gsub(//, empty_t).tainted?.should == true + hello.gsub(/./, a_t).should.tainted? + hello.gsub(/./, empty_t).should.tainted? + hello.gsub(//, empty_t).should.tainted? - hello.gsub(//.taint, "foo").tainted?.should == false + hello.gsub(//.taint, "foo").should_not.tainted? end end @@ -199,14 +199,14 @@ hello_t.untrust; a_t.untrust; empty_t.untrust - hello_t.gsub(/./, a).untrusted?.should == true - hello_t.gsub(/./, empty).untrusted?.should == true + hello_t.gsub(/./, a).should.untrusted? + hello_t.gsub(/./, empty).should.untrusted? - hello.gsub(/./, a_t).untrusted?.should == true - hello.gsub(/./, empty_t).untrusted?.should == true - hello.gsub(//, empty_t).untrusted?.should == true + hello.gsub(/./, a_t).should.untrusted? + hello.gsub(/./, empty_t).should.untrusted? + hello.gsub(//, empty_t).should.untrusted? - hello.gsub(//.untrust, "foo").untrusted?.should == false + hello.gsub(//.untrust, "foo").should_not.untrusted? end end @@ -521,14 +521,14 @@ def obj.to_s() "ok" end hello_t.untrust; a_t.untrust; empty_t.untrust - hello_t.gsub(/./) { a }.untrusted?.should == true - hello_t.gsub(/./) { empty }.untrusted?.should == true + hello_t.gsub(/./) { a }.should.untrusted? + hello_t.gsub(/./) { empty }.should.untrusted? - hello.gsub(/./) { a_t }.untrusted?.should == true - hello.gsub(/./) { empty_t }.untrusted?.should == true - hello.gsub(//) { empty_t }.untrusted?.should == true + hello.gsub(/./) { a_t }.should.untrusted? + hello.gsub(/./) { empty_t }.should.untrusted? + hello.gsub(//) { empty_t }.should.untrusted? - hello.gsub(//.untrust) { "foo" }.untrusted?.should == false + hello.gsub(//.untrust) { "foo" }.should_not.untrusted? end end @@ -594,14 +594,14 @@ def obj.to_s() "ok" end ruby_version_is ''...'2.7' do it "taints self if replacement is tainted" do a = "hello" - a.gsub!(/./.taint, "foo").tainted?.should == false - a.gsub!(/./, "foo".taint).tainted?.should == true + a.gsub!(/./.taint, "foo").should_not.tainted? + a.gsub!(/./, "foo".taint).should.tainted? end it "untrusts self if replacement is untrusted" do a = "hello" - a.gsub!(/./.untrust, "foo").untrusted?.should == false - a.gsub!(/./, "foo".untrust).untrusted?.should == true + a.gsub!(/./.untrust, "foo").should_not.untrusted? + a.gsub!(/./, "foo".untrust).should.untrusted? end end @@ -633,14 +633,14 @@ def obj.to_s() "ok" end ruby_version_is ''...'2.7' do it "taints self if block's result is tainted" do a = "hello" - a.gsub!(/./.taint) { "foo" }.tainted?.should == false - a.gsub!(/./) { "foo".taint }.tainted?.should == true + a.gsub!(/./.taint) { "foo" }.should_not.tainted? + a.gsub!(/./) { "foo".taint }.should.tainted? end it "untrusts self if block's result is untrusted" do a = "hello" - a.gsub!(/./.untrust) { "foo" }.untrusted?.should == false - a.gsub!(/./) { "foo".untrust }.untrusted?.should == true + a.gsub!(/./.untrust) { "foo" }.should_not.untrusted? + a.gsub!(/./) { "foo".untrust }.should.untrusted? end end diff --git a/spec/ruby/core/string/insert_spec.rb b/spec/ruby/core/string/insert_spec.rb index b26845419f9c12..752cbb2f376f7a 100644 --- a/spec/ruby/core/string/insert_spec.rb +++ b/spec/ruby/core/string/insert_spec.rb @@ -44,12 +44,12 @@ ruby_version_is ''...'2.7' do it "taints self if string to insert is tainted" do str = "abcd" - str.insert(0, "T".taint).tainted?.should == true + str.insert(0, "T".taint).should.tainted? str = "abcd" other = mock('T') def other.to_str() "T".taint end - str.insert(0, other).tainted?.should == true + str.insert(0, other).should.tainted? end end diff --git a/spec/ruby/core/string/inspect_spec.rb b/spec/ruby/core/string/inspect_spec.rb index e63d89ead5e647..9818796c83133f 100644 --- a/spec/ruby/core/string/inspect_spec.rb +++ b/spec/ruby/core/string/inspect_spec.rb @@ -5,13 +5,13 @@ describe "String#inspect" do ruby_version_is ''...'2.7' do it "taints the result if self is tainted" do - "foo".taint.inspect.tainted?.should == true - "foo\n".taint.inspect.tainted?.should == true + "foo".taint.inspect.should.tainted? + "foo\n".taint.inspect.should.tainted? end it "untrusts the result if self is untrusted" do - "foo".untrust.inspect.untrusted?.should == true - "foo\n".untrust.inspect.untrusted?.should == true + "foo".untrust.inspect.should.untrusted? + "foo\n".untrust.inspect.should.untrusted? end end diff --git a/spec/ruby/core/string/ljust_spec.rb b/spec/ruby/core/string/ljust_spec.rb index f377e397759907..481ef77ca85b6f 100644 --- a/spec/ruby/core/string/ljust_spec.rb +++ b/spec/ruby/core/string/ljust_spec.rb @@ -33,11 +33,11 @@ ruby_version_is ''...'2.7' do it "taints result when self or padstr is tainted" do - "x".taint.ljust(4).tainted?.should == true - "x".taint.ljust(0).tainted?.should == true - "".taint.ljust(0).tainted?.should == true - "x".taint.ljust(4, "*").tainted?.should == true - "x".ljust(4, "*".taint).tainted?.should == true + "x".taint.ljust(4).should.tainted? + "x".taint.ljust(0).should.tainted? + "".taint.ljust(0).should.tainted? + "x".taint.ljust(4, "*").should.tainted? + "x".ljust(4, "*".taint).should.tainted? end end diff --git a/spec/ruby/core/string/lstrip_spec.rb b/spec/ruby/core/string/lstrip_spec.rb index 902d660455fb42..12c7b132005774 100644 --- a/spec/ruby/core/string/lstrip_spec.rb +++ b/spec/ruby/core/string/lstrip_spec.rb @@ -16,9 +16,9 @@ ruby_version_is ''...'2.7' do it "taints the result when self is tainted" do - "".taint.lstrip.tainted?.should == true - "ok".taint.lstrip.tainted?.should == true - " ok".taint.lstrip.tainted?.should == true + "".taint.lstrip.should.tainted? + "ok".taint.lstrip.should.tainted? + " ok".taint.lstrip.should.tainted? end end end diff --git a/spec/ruby/core/string/modulo_spec.rb b/spec/ruby/core/string/modulo_spec.rb index ad4b85e3c3c641..dc11ced4e285eb 100644 --- a/spec/ruby/core/string/modulo_spec.rb +++ b/spec/ruby/core/string/modulo_spec.rb @@ -319,8 +319,8 @@ def universal.to_f() 0.0 end subcls_format.taint format.taint - (format % universal).tainted?.should == true - (subcls_format % universal).tainted?.should == true + (format % universal).should.tainted? + (subcls_format % universal).should.tainted? end end end @@ -583,12 +583,12 @@ def obj.inspect() "obj" end obj = mock('x') def obj.inspect() "x".taint end - ("%p" % obj).tainted?.should == true + ("%p" % obj).should.tainted? obj = mock('x'); obj.taint def obj.inspect() "x" end - ("%p" % obj).tainted?.should == false + ("%p" % obj).should_not.tainted? end end @@ -622,8 +622,8 @@ def obj.to_s() "obj" end ruby_version_is ''...'2.7' do it "taints result for %s when argument is tainted" do - ("%s" % "x".taint).tainted?.should == true - ("%s" % mock('x').taint).tainted?.should == true + ("%s" % "x".taint).should.tainted? + ("%s" % mock('x').taint).should.tainted? end end @@ -789,7 +789,7 @@ def obj.to_s() "obj" end ruby_version_is ''...'2.7' do it "doesn't taint the result for #{format} when argument is tainted" do - (format % "5".taint).tainted?.should == false + (format % "5".taint).should_not.tainted? end end end diff --git a/spec/ruby/core/string/reverse_spec.rb b/spec/ruby/core/string/reverse_spec.rb index 30d5385c838723..cf4956a5285b11 100644 --- a/spec/ruby/core/string/reverse_spec.rb +++ b/spec/ruby/core/string/reverse_spec.rb @@ -12,8 +12,8 @@ ruby_version_is ''...'2.7' do it "taints the result if self is tainted" do - "".taint.reverse.tainted?.should == true - "m".taint.reverse.tainted?.should == true + "".taint.reverse.should.tainted? + "m".taint.reverse.should.tainted? end end diff --git a/spec/ruby/core/string/rjust_spec.rb b/spec/ruby/core/string/rjust_spec.rb index 9285ecb6a73d49..bf39f4fdb9bc61 100644 --- a/spec/ruby/core/string/rjust_spec.rb +++ b/spec/ruby/core/string/rjust_spec.rb @@ -33,11 +33,11 @@ ruby_version_is ''...'2.7' do it "taints result when self or padstr is tainted" do - "x".taint.rjust(4).tainted?.should == true - "x".taint.rjust(0).tainted?.should == true - "".taint.rjust(0).tainted?.should == true - "x".taint.rjust(4, "*").tainted?.should == true - "x".rjust(4, "*".taint).tainted?.should == true + "x".taint.rjust(4).should.tainted? + "x".taint.rjust(0).should.tainted? + "".taint.rjust(0).should.tainted? + "x".taint.rjust(4, "*").should.tainted? + "x".rjust(4, "*".taint).should.tainted? end end diff --git a/spec/ruby/core/string/rstrip_spec.rb b/spec/ruby/core/string/rstrip_spec.rb index 0a01ffad7303e4..57e1867956bdfe 100644 --- a/spec/ruby/core/string/rstrip_spec.rb +++ b/spec/ruby/core/string/rstrip_spec.rb @@ -16,9 +16,9 @@ ruby_version_is ''...'2.7' do it "taints the result when self is tainted" do - "".taint.rstrip.tainted?.should == true - "ok".taint.rstrip.tainted?.should == true - "ok ".taint.rstrip.tainted?.should == true + "".taint.rstrip.should.tainted? + "ok".taint.rstrip.should.tainted? + "ok ".taint.rstrip.should.tainted? end end end diff --git a/spec/ruby/core/string/shared/chars.rb b/spec/ruby/core/string/shared/chars.rb index 9c7a4deb8b08f2..1f045e45303385 100644 --- a/spec/ruby/core/string/shared/chars.rb +++ b/spec/ruby/core/string/shared/chars.rb @@ -69,11 +69,11 @@ str = "hello" str.send(@method) do |x| - x.tainted?.should == false + x.should_not.tainted? end str.dup.taint.send(@method) do |x| - x.tainted?.should == true + x.should.tainted? end end end diff --git a/spec/ruby/core/string/shared/concat.rb b/spec/ruby/core/string/shared/concat.rb index d127b08e9cffa2..d6ffad7d4d9683 100644 --- a/spec/ruby/core/string/shared/concat.rb +++ b/spec/ruby/core/string/shared/concat.rb @@ -41,13 +41,13 @@ ruby_version_is ''...'2.7' do it "taints self if other is tainted" do - "x".send(@method, "".taint).tainted?.should == true - "x".send(@method, "y".taint).tainted?.should == true + "x".send(@method, "".taint).should.tainted? + "x".send(@method, "y".taint).should.tainted? end it "untrusts self if other is untrusted" do - "x".send(@method, "".untrust).untrusted?.should == true - "x".send(@method, "y".untrust).untrusted?.should == true + "x".send(@method, "".untrust).should.untrusted? + "x".send(@method, "y".untrust).should.untrusted? end end diff --git a/spec/ruby/core/string/shared/each_line.rb b/spec/ruby/core/string/shared/each_line.rb index c82e63cfe8a088..156565ff138a33 100644 --- a/spec/ruby/core/string/shared/each_line.rb +++ b/spec/ruby/core/string/shared/each_line.rb @@ -42,9 +42,9 @@ ruby_version_is ''...'2.7' do it "taints substrings that are passed to the block if self is tainted" do - "one\ntwo\r\nthree".taint.send(@method) { |s| s.tainted?.should == true } + "one\ntwo\r\nthree".taint.send(@method) { |s| s.should.tainted? } - "x.y.".send(@method, ".".taint) { |s| s.tainted?.should == false } + "x.y.".send(@method, ".".taint) { |s| s.should_not.tainted? } end end diff --git a/spec/ruby/core/string/shared/replace.rb b/spec/ruby/core/string/shared/replace.rb index 3c5a15e12dae45..8dfac49f029855 100644 --- a/spec/ruby/core/string/shared/replace.rb +++ b/spec/ruby/core/string/shared/replace.rb @@ -15,28 +15,28 @@ a = "" b = "".taint a.send(@method, b) - a.tainted?.should == true + a.should.tainted? end it "does not untaint self if other is untainted" do a = "".taint b = "" a.send(@method, b) - a.tainted?.should == true + a.should.tainted? end it "untrusts self if other is untrusted" do a = "" b = "".untrust a.send(@method, b) - a.untrusted?.should == true + a.should.untrusted? end it "does not trust self if other is trusted" do a = "".untrust b = "" a.send(@method, b) - a.untrusted?.should == true + a.should.untrusted? end end diff --git a/spec/ruby/core/string/shared/slice.rb b/spec/ruby/core/string/shared/slice.rb index 1c438bc48d0e5a..6b6f37217a58a8 100644 --- a/spec/ruby/core/string/shared/slice.rb +++ b/spec/ruby/core/string/shared/slice.rb @@ -85,9 +85,9 @@ str = "hello world" str.taint - str.send(@method, 0,0).tainted?.should == true - str.send(@method, 0,1).tainted?.should == true - str.send(@method, 2,1).tainted?.should == true + str.send(@method, 0,0).should.tainted? + str.send(@method, 0,1).should.tainted? + str.send(@method, 2,1).should.tainted? end end @@ -243,12 +243,12 @@ str = "hello world" str.taint - str.send(@method, 0..0).tainted?.should == true - str.send(@method, 0...0).tainted?.should == true - str.send(@method, 0..1).tainted?.should == true - str.send(@method, 0...1).tainted?.should == true - str.send(@method, 2..3).tainted?.should == true - str.send(@method, 2..0).tainted?.should == true + str.send(@method, 0..0).should.tainted? + str.send(@method, 0...0).should.tainted? + str.send(@method, 0..1).should.tainted? + str.send(@method, 0...1).should.tainted? + str.send(@method, 2..3).should.tainted? + str.send(@method, 2..0).should.tainted? end end @@ -338,7 +338,7 @@ tainted_re = /./ tainted_re.taint - str.send(@method, tainted_re).tainted?.should == true + str.send(@method, tainted_re).should.tainted? end end @@ -395,9 +395,9 @@ tainted_re = /(.)(.)(.)/ tainted_re.taint - str.send(@method, tainted_re, 0).tainted?.should == true - str.send(@method, tainted_re, 1).tainted?.should == true - str.send(@method, tainted_re, -1).tainted?.should == true + str.send(@method, tainted_re, 0).should.tainted? + str.send(@method, tainted_re, 1).should.tainted? + str.send(@method, tainted_re, -1).should.tainted? end end diff --git a/spec/ruby/core/string/shared/succ.rb b/spec/ruby/core/string/shared/succ.rb index 346ccee4093f95..7ca488dd882daf 100644 --- a/spec/ruby/core/string/shared/succ.rb +++ b/spec/ruby/core/string/shared/succ.rb @@ -68,7 +68,7 @@ ruby_version_is ''...'2.7' do it "taints the result if self is tainted" do ["", "a", "z", "Z", "9", "\xFF", "\xFF\xFF"].each do |s| - s.taint.send(@method).tainted?.should == true + s.taint.send(@method).should.tainted? end end end diff --git a/spec/ruby/core/string/shared/to_s.rb b/spec/ruby/core/string/shared/to_s.rb index 36283be4d04caf..b8c9b8ab441571 100644 --- a/spec/ruby/core/string/shared/to_s.rb +++ b/spec/ruby/core/string/shared/to_s.rb @@ -13,8 +13,8 @@ ruby_version_is ''...'2.7' do it "taints the result when self is tainted" do - "x".taint.send(@method).tainted?.should == true - StringSpecs::MyString.new("x").taint.send(@method).tainted?.should == true + "x".taint.send(@method).should.tainted? + StringSpecs::MyString.new("x").taint.send(@method).should.tainted? end end end diff --git a/spec/ruby/core/string/shared/to_sym.rb b/spec/ruby/core/string/shared/to_sym.rb index 1180d647123e3d..416f302aefd211 100644 --- a/spec/ruby/core/string/shared/to_sym.rb +++ b/spec/ruby/core/string/shared/to_sym.rb @@ -55,7 +55,7 @@ it "raises an EncodingError for UTF-8 String containing invalid bytes" do invalid_utf8 = "\xC3" - invalid_utf8.valid_encoding?.should == false + invalid_utf8.should_not.valid_encoding? -> { invalid_utf8.send(@method) }.should raise_error(EncodingError, /invalid/) diff --git a/spec/ruby/core/string/slice_spec.rb b/spec/ruby/core/string/slice_spec.rb index a34dd1b8d4a923..bd0a63971b848a 100644 --- a/spec/ruby/core/string/slice_spec.rb +++ b/spec/ruby/core/string/slice_spec.rb @@ -99,8 +99,8 @@ str = "hello world" str.taint - str.slice!(0, 0).tainted?.should == true - str.slice!(2, 1).tainted?.should == true + str.slice!(0, 0).should.tainted? + str.slice!(2, 1).should.tainted? end end @@ -191,8 +191,8 @@ def obj.method_missing(name, *) name == :to_int ? 2 : super; end str = "hello world" str.taint - str.slice!(0..0).tainted?.should == true - str.slice!(2..3).tainted?.should == true + str.slice!(0..0).should.tainted? + str.slice!(2..3).should.tainted? end end @@ -288,14 +288,14 @@ def to.method_missing(name) name == :to_int ? -2 : super; end tainted_re = /./ tainted_re.taint - str.slice!(tainted_re).tainted?.should == true + str.slice!(tainted_re).should.tainted? end end it "doesn't taint self when regexp is tainted" do s = "hello" s.slice!(/./.taint) - s.tainted?.should == false + s.should_not.tainted? end end @@ -349,14 +349,14 @@ def to.method_missing(name) name == :to_int ? -2 : super; end tainted_re = /(.)(.)(.)/ tainted_re.taint - str.slice!(tainted_re, 1).tainted?.should == true + str.slice!(tainted_re, 1).should.tainted? end end it "doesn't taint self when regexp is tainted" do s = "hello" s.slice!(/(.)(.)/.taint, 1) - s.tainted?.should == false + s.should_not.tainted? end end diff --git a/spec/ruby/core/string/split_spec.rb b/spec/ruby/core/string/split_spec.rb index 8a740b04caaaa3..34a50a5f131f66 100644 --- a/spec/ruby/core/string/split_spec.rb +++ b/spec/ruby/core/string/split_spec.rb @@ -189,11 +189,11 @@ ["", ".", " "].each do |pat| [-1, 0, 1, 2].each do |limit| str.dup.taint.split(pat).each do |x| - x.tainted?.should == true + x.should.tainted? end str.split(pat.dup.taint).each do |x| - x.tainted?.should == false + x.should_not.tainted? end end end diff --git a/spec/ruby/core/string/squeeze_spec.rb b/spec/ruby/core/string/squeeze_spec.rb index e54ed42b49e60e..5a7fbb59def7ae 100644 --- a/spec/ruby/core/string/squeeze_spec.rb +++ b/spec/ruby/core/string/squeeze_spec.rb @@ -56,11 +56,11 @@ ruby_version_is ''...'2.7' do it "taints the result when self is tainted" do - "hello".taint.squeeze("e").tainted?.should == true - "hello".taint.squeeze("a-z").tainted?.should == true + "hello".taint.squeeze("e").should.tainted? + "hello".taint.squeeze("a-z").should.tainted? - "hello".squeeze("e".taint).tainted?.should == false - "hello".squeeze("l".taint).tainted?.should == false + "hello".squeeze("e".taint).should_not.tainted? + "hello".squeeze("l".taint).should_not.tainted? end end diff --git a/spec/ruby/core/string/strip_spec.rb b/spec/ruby/core/string/strip_spec.rb index 1838e07f32085a..252d4a9cc3b4f0 100644 --- a/spec/ruby/core/string/strip_spec.rb +++ b/spec/ruby/core/string/strip_spec.rb @@ -15,9 +15,9 @@ ruby_version_is ''...'2.7' do it "taints the result when self is tainted" do - "".taint.strip.tainted?.should == true - "ok".taint.strip.tainted?.should == true - " ok ".taint.strip.tainted?.should == true + "".taint.strip.should.tainted? + "ok".taint.strip.should.tainted? + " ok ".taint.strip.should.tainted? end end end diff --git a/spec/ruby/core/string/sub_spec.rb b/spec/ruby/core/string/sub_spec.rb index f240cd8cffe921..80cf8622d5496a 100644 --- a/spec/ruby/core/string/sub_spec.rb +++ b/spec/ruby/core/string/sub_spec.rb @@ -148,14 +148,14 @@ hello_t.taint; a_t.taint; empty_t.taint - hello_t.sub(/./, a).tainted?.should == true - hello_t.sub(/./, empty).tainted?.should == true + hello_t.sub(/./, a).should.tainted? + hello_t.sub(/./, empty).should.tainted? - hello.sub(/./, a_t).tainted?.should == true - hello.sub(/./, empty_t).tainted?.should == true - hello.sub(//, empty_t).tainted?.should == true + hello.sub(/./, a_t).should.tainted? + hello.sub(/./, empty_t).should.tainted? + hello.sub(//, empty_t).should.tainted? - hello.sub(//.taint, "foo").tainted?.should == false + hello.sub(//.taint, "foo").should_not.tainted? end end @@ -298,14 +298,14 @@ hello_t.taint; a_t.taint; empty_t.taint - hello_t.sub(/./) { a }.tainted?.should == true - hello_t.sub(/./) { empty }.tainted?.should == true + hello_t.sub(/./) { a }.should.tainted? + hello_t.sub(/./) { empty }.should.tainted? - hello.sub(/./) { a_t }.tainted?.should == true - hello.sub(/./) { empty_t }.tainted?.should == true - hello.sub(//) { empty_t }.tainted?.should == true + hello.sub(/./) { a_t }.should.tainted? + hello.sub(/./) { empty_t }.should.tainted? + hello.sub(//) { empty_t }.should.tainted? - hello.sub(//.taint) { "foo" }.tainted?.should == false + hello.sub(//.taint) { "foo" }.should_not.tainted? end end end @@ -320,8 +320,8 @@ ruby_version_is ''...'2.7' do it "taints self if replacement is tainted" do a = "hello" - a.sub!(/./.taint, "foo").tainted?.should == false - a.sub!(/./, "foo".taint).tainted?.should == true + a.sub!(/./.taint, "foo").should_not.tainted? + a.sub!(/./, "foo".taint).should.tainted? end end @@ -370,8 +370,8 @@ ruby_version_is ''...'2.7' do it "taints self if block's result is tainted" do a = "hello" - a.sub!(/./.taint) { "foo" }.tainted?.should == false - a.sub!(/./) { "foo".taint }.tainted?.should == true + a.sub!(/./.taint) { "foo" }.should_not.tainted? + a.sub!(/./) { "foo".taint }.should.tainted? end end diff --git a/spec/ruby/core/string/swapcase_spec.rb b/spec/ruby/core/string/swapcase_spec.rb index d1e908d71dd5cb..0b50cc35c48882 100644 --- a/spec/ruby/core/string/swapcase_spec.rb +++ b/spec/ruby/core/string/swapcase_spec.rb @@ -11,8 +11,8 @@ ruby_version_is ''...'2.7' do it "taints resulting string when self is tainted" do - "".taint.swapcase.tainted?.should == true - "hello".taint.swapcase.tainted?.should == true + "".taint.swapcase.should.tainted? + "hello".taint.swapcase.should.tainted? end end diff --git a/spec/ruby/core/string/tr_s_spec.rb b/spec/ruby/core/string/tr_s_spec.rb index e004ab713c5477..cdf5667ea3701a 100644 --- a/spec/ruby/core/string/tr_s_spec.rb +++ b/spec/ruby/core/string/tr_s_spec.rb @@ -54,10 +54,10 @@ ["h", "hello"].each do |str| tainted_str = str.dup.taint - tainted_str.tr_s("e", "a").tainted?.should == true + tainted_str.tr_s("e", "a").should.tainted? - str.tr_s("e".taint, "a").tainted?.should == false - str.tr_s("e", "a".taint).tainted?.should == false + str.tr_s("e".taint, "a").should_not.tainted? + str.tr_s("e", "a".taint).should_not.tainted? end end end diff --git a/spec/ruby/core/string/tr_spec.rb b/spec/ruby/core/string/tr_spec.rb index 0e4da398d54d8e..212d06f6790c8a 100644 --- a/spec/ruby/core/string/tr_spec.rb +++ b/spec/ruby/core/string/tr_spec.rb @@ -66,10 +66,10 @@ ["h", "hello"].each do |str| tainted_str = str.dup.taint - tainted_str.tr("e", "a").tainted?.should == true + tainted_str.tr("e", "a").should.tainted? - str.tr("e".taint, "a").tainted?.should == false - str.tr("e", "a".taint).tainted?.should == false + str.tr("e".taint, "a").should_not.tainted? + str.tr("e", "a".taint).should_not.tainted? end end end diff --git a/spec/ruby/core/string/uminus_spec.rb b/spec/ruby/core/string/uminus_spec.rb index 85b484b6df7509..91f91fdb1ec354 100644 --- a/spec/ruby/core/string/uminus_spec.rb +++ b/spec/ruby/core/string/uminus_spec.rb @@ -6,14 +6,14 @@ output = -input output.should equal(input) - output.frozen?.should == true + output.should.frozen? end it 'returns a frozen copy if the String is not frozen' do input = 'foo' output = -input - output.frozen?.should == true + output.should.frozen? output.should_not equal(input) output.should == 'foo' end diff --git a/spec/ruby/core/string/undump_spec.rb b/spec/ruby/core/string/undump_spec.rb index 81deb6fa58234f..b990aa25eed90c 100644 --- a/spec/ruby/core/string/undump_spec.rb +++ b/spec/ruby/core/string/undump_spec.rb @@ -5,16 +5,16 @@ describe "String#undump" do ruby_version_is ''...'2.7' do it "taints the result if self is tainted" do - '"foo"'.taint.undump.tainted?.should == true + '"foo"'.taint.undump.should.tainted? end it "untrusts the result if self is untrusted" do - '"foo"'.untrust.undump.untrusted?.should == true + '"foo"'.untrust.undump.should.untrusted? end end it "does not take into account if a string is frozen" do - '"foo"'.freeze.undump.frozen?.should == false + '"foo"'.freeze.undump.should_not.frozen? end it "always returns String instance" do diff --git a/spec/ruby/core/string/unicode_normalized_spec.rb b/spec/ruby/core/string/unicode_normalized_spec.rb index 25c810a98f6569..87f3740459bb0b 100644 --- a/spec/ruby/core/string/unicode_normalized_spec.rb +++ b/spec/ruby/core/string/unicode_normalized_spec.rb @@ -24,16 +24,16 @@ end it "defaults to the nfc normalization form if no forms are specified" do - @nfc_normalized_str.unicode_normalized?.should == true - @nfd_normalized_str.unicode_normalized?.should == false + @nfc_normalized_str.should.unicode_normalized? + @nfd_normalized_str.should_not.unicode_normalized? end it "returns true if string is empty" do - "".unicode_normalized?.should == true + "".should.unicode_normalized? end it "returns true if string does not contain any unicode codepoints" do - "abc".unicode_normalized?.should == true + "abc".should.unicode_normalized? end it "raises an Encoding::CompatibilityError if the string is not in an unicode encoding" do diff --git a/spec/ruby/core/string/upcase_spec.rb b/spec/ruby/core/string/upcase_spec.rb index c440b1b0aa8ed7..13ebd09a95078d 100644 --- a/spec/ruby/core/string/upcase_spec.rb +++ b/spec/ruby/core/string/upcase_spec.rb @@ -67,9 +67,9 @@ ruby_version_is ''...'2.7' do it "taints result when self is tainted" do - "".taint.upcase.tainted?.should == true - "X".taint.upcase.tainted?.should == true - "x".taint.upcase.tainted?.should == true + "".taint.upcase.should.tainted? + "X".taint.upcase.should.tainted? + "x".taint.upcase.should.tainted? end end diff --git a/spec/ruby/core/string/uplus_spec.rb b/spec/ruby/core/string/uplus_spec.rb index a7402b45498cdb..038b283c90eff0 100644 --- a/spec/ruby/core/string/uplus_spec.rb +++ b/spec/ruby/core/string/uplus_spec.rb @@ -5,7 +5,7 @@ input = 'foo'.freeze output = +input - output.frozen?.should == false + output.should_not.frozen? output.should == 'foo' end diff --git a/spec/ruby/core/symbol/to_proc_spec.rb b/spec/ruby/core/symbol/to_proc_spec.rb index 6651022375f17b..32f996d63c373c 100644 --- a/spec/ruby/core/symbol/to_proc_spec.rb +++ b/spec/ruby/core/symbol/to_proc_spec.rb @@ -15,7 +15,7 @@ ruby_version_is ""..."2.8" do it "returns a Proc with #lambda? false" do pr = :to_s.to_proc - pr.lambda?.should == false + pr.should_not.lambda? end it "produces a Proc with arity -1" do @@ -32,7 +32,7 @@ ruby_version_is "2.8" do it "returns a Proc with #lambda? true" do pr = :to_s.to_proc - pr.lambda?.should == true + pr.should.lambda? end it "produces a Proc with arity -2" do diff --git a/spec/ruby/core/systemexit/success_spec.rb b/spec/ruby/core/systemexit/success_spec.rb index 6d36509c808a7b..ba2fd22ded4f97 100644 --- a/spec/ruby/core/systemexit/success_spec.rb +++ b/spec/ruby/core/systemexit/success_spec.rb @@ -3,11 +3,11 @@ describe "SystemExit#success?" do it "returns true when the status is 0" do s = SystemExit.new 0 - s.success?.should == true + s.should.success? end it "returns false when the status is not 0" do s = SystemExit.new 1 - s.success?.should == false + s.should_not.success? end end diff --git a/spec/ruby/core/thread/alive_spec.rb b/spec/ruby/core/thread/alive_spec.rb index d4ba149d87beb4..c2f5f5371df5df 100644 --- a/spec/ruby/core/thread/alive_spec.rb +++ b/spec/ruby/core/thread/alive_spec.rb @@ -3,39 +3,39 @@ describe "Thread#alive?" do it "can check it's own status" do - ThreadSpecs.status_of_current_thread.alive?.should == true + ThreadSpecs.status_of_current_thread.should.alive? end it "describes a running thread" do - ThreadSpecs.status_of_running_thread.alive?.should == true + ThreadSpecs.status_of_running_thread.should.alive? end it "describes a sleeping thread" do - ThreadSpecs.status_of_sleeping_thread.alive?.should == true + ThreadSpecs.status_of_sleeping_thread.should.alive? end it "describes a blocked thread" do - ThreadSpecs.status_of_blocked_thread.alive?.should == true + ThreadSpecs.status_of_blocked_thread.should.alive? end it "describes a completed thread" do - ThreadSpecs.status_of_completed_thread.alive?.should == false + ThreadSpecs.status_of_completed_thread.should_not.alive? end it "describes a killed thread" do - ThreadSpecs.status_of_killed_thread.alive?.should == false + ThreadSpecs.status_of_killed_thread.should_not.alive? end it "describes a thread with an uncaught exception" do - ThreadSpecs.status_of_thread_with_uncaught_exception.alive?.should == false + ThreadSpecs.status_of_thread_with_uncaught_exception.should_not.alive? end it "describes a dying running thread" do - ThreadSpecs.status_of_dying_running_thread.alive?.should == true + ThreadSpecs.status_of_dying_running_thread.should.alive? end it "describes a dying sleeping thread" do - ThreadSpecs.status_of_dying_sleeping_thread.alive?.should == true + ThreadSpecs.status_of_dying_sleeping_thread.should.alive? end it "returns true for a killed but still running thread" do @@ -51,7 +51,7 @@ ThreadSpecs.spin_until_sleeping(t) t.kill - t.alive?.should == true + t.should.alive? exit = true t.join end diff --git a/spec/ruby/core/thread/new_spec.rb b/spec/ruby/core/thread/new_spec.rb index 3a57149381e06a..47a836201c0a0d 100644 --- a/spec/ruby/core/thread/new_spec.rb +++ b/spec/ruby/core/thread/new_spec.rb @@ -58,13 +58,13 @@ def initialize m2 = Mutex.new t = Thread.new { m1.lock - m1.locked?.should == true + m1.should.locked? m2.lock - m2.locked?.should == true + m2.should.locked? } t.join - m1.locked?.should == false - m2.locked?.should == false + m1.should_not.locked? + m2.should_not.locked? end it "releases Mutexes held by the Thread when the Thread finishes, also with Mutex#synchronize" do @@ -75,9 +75,9 @@ def initialize m.lock } m.lock - m.locked?.should == true + m.should.locked? } t.join - m.locked?.should == false + m.should_not.locked? end end diff --git a/spec/ruby/core/thread/stop_spec.rb b/spec/ruby/core/thread/stop_spec.rb index 33cf8f7b5c0f52..084ab46ef655c0 100644 --- a/spec/ruby/core/thread/stop_spec.rb +++ b/spec/ruby/core/thread/stop_spec.rb @@ -13,42 +13,42 @@ describe "Thread#stop?" do it "can check it's own status" do - ThreadSpecs.status_of_current_thread.stop?.should == false + ThreadSpecs.status_of_current_thread.should_not.stop? end it "describes a running thread" do - ThreadSpecs.status_of_running_thread.stop?.should == false + ThreadSpecs.status_of_running_thread.should_not.stop? end it "describes a sleeping thread" do - ThreadSpecs.status_of_sleeping_thread.stop?.should == true + ThreadSpecs.status_of_sleeping_thread.should.stop? end it "describes a blocked thread" do - ThreadSpecs.status_of_blocked_thread.stop?.should == true + ThreadSpecs.status_of_blocked_thread.should.stop? end it "describes a completed thread" do - ThreadSpecs.status_of_completed_thread.stop?.should == true + ThreadSpecs.status_of_completed_thread.should.stop? end it "describes a killed thread" do - ThreadSpecs.status_of_killed_thread.stop?.should == true + ThreadSpecs.status_of_killed_thread.should.stop? end it "describes a thread with an uncaught exception" do - ThreadSpecs.status_of_thread_with_uncaught_exception.stop?.should == true + ThreadSpecs.status_of_thread_with_uncaught_exception.should.stop? end it "describes a dying running thread" do - ThreadSpecs.status_of_dying_running_thread.stop?.should == false + ThreadSpecs.status_of_dying_running_thread.should_not.stop? end it "describes a dying sleeping thread" do - ThreadSpecs.status_of_dying_sleeping_thread.stop?.should == true + ThreadSpecs.status_of_dying_sleeping_thread.should.stop? end it "describes a dying thread after sleep" do - ThreadSpecs.status_of_dying_thread_after_sleep.stop?.should == false + ThreadSpecs.status_of_dying_thread_after_sleep.should_not.stop? end end diff --git a/spec/ruby/core/time/_dump_spec.rb b/spec/ruby/core/time/_dump_spec.rb index 6941a1531f0191..4dc1c43cd2d941 100644 --- a/spec/ruby/core/time/_dump_spec.rb +++ b/spec/ruby/core/time/_dump_spec.rb @@ -15,11 +15,11 @@ # http://redmine.ruby-lang.org/issues/show/627 it "preserves the GMT flag" do - @t.gmt?.should == true + @t.should.gmt? dump = @t.send(:_dump).unpack("VV").first ((dump >> 30) & 0x1).should == 1 - @local.gmt?.should == false + @local.should_not.gmt? dump = @local.send(:_dump).unpack("VV").first ((dump >> 30) & 0x1).should == 0 end diff --git a/spec/ruby/core/time/at_spec.rb b/spec/ruby/core/time/at_spec.rb index 28a3d7b34c84fa..6f4d83f9ad450c 100644 --- a/spec/ruby/core/time/at_spec.rb +++ b/spec/ruby/core/time/at_spec.rb @@ -14,7 +14,7 @@ end it "returns a non-UTC Time" do - Time.at(1184027924).utc?.should == false + Time.at(1184027924).should_not.utc? end it "returns a subclass instance on a Time subclass" do @@ -54,12 +54,12 @@ it "returns a UTC time if the argument is UTC" do t = Time.now.getgm - Time.at(t).utc?.should == true + Time.at(t).should.utc? end it "returns a non-UTC time if the argument is non-UTC" do t = Time.now - Time.at(t).utc?.should == false + Time.at(t).should_not.utc? end it "returns a subclass instance" do diff --git a/spec/ruby/core/time/dup_spec.rb b/spec/ruby/core/time/dup_spec.rb index ee2ff7dbba81d3..5d6621beaa84f7 100644 --- a/spec/ruby/core/time/dup_spec.rb +++ b/spec/ruby/core/time/dup_spec.rb @@ -7,7 +7,7 @@ end it "copies the gmt state flag" do - Time.now.gmtime.dup.gmt?.should == true + Time.now.gmtime.dup.should.gmt? end it "returns an independent Time object" do @@ -15,7 +15,7 @@ t2 = t.dup t.gmtime - t2.gmt?.should == false + t2.should_not.gmt? end it "returns a subclass instance" do diff --git a/spec/ruby/core/time/friday_spec.rb b/spec/ruby/core/time/friday_spec.rb index 27f9e1dbe5e4a3..8bee7f755837b1 100644 --- a/spec/ruby/core/time/friday_spec.rb +++ b/spec/ruby/core/time/friday_spec.rb @@ -2,10 +2,10 @@ describe "Time#friday?" do it "returns true if time represents Friday" do - Time.local(2000, 1, 7).friday?.should == true + Time.local(2000, 1, 7).should.friday? end it "returns false if time doesn't represent Friday" do - Time.local(2000, 1, 1).friday?.should == false + Time.local(2000, 1, 1).should_not.friday? end end diff --git a/spec/ruby/core/time/gmt_spec.rb b/spec/ruby/core/time/gmt_spec.rb index 7e85749d5b249e..840f59e0e84abc 100644 --- a/spec/ruby/core/time/gmt_spec.rb +++ b/spec/ruby/core/time/gmt_spec.rb @@ -2,7 +2,7 @@ describe "Time#gmt?" do it "returns true if time represents a time in UTC (GMT)" do - Time.now.gmt?.should == false - Time.now.gmtime.gmt?.should == true + Time.now.should_not.gmt? + Time.now.gmtime.should.gmt? end end diff --git a/spec/ruby/core/time/minus_spec.rb b/spec/ruby/core/time/minus_spec.rb index 65613d11e90b9b..995dac846283d1 100644 --- a/spec/ruby/core/time/minus_spec.rb +++ b/spec/ruby/core/time/minus_spec.rb @@ -79,11 +79,11 @@ end it "returns a UTC time if self is UTC" do - (Time.utc(2012) - 10).utc?.should == true + (Time.utc(2012) - 10).should.utc? end it "returns a non-UTC time if self is non-UTC" do - (Time.local(2012) - 10).utc?.should == false + (Time.local(2012) - 10).should_not.utc? end it "returns a time with the same fixed offset as self" do diff --git a/spec/ruby/core/time/monday_spec.rb b/spec/ruby/core/time/monday_spec.rb index c5c43a5c3ef246..47ecaeb1db2a22 100644 --- a/spec/ruby/core/time/monday_spec.rb +++ b/spec/ruby/core/time/monday_spec.rb @@ -2,10 +2,10 @@ describe "Time#monday?" do it "returns true if time represents Monday" do - Time.local(2000, 1, 3).monday?.should == true + Time.local(2000, 1, 3).should.monday? end it "returns false if time doesn't represent Monday" do - Time.local(2000, 1, 1).monday?.should == false + Time.local(2000, 1, 1).should_not.monday? end end diff --git a/spec/ruby/core/time/new_spec.rb b/spec/ruby/core/time/new_spec.rb index a5cfa2a7dfe574..3cafd46db7dce4 100644 --- a/spec/ruby/core/time/new_spec.rb +++ b/spec/ruby/core/time/new_spec.rb @@ -15,7 +15,7 @@ describe "Time.new with a utc_offset argument" do it "returns a non-UTC time" do - Time.new(2000, 1, 1, 0, 0, 0, 0).utc?.should == false + Time.new(2000, 1, 1, 0, 0, 0, 0).should_not.utc? end it "returns a Time with a UTC offset of the specified number of Integer seconds" do diff --git a/spec/ruby/core/time/plus_spec.rb b/spec/ruby/core/time/plus_spec.rb index 6c29baf1247c97..c59d9a32bb6cf7 100644 --- a/spec/ruby/core/time/plus_spec.rb +++ b/spec/ruby/core/time/plus_spec.rb @@ -37,11 +37,11 @@ end it "returns a UTC time if self is UTC" do - (Time.utc(2012) + 10).utc?.should == true + (Time.utc(2012) + 10).should.utc? end it "returns a non-UTC time if self is non-UTC" do - (Time.local(2012) + 10).utc?.should == false + (Time.local(2012) + 10).should_not.utc? end it "returns a time with the same fixed offset as self" do diff --git a/spec/ruby/core/time/saturday_spec.rb b/spec/ruby/core/time/saturday_spec.rb index 60ffea41986a87..0e51407366bbf0 100644 --- a/spec/ruby/core/time/saturday_spec.rb +++ b/spec/ruby/core/time/saturday_spec.rb @@ -2,10 +2,10 @@ describe "Time#saturday?" do it "returns true if time represents Saturday" do - Time.local(2000, 1, 1).saturday?.should == true + Time.local(2000, 1, 1).should.saturday? end it "returns false if time doesn't represent Saturday" do - Time.local(2000, 1, 2).saturday?.should == false + Time.local(2000, 1, 2).should_not.saturday? end end diff --git a/spec/ruby/core/time/shared/to_i.rb b/spec/ruby/core/time/shared/to_i.rb index 03497c700bd01c..06c966b7085b1e 100644 --- a/spec/ruby/core/time/shared/to_i.rb +++ b/spec/ruby/core/time/shared/to_i.rb @@ -6,4 +6,11 @@ it "doesn't return an actual number of seconds in time" do Time.at(65.5).send(@method).should == 65 end + + it "rounds fractional seconds toward zero" do + t = Time.utc(1960, 1, 1, 0, 0, 0, 999_999) + + t.to_f.to_i.should == -315619199 + t.to_i.should == -315619200 + end end diff --git a/spec/ruby/core/time/sunday_spec.rb b/spec/ruby/core/time/sunday_spec.rb index 2285583579d2e2..0d46421132dded 100644 --- a/spec/ruby/core/time/sunday_spec.rb +++ b/spec/ruby/core/time/sunday_spec.rb @@ -2,10 +2,10 @@ describe "Time#sunday?" do it "returns true if time represents Sunday" do - Time.local(2000, 1, 2).sunday?.should == true + Time.local(2000, 1, 2).should.sunday? end it "returns false if time doesn't represent Sunday" do - Time.local(2000, 1, 1).sunday?.should == false + Time.local(2000, 1, 1).should_not.sunday? end end diff --git a/spec/ruby/core/time/thursday_spec.rb b/spec/ruby/core/time/thursday_spec.rb index c82d5175194486..c11e79d2fa9427 100644 --- a/spec/ruby/core/time/thursday_spec.rb +++ b/spec/ruby/core/time/thursday_spec.rb @@ -2,10 +2,10 @@ describe "Time#thursday?" do it "returns true if time represents Thursday" do - Time.local(2000, 1, 6).thursday?.should == true + Time.local(2000, 1, 6).should.thursday? end it "returns false if time doesn't represent Thursday" do - Time.local(2000, 1, 1).thursday?.should == false + Time.local(2000, 1, 1).should_not.thursday? end end diff --git a/spec/ruby/core/time/tuesday_spec.rb b/spec/ruby/core/time/tuesday_spec.rb index 7abbdc92c0a96c..0e7b9e75063bd9 100644 --- a/spec/ruby/core/time/tuesday_spec.rb +++ b/spec/ruby/core/time/tuesday_spec.rb @@ -2,10 +2,10 @@ describe "Time#tuesday?" do it "returns true if time represents Tuesday" do - Time.local(2000, 1, 4).tuesday?.should == true + Time.local(2000, 1, 4).should.tuesday? end it "returns false if time doesn't represent Tuesday" do - Time.local(2000, 1, 1).tuesday?.should == false + Time.local(2000, 1, 1).should_not.tuesday? end end diff --git a/spec/ruby/core/time/utc_spec.rb b/spec/ruby/core/time/utc_spec.rb index 5074c8d54d980f..74c17a93d167ab 100644 --- a/spec/ruby/core/time/utc_spec.rb +++ b/spec/ruby/core/time/utc_spec.rb @@ -5,7 +5,7 @@ describe "Time#utc?" do it "returns true if time represents a time in UTC (GMT)" do - Time.now.utc?.should == false + Time.now.should_not.utc? end end diff --git a/spec/ruby/core/time/wednesday_spec.rb b/spec/ruby/core/time/wednesday_spec.rb index 6a52c3577bfd81..cc686681d7fafb 100644 --- a/spec/ruby/core/time/wednesday_spec.rb +++ b/spec/ruby/core/time/wednesday_spec.rb @@ -2,10 +2,10 @@ describe "Time#wednesday?" do it "returns true if time represents Wednesday" do - Time.local(2000, 1, 5).wednesday?.should == true + Time.local(2000, 1, 5).should.wednesday? end it "returns false if time doesn't represent Wednesday" do - Time.local(2000, 1, 1).wednesday?.should == false + Time.local(2000, 1, 1).should_not.wednesday? end end diff --git a/spec/ruby/core/tracepoint/disable_spec.rb b/spec/ruby/core/tracepoint/disable_spec.rb index 612ca3c25ab67f..2ab9b987f4b0bf 100644 --- a/spec/ruby/core/tracepoint/disable_spec.rb +++ b/spec/ruby/core/tracepoint/disable_spec.rb @@ -41,7 +41,7 @@ begin trace.disable { enabled = trace.enabled? } enabled.should == false - trace.enabled?.should == true + trace.should.enabled? ensure trace.disable end @@ -52,7 +52,7 @@ trace.enable begin trace.disable { 42 }.should == 42 - trace.enabled?.should == true + trace.should.enabled? ensure trace.disable end @@ -65,7 +65,7 @@ trace.disable do |*args| args.should == [] end - trace.enabled?.should == true + trace.should.enabled? ensure trace.disable end diff --git a/spec/ruby/core/tracepoint/enable_spec.rb b/spec/ruby/core/tracepoint/enable_spec.rb index b0fe38c559e8b8..15eb2f1616a4d5 100644 --- a/spec/ruby/core/tracepoint/enable_spec.rb +++ b/spec/ruby/core/tracepoint/enable_spec.rb @@ -65,7 +65,7 @@ event_name.should equal(:line) args.should == [] end - trace.enabled?.should == false + trace.should_not.enabled? end it 'enables trace object on calling with a block if it was already enabled' do @@ -92,7 +92,7 @@ line_event = true } called.should == true - trace.enabled?.should == false + trace.should_not.enabled? end end diff --git a/spec/ruby/core/tracepoint/enabled_spec.rb b/spec/ruby/core/tracepoint/enabled_spec.rb index 0167d32fb0eeaa..dbc3c214c53a55 100644 --- a/spec/ruby/core/tracepoint/enabled_spec.rb +++ b/spec/ruby/core/tracepoint/enabled_spec.rb @@ -4,11 +4,11 @@ it 'returns true when current status of the trace is enable' do trace = TracePoint.new(:line) {} trace.enable do - trace.enabled?.should == true + trace.should.enabled? end end it 'returns false when current status of the trace is disabled' do - TracePoint.new(:line) {}.enabled?.should == false + TracePoint.new(:line) {}.should_not.enabled? end end diff --git a/spec/ruby/core/tracepoint/inspect_spec.rb b/spec/ruby/core/tracepoint/inspect_spec.rb index 9ff1653ae83b42..465f01e2298396 100644 --- a/spec/ruby/core/tracepoint/inspect_spec.rb +++ b/spec/ruby/core/tracepoint/inspect_spec.rb @@ -3,26 +3,32 @@ describe 'TracePoint#inspect' do it 'returns a string containing a human-readable TracePoint status' do - TracePoint.new(:line) {}.inspect.should == - '#' + TracePoint.new(:line) {}.inspect.should == '#' end it 'returns a String showing the event, path and line' do inspect = nil - line = __LINE__ - TracePoint.new(:line) { |tp| inspect = tp.inspect }.enable do - inspect.should == "#" + line = nil + TracePoint.new(:line) { |tp| + inspect ||= tp.inspect + }.enable do + line = __LINE__ end + + inspect.should == "#" end it 'returns a String showing the event, path and line for a :class event' do inspect = nil - line = __LINE__ - TracePoint.new(:class) { |tp| inspect = tp.inspect }.enable do + line = nil + TracePoint.new(:class) { |tp| + inspect ||= tp.inspect + }.enable do + line = __LINE__ + 1 class TracePointSpec::C end end - inspect.should == "#" + inspect.should == "#" end end diff --git a/spec/ruby/core/tracepoint/trace_spec.rb b/spec/ruby/core/tracepoint/trace_spec.rb index ea6c85bcc55762..c39721e69298b5 100644 --- a/spec/ruby/core/tracepoint/trace_spec.rb +++ b/spec/ruby/core/tracepoint/trace_spec.rb @@ -3,7 +3,7 @@ describe 'TracePoint.trace' do it 'activates the trace automatically' do trace = TracePoint.trace(:line) {} - trace.enabled?.should == true + trace.should.enabled? trace.disable end end diff --git a/spec/ruby/core/true/to_s_spec.rb b/spec/ruby/core/true/to_s_spec.rb index 68b0052c5d5300..f26cd138e2e521 100644 --- a/spec/ruby/core/true/to_s_spec.rb +++ b/spec/ruby/core/true/to_s_spec.rb @@ -7,7 +7,7 @@ ruby_version_is "2.7" do it "returns a frozen string" do - true.to_s.frozen?.should == true + true.to_s.should.frozen? end it "always returns the same string" do diff --git a/spec/ruby/language/hash_spec.rb b/spec/ruby/language/hash_spec.rb index 6f2e8e5cf0cbbc..630c9d2364bca0 100644 --- a/spec/ruby/language/hash_spec.rb +++ b/spec/ruby/language/hash_spec.rb @@ -38,7 +38,7 @@ key.reverse! h["foo"].should == "bar" h.keys.first.should == "foo" - h.keys.first.frozen?.should == true + h.keys.first.should.frozen? key.should == "oof" end diff --git a/spec/ruby/language/predefined_spec.rb b/spec/ruby/language/predefined_spec.rb index 970071eccd73f4..5ce4e77906ce9b 100644 --- a/spec/ruby/language/predefined_spec.rb +++ b/spec/ruby/language/predefined_spec.rb @@ -53,10 +53,10 @@ it "is set to nil if the last match was unsuccessful" do /foo/ =~ 'foo' - $~.nil?.should == false + $~.should_not.nil? /foo/ =~ 'bar' - $~.nil?.should == true + $~.should.nil? end it "is set at the method-scoped level rather than block-scoped" do @@ -1091,8 +1091,6 @@ def obj.foo2; yield; end DATA IO If the main program file contains the directive __END__, then the constant DATA will be initialized so that reading from it will return lines following __END__ from the source file. -FALSE FalseClass Synonym for false. -NIL NilClass Synonym for nil. RUBY_PLATFORM String The identifier of the platform running this program. This string is in the same form as the platform identifier used by the GNU configure utility (which is not a coincidence). @@ -1110,31 +1108,9 @@ def obj.foo2; yield; end the value. TOPLEVEL_BINDING Binding A Binding object representing the binding at Ruby’s top level— the level where programs are initially executed. -TRUE TrueClass Synonym for true. =end describe "The predefined global constants" do - it "includes TRUE" do - Object.const_defined?(:TRUE).should == true - -> { - TRUE.should equal(true) - }.should complain(/constant ::TRUE is deprecated/) - end - - it "includes FALSE" do - Object.const_defined?(:FALSE).should == true - -> { - FALSE.should equal(false) - }.should complain(/constant ::FALSE is deprecated/) - end - - it "includes NIL" do - Object.const_defined?(:NIL).should == true - -> { - NIL.should equal(nil) - }.should complain(/constant ::NIL is deprecated/) - end - it "includes STDIN" do Object.const_defined?(:STDIN).should == true end diff --git a/spec/ruby/language/regexp/encoding_spec.rb b/spec/ruby/language/regexp/encoding_spec.rb index 2db09fdda859da..8e2a294b9581a4 100644 --- a/spec/ruby/language/regexp/encoding_spec.rb +++ b/spec/ruby/language/regexp/encoding_spec.rb @@ -121,11 +121,11 @@ make_regexp = -> str { /#{str}/ } r = make_regexp.call("été".force_encoding(Encoding::UTF_8)) - r.fixed_encoding?.should == true + r.should.fixed_encoding? r.encoding.should == Encoding::UTF_8 r = make_regexp.call("abc".force_encoding(Encoding::UTF_8)) - r.fixed_encoding?.should == false + r.should_not.fixed_encoding? r.encoding.should == Encoding::US_ASCII end end diff --git a/spec/ruby/language/regexp_spec.rb b/spec/ruby/language/regexp_spec.rb index cd71d543386ae0..ac3f773c492d2e 100644 --- a/spec/ruby/language/regexp_spec.rb +++ b/spec/ruby/language/regexp_spec.rb @@ -20,7 +20,7 @@ ruby_version_is "2.8" do it "is frozen" do - /Hello/.frozen?.should == true + /Hello/.should.frozen? end end diff --git a/spec/ruby/language/string_spec.rb b/spec/ruby/language/string_spec.rb index 68c5fd221b97a6..d19b909cab49de 100644 --- a/spec/ruby/language/string_spec.rb +++ b/spec/ruby/language/string_spec.rb @@ -32,6 +32,11 @@ "#@my_ip".should == 'xxx' end + it "does not interpolate invalid variable names" do + "#@".should == '#@' + "#$%".should == '#$%' + end + it "has characters [.(=?!# end simple # interpolation" do "#@ip[".should == 'xxx[' "#@ip.".should == 'xxx.' @@ -260,6 +265,12 @@ def long_string_literals end describe "Ruby String interpolation" do + it "permits an empty expression" do + s = "#{}" # rubocop:disable Lint/EmptyInterpolation + s.should.empty? + s.should_not.frozen? + end + it "returns a string with the source encoding by default" do "a#{"b"}c".encoding.should == Encoding::BINARY eval('"a#{"b"}c"'.force_encoding("us-ascii")).encoding.should == Encoding::US_ASCII diff --git a/spec/ruby/language/variables_spec.rb b/spec/ruby/language/variables_spec.rb index 7c2c7889f1b6ac..8b67289df4d6bb 100644 --- a/spec/ruby/language/variables_spec.rb +++ b/spec/ruby/language/variables_spec.rb @@ -361,7 +361,7 @@ def obj.to_a end res = *obj res.should == [1,2] - res.frozen?.should == false + res.should_not.frozen? end it "consumes values for an anonymous splat" do diff --git a/spec/ruby/library/bigdecimal/BigDecimal_spec.rb b/spec/ruby/library/bigdecimal/BigDecimal_spec.rb index faa8dc610c96a1..4e839e21a3f4a0 100644 --- a/spec/ruby/library/bigdecimal/BigDecimal_spec.rb +++ b/spec/ruby/library/bigdecimal/BigDecimal_spec.rb @@ -41,7 +41,7 @@ it "ignores leading and trailing whitespace" do BigDecimal(" \t\n \r1234\t\r\n ").should == BigDecimal("1234") - BigDecimal(" \t\n \rNaN \n").nan?.should == true + BigDecimal(" \t\n \rNaN \n").should.nan? BigDecimal(" \t\n \rInfinity \n").infinite?.should == 1 BigDecimal(" \t\n \r-Infinity \n").infinite?.should == -1 end @@ -100,42 +100,42 @@ end it "accepts NaN and [+-]Infinity" do - BigDecimal("NaN").nan?.should == true + BigDecimal("NaN").should.nan? pos_inf = BigDecimal("Infinity") - pos_inf.finite?.should == false + pos_inf.should_not.finite? pos_inf.should > 0 pos_inf.should == BigDecimal("+Infinity") neg_inf = BigDecimal("-Infinity") - neg_inf.finite?.should == false + neg_inf.should_not.finite? neg_inf.should < 0 end describe "accepts NaN and [+-]Infinity as Float values" do it "works without an explicit precision" do - BigDecimal(Float::NAN).nan?.should == true + BigDecimal(Float::NAN).should.nan? pos_inf = BigDecimal(Float::INFINITY) - pos_inf.finite?.should == false + pos_inf.should_not.finite? pos_inf.should > 0 pos_inf.should == BigDecimal("+Infinity") neg_inf = BigDecimal(-Float::INFINITY) - neg_inf.finite?.should == false + neg_inf.should_not.finite? neg_inf.should < 0 end it "works with an explicit precision" do - BigDecimal(Float::NAN, Float::DIG).nan?.should == true + BigDecimal(Float::NAN, Float::DIG).should.nan? pos_inf = BigDecimal(Float::INFINITY, Float::DIG) - pos_inf.finite?.should == false + pos_inf.should_not.finite? pos_inf.should > 0 pos_inf.should == BigDecimal("+Infinity") neg_inf = BigDecimal(-Float::INFINITY, Float::DIG) - neg_inf.finite?.should == false + neg_inf.should_not.finite? neg_inf.should < 0 end end diff --git a/spec/ruby/library/bigdecimal/abs_spec.rb b/spec/ruby/library/bigdecimal/abs_spec.rb index ddd2bae9a9fa8f..95dc45a90589e0 100644 --- a/spec/ruby/library/bigdecimal/abs_spec.rb +++ b/spec/ruby/library/bigdecimal/abs_spec.rb @@ -38,7 +38,7 @@ it "properly handles special values" do @infinity.abs.should == @infinity @infinity_minus.abs.should == @infinity - @nan.abs.nan?.should == true # have to do it this way, since == doesn't work on NaN + @nan.abs.should.nan? # have to do it this way, since == doesn't work on NaN @zero.abs.should == 0 @zero.abs.sign.should == BigDecimal::SIGN_POSITIVE_ZERO @zero_pos.abs.should == 0 diff --git a/spec/ruby/library/bigdecimal/add_spec.rb b/spec/ruby/library/bigdecimal/add_spec.rb index 5b874687fea6a3..bea8b8f7640560 100644 --- a/spec/ruby/library/bigdecimal/add_spec.rb +++ b/spec/ruby/library/bigdecimal/add_spec.rb @@ -136,8 +136,8 @@ end it "returns NaN if NaN is involved" do - @one.add(@nan, 10000).nan?.should == true - @nan.add(@one, 1).nan?.should == true + @one.add(@nan, 10000).should.nan? + @nan.add(@one, 1).should.nan? end it "returns Infinity or -Infinity if these are involved" do @@ -166,8 +166,8 @@ end it "returns NaN if Infinity + (- Infinity)" do - @infinity.add(@infinity_minus, 10000).nan?.should == true - @infinity_minus.add(@infinity, 10000).nan?.should == true + @infinity.add(@infinity_minus, 10000).should.nan? + @infinity_minus.add(@infinity, 10000).should.nan? end it "raises TypeError when adds nil" do diff --git a/spec/ruby/library/bigdecimal/comparison_spec.rb b/spec/ruby/library/bigdecimal/comparison_spec.rb index a1e09b601fbbf6..c53187b727d830 100644 --- a/spec/ruby/library/bigdecimal/comparison_spec.rb +++ b/spec/ruby/library/bigdecimal/comparison_spec.rb @@ -18,7 +18,7 @@ class << @int_mock def coerce(other) return [other, BigDecimal('123')] end - def >= (other) + def >=(other) BigDecimal('123') >= other end end diff --git a/spec/ruby/library/bigdecimal/div_spec.rb b/spec/ruby/library/bigdecimal/div_spec.rb index 0c9eb2ddec6275..53ad6d04184d87 100644 --- a/spec/ruby/library/bigdecimal/div_spec.rb +++ b/spec/ruby/library/bigdecimal/div_spec.rb @@ -80,13 +80,13 @@ end it "returns NaN if zero is divided by zero" do - @zero.div(@zero, 0).nan?.should == true - @zero_minus.div(@zero_plus, 0).nan?.should == true - @zero_plus.div(@zero_minus, 0).nan?.should == true + @zero.div(@zero, 0).should.nan? + @zero_minus.div(@zero_plus, 0).should.nan? + @zero_plus.div(@zero_minus, 0).should.nan? - @zero.div(@zero, 10).nan?.should == true - @zero_minus.div(@zero_plus, 10).nan?.should == true - @zero_plus.div(@zero_minus, 10).nan?.should == true + @zero.div(@zero, 10).should.nan? + @zero_minus.div(@zero_plus, 10).should.nan? + @zero_plus.div(@zero_minus, 10).should.nan? end it "raises FloatDomainError if (+|-) Infinity divided by 1 and no precision given" do @@ -102,8 +102,8 @@ end it "returns NaN if Infinity / ((+|-) Infinity)" do - @infinity.div(@infinity_minus, 100000).nan?.should == true - @infinity_minus.div(@infinity, 1).nan?.should == true + @infinity.div(@infinity_minus, 100000).should.nan? + @infinity_minus.div(@infinity, 1).should.nan? end diff --git a/spec/ruby/library/bigdecimal/divmod_spec.rb b/spec/ruby/library/bigdecimal/divmod_spec.rb index ae8b84983abcac..294f01cba01484 100644 --- a/spec/ruby/library/bigdecimal/divmod_spec.rb +++ b/spec/ruby/library/bigdecimal/divmod_spec.rb @@ -5,8 +5,8 @@ module DivmodSpecs def self.check_both_nan(array) array.length.should == 2 - array[0].nan?.should == true - array[1].nan?.should == true + array[0].should.nan? + array[1].should.nan? end def self.check_both_bigdecimal(array) array.length.should == 2 @@ -150,7 +150,7 @@ class BigDecimal array = @infinity.divmod(val) array.length.should == 2 array[0].infinite?.should == (val > 0 ? 1 : -1) - array[1].nan?.should == true + array[1].should.nan? end end diff --git a/spec/ruby/library/bigdecimal/finite_spec.rb b/spec/ruby/library/bigdecimal/finite_spec.rb index 6685d589b6a307..8fc06029bb3d76 100644 --- a/spec/ruby/library/bigdecimal/finite_spec.rb +++ b/spec/ruby/library/bigdecimal/finite_spec.rb @@ -21,14 +21,14 @@ end it "is false if Infinity or NaN" do - @infinity.finite?.should == false - @infinity_minus.finite?.should == false - @nan.finite?.should == false + @infinity.should_not.finite? + @infinity_minus.should_not.finite? + @nan.should_not.finite? end it "returns true for finite values" do @finite_vals.each do |val| - val.finite?.should == true + val.should.finite? end end end diff --git a/spec/ruby/library/bigdecimal/fix_spec.rb b/spec/ruby/library/bigdecimal/fix_spec.rb index 53b30cbf8beb38..231c9a587e3cae 100644 --- a/spec/ruby/library/bigdecimal/fix_spec.rb +++ b/spec/ruby/library/bigdecimal/fix_spec.rb @@ -34,7 +34,7 @@ it "correctly handles special values" do @infinity.fix.should == @infinity @infinity_neg.fix.should == @infinity_neg - @nan.fix.nan?.should == true + @nan.fix.should.nan? end it "returns 0 if the absolute value is < 1" do diff --git a/spec/ruby/library/bigdecimal/frac_spec.rb b/spec/ruby/library/bigdecimal/frac_spec.rb index 4a023b4ff696a6..11ccf03c2f0606 100644 --- a/spec/ruby/library/bigdecimal/frac_spec.rb +++ b/spec/ruby/library/bigdecimal/frac_spec.rb @@ -42,7 +42,7 @@ it "correctly handles special values" do @infinity.frac.should == @infinity @infinity_neg.frac.should == @infinity_neg - @nan.frac.nan?.should == true + @nan.frac.should.nan? end end diff --git a/spec/ruby/library/bigdecimal/gt_spec.rb b/spec/ruby/library/bigdecimal/gt_spec.rb index 4717cfdd9d670c..78547fb85f152f 100644 --- a/spec/ruby/library/bigdecimal/gt_spec.rb +++ b/spec/ruby/library/bigdecimal/gt_spec.rb @@ -17,7 +17,7 @@ class << @int_mock def coerce(other) return [other, BigDecimal('123')] end - def > (other) + def >(other) BigDecimal('123') > other end end diff --git a/spec/ruby/library/bigdecimal/gte_spec.rb b/spec/ruby/library/bigdecimal/gte_spec.rb index 8dc81707f063eb..2a5cc025ba3821 100644 --- a/spec/ruby/library/bigdecimal/gte_spec.rb +++ b/spec/ruby/library/bigdecimal/gte_spec.rb @@ -17,7 +17,7 @@ class << @int_mock def coerce(other) return [other, BigDecimal('123')] end - def >= (other) + def >=(other) BigDecimal('123') >= other end end diff --git a/spec/ruby/library/bigdecimal/lt_spec.rb b/spec/ruby/library/bigdecimal/lt_spec.rb index 61f4f199120cda..02390e76e33b61 100644 --- a/spec/ruby/library/bigdecimal/lt_spec.rb +++ b/spec/ruby/library/bigdecimal/lt_spec.rb @@ -17,7 +17,7 @@ class << @int_mock def coerce(other) return [other, BigDecimal('123')] end - def < (other) + def <(other) BigDecimal('123') < other end end diff --git a/spec/ruby/library/bigdecimal/lte_spec.rb b/spec/ruby/library/bigdecimal/lte_spec.rb index fc632315f8d5c3..b92be04123f106 100644 --- a/spec/ruby/library/bigdecimal/lte_spec.rb +++ b/spec/ruby/library/bigdecimal/lte_spec.rb @@ -17,7 +17,7 @@ class << @int_mock def coerce(other) return [other, BigDecimal('123')] end - def <= (other) + def <=(other) BigDecimal('123') <= other end end diff --git a/spec/ruby/library/bigdecimal/minus_spec.rb b/spec/ruby/library/bigdecimal/minus_spec.rb index 267a0f7eabbc22..bd3c19584b84b8 100644 --- a/spec/ruby/library/bigdecimal/minus_spec.rb +++ b/spec/ruby/library/bigdecimal/minus_spec.rb @@ -26,18 +26,18 @@ end it "returns NaN if NaN is involved" do - (@one - @nan).nan?.should == true - (@nan - @one).nan?.should == true - (@nan - @nan).nan?.should == true - (@nan - @infinity).nan?.should == true - (@nan - @infinity_minus).nan?.should == true - (@infinity - @nan).nan?.should == true - (@infinity_minus - @nan).nan?.should == true + (@one - @nan).should.nan? + (@nan - @one).should.nan? + (@nan - @nan).should.nan? + (@nan - @infinity).should.nan? + (@nan - @infinity_minus).should.nan? + (@infinity - @nan).should.nan? + (@infinity_minus - @nan).should.nan? end it "returns NaN both operands are infinite with the same sign" do - (@infinity - @infinity).nan?.should == true - (@infinity_minus - @infinity_minus).nan?.should == true + (@infinity - @infinity).should.nan? + (@infinity_minus - @infinity_minus).should.nan? end it "returns Infinity or -Infinity if these are involved" do diff --git a/spec/ruby/library/bigdecimal/mode_spec.rb b/spec/ruby/library/bigdecimal/mode_spec.rb index f57028ae5dd600..73fa1a118eaf41 100644 --- a/spec/ruby/library/bigdecimal/mode_spec.rb +++ b/spec/ruby/library/bigdecimal/mode_spec.rb @@ -12,7 +12,7 @@ end it "returns the appropriate value and continue the computation if the flag is false" do - BigDecimal("NaN").add(BigDecimal("1"),0).nan?.should == true + BigDecimal("NaN").add(BigDecimal("1"),0).should.nan? BigDecimal("0").add(BigDecimal("Infinity"),0).should == BigDecimal("Infinity") BigDecimal("1").quo(BigDecimal("0")).should == BigDecimal("Infinity") end diff --git a/spec/ruby/library/bigdecimal/nan_spec.rb b/spec/ruby/library/bigdecimal/nan_spec.rb index 705492614bd7a4..9eaf69b6106c00 100644 --- a/spec/ruby/library/bigdecimal/nan_spec.rb +++ b/spec/ruby/library/bigdecimal/nan_spec.rb @@ -4,20 +4,20 @@ describe "BigDecimal#nan?" do it "returns true if self is not a number" do - BigDecimal("NaN").nan?.should == true + BigDecimal("NaN").should.nan? end it "returns false if self is not a NaN" do - BigDecimal("Infinity").nan?.should == false - BigDecimal("-Infinity").nan?.should == false - BigDecimal("0").nan?.should == false - BigDecimal("+0").nan?.should == false - BigDecimal("-0").nan?.should == false - BigDecimal("2E40001").nan?.should == false - BigDecimal("3E-20001").nan?.should == false - BigDecimal("0E-200000000").nan?.should == false - BigDecimal("0E200000000000").nan?.should == false - BigDecimal("0.000000000000000000000000").nan?.should == false + BigDecimal("Infinity").should_not.nan? + BigDecimal("-Infinity").should_not.nan? + BigDecimal("0").should_not.nan? + BigDecimal("+0").should_not.nan? + BigDecimal("-0").should_not.nan? + BigDecimal("2E40001").should_not.nan? + BigDecimal("3E-20001").should_not.nan? + BigDecimal("0E-200000000").should_not.nan? + BigDecimal("0E200000000000").should_not.nan? + BigDecimal("0.000000000000000000000000").should_not.nan? end end diff --git a/spec/ruby/library/bigdecimal/plus_spec.rb b/spec/ruby/library/bigdecimal/plus_spec.rb index cefc43aeaa8c46..d1934841c8ded7 100644 --- a/spec/ruby/library/bigdecimal/plus_spec.rb +++ b/spec/ruby/library/bigdecimal/plus_spec.rb @@ -30,8 +30,8 @@ end it "returns NaN if NaN is involved" do - (@one + @nan).nan?.should == true - (@nan + @one).nan?.should == true + (@one + @nan).should.nan? + (@nan + @one).should.nan? end it "returns Infinity or -Infinity if these are involved" do @@ -41,7 +41,7 @@ end it "returns NaN if Infinity + (- Infinity)" do - (@infinity + @infinity_minus).nan?.should == true + (@infinity + @infinity_minus).should.nan? end describe "with Object" do diff --git a/spec/ruby/library/bigdecimal/precs_spec.rb b/spec/ruby/library/bigdecimal/precs_spec.rb index f9320f2b9ee787..78a62341e80aa1 100644 --- a/spec/ruby/library/bigdecimal/precs_spec.rb +++ b/spec/ruby/library/bigdecimal/precs_spec.rb @@ -40,7 +40,7 @@ it "returns the maximum number of significant digits as the second value" do BigDecimal("3.14159").precs[1].should >= 6 BigDecimal('1').precs[1].should >= 1 - BigDecimal('1' + '0' * 100).precs[1] >= 101 + BigDecimal('1' + '0' * 100).precs[1].should >= 101 [@infinity, @infinity_neg, @nan, @zero, @zero_neg].each do |value| value.precs[1].should >= 1 end diff --git a/spec/ruby/library/bigdecimal/quo_spec.rb b/spec/ruby/library/bigdecimal/quo_spec.rb index a5c56517787302..65a4330303d5ef 100644 --- a/spec/ruby/library/bigdecimal/quo_spec.rb +++ b/spec/ruby/library/bigdecimal/quo_spec.rb @@ -6,7 +6,7 @@ it_behaves_like :bigdecimal_quo, :quo, [] it "returns NaN if NaN is involved" do - BigDecimal("1").quo(BigDecimal("NaN")).nan?.should == true - BigDecimal("NaN").quo(BigDecimal("1")).nan?.should == true + BigDecimal("1").quo(BigDecimal("NaN")).should.nan? + BigDecimal("NaN").quo(BigDecimal("1")).should.nan? end end diff --git a/spec/ruby/library/bigdecimal/remainder_spec.rb b/spec/ruby/library/bigdecimal/remainder_spec.rb index 04233edece7565..1866f665cd326f 100644 --- a/spec/ruby/library/bigdecimal/remainder_spec.rb +++ b/spec/ruby/library/bigdecimal/remainder_spec.rb @@ -38,8 +38,8 @@ end it "returns NaN used with zero" do - @mixed.remainder(@zero).nan?.should == true - @zero.remainder(@zero).nan?.should == true + @mixed.remainder(@zero).should.nan? + @zero.remainder(@zero).should.nan? end it "returns zero if used on zero" do @@ -47,28 +47,28 @@ end it "returns NaN if NaN is involved" do - @nan.remainder(@nan).nan?.should == true - @nan.remainder(@one).nan?.should == true - @one.remainder(@nan).nan?.should == true - @infinity.remainder(@nan).nan?.should == true - @nan.remainder(@infinity).nan?.should == true + @nan.remainder(@nan).should.nan? + @nan.remainder(@one).should.nan? + @one.remainder(@nan).should.nan? + @infinity.remainder(@nan).should.nan? + @nan.remainder(@infinity).should.nan? end it "returns NaN if Infinity is involved" do - @infinity.remainder(@infinity).nan?.should == true - @infinity.remainder(@one).nan?.should == true - @infinity.remainder(@mixed).nan?.should == true - @infinity.remainder(@one_minus).nan?.should == true - @infinity.remainder(@frac_1).nan?.should == true - @one.remainder(@infinity).nan?.should == true + @infinity.remainder(@infinity).should.nan? + @infinity.remainder(@one).should.nan? + @infinity.remainder(@mixed).should.nan? + @infinity.remainder(@one_minus).should.nan? + @infinity.remainder(@frac_1).should.nan? + @one.remainder(@infinity).should.nan? - @infinity_minus.remainder(@infinity_minus).nan?.should == true - @infinity_minus.remainder(@one).nan?.should == true - @one.remainder(@infinity_minus).nan?.should == true - @frac_2.remainder(@infinity_minus).nan?.should == true + @infinity_minus.remainder(@infinity_minus).should.nan? + @infinity_minus.remainder(@one).should.nan? + @one.remainder(@infinity_minus).should.nan? + @frac_2.remainder(@infinity_minus).should.nan? - @infinity.remainder(@infinity_minus).nan?.should == true - @infinity_minus.remainder(@infinity).nan?.should == true + @infinity.remainder(@infinity_minus).should.nan? + @infinity_minus.remainder(@infinity).should.nan? end it "coerces arguments to BigDecimal if possible" do diff --git a/spec/ruby/library/bigdecimal/shared/modulo.rb b/spec/ruby/library/bigdecimal/shared/modulo.rb index 67c0ecf2fccc59..aa5c5a640b2cc2 100644 --- a/spec/ruby/library/bigdecimal/shared/modulo.rb +++ b/spec/ruby/library/bigdecimal/shared/modulo.rb @@ -80,25 +80,25 @@ end it "returns NaN if NaN is involved" do - @nan.send(@method, @nan).nan?.should == true - @nan.send(@method, @one).nan?.should == true - @one.send(@method, @nan).nan?.should == true - @infinity.send(@method, @nan).nan?.should == true - @nan.send(@method, @infinity).nan?.should == true + @nan.send(@method, @nan).should.nan? + @nan.send(@method, @one).should.nan? + @one.send(@method, @nan).should.nan? + @infinity.send(@method, @nan).should.nan? + @nan.send(@method, @infinity).should.nan? end it "returns NaN if the dividend is Infinity" do - @infinity.send(@method, @infinity).nan?.should == true - @infinity.send(@method, @one).nan?.should == true - @infinity.send(@method, @mixed).nan?.should == true - @infinity.send(@method, @one_minus).nan?.should == true - @infinity.send(@method, @frac_1).nan?.should == true + @infinity.send(@method, @infinity).should.nan? + @infinity.send(@method, @one).should.nan? + @infinity.send(@method, @mixed).should.nan? + @infinity.send(@method, @one_minus).should.nan? + @infinity.send(@method, @frac_1).should.nan? - @infinity_minus.send(@method, @infinity_minus).nan?.should == true - @infinity_minus.send(@method, @one).nan?.should == true + @infinity_minus.send(@method, @infinity_minus).should.nan? + @infinity_minus.send(@method, @one).should.nan? - @infinity.send(@method, @infinity_minus).nan?.should == true - @infinity_minus.send(@method, @infinity).nan?.should == true + @infinity.send(@method, @infinity_minus).should.nan? + @infinity_minus.send(@method, @infinity).should.nan? end it "returns the dividend if the divisor is Infinity" do diff --git a/spec/ruby/library/bigdecimal/shared/mult.rb b/spec/ruby/library/bigdecimal/shared/mult.rb index b94c9385de73b8..c613df04c47683 100644 --- a/spec/ruby/library/bigdecimal/shared/mult.rb +++ b/spec/ruby/library/bigdecimal/shared/mult.rb @@ -51,8 +51,8 @@ values = @regular_vals + @zeroes values.each do |val| - @nan.send(@method, val, *@object).nan?.should == true - val.send(@method, @nan, *@object).nan?.should == true + @nan.send(@method, val, *@object).should.nan? + val.send(@method, @nan, *@object).should.nan? end end @@ -62,9 +62,9 @@ values.each do |val| @zeroes.each do |zero| zero.send(@method, val, *@object).should == 0 - zero.send(@method, val, *@object).zero?.should == true + zero.send(@method, val, *@object).should.zero? val.send(@method, zero, *@object).should == 0 - val.send(@method, zero, *@object).zero?.should == true + val.send(@method, zero, *@object).should.zero? end end end @@ -75,8 +75,8 @@ values.each do |val| infs.each do |inf| - inf.send(@method, val, *@object).finite?.should == false - val.send(@method, inf, *@object).finite?.should == false + inf.send(@method, val, *@object).should_not.finite? + val.send(@method, inf, *@object).should_not.finite? end end @@ -89,9 +89,9 @@ end it "returns NaN if the result is undefined" do - @zero.send(@method, @infinity, *@object).nan?.should == true - @zero.send(@method, @infinity_minus, *@object).nan?.should == true - @infinity.send(@method, @zero, *@object).nan?.should == true - @infinity_minus.send(@method, @zero, *@object).nan?.should == true + @zero.send(@method, @infinity, *@object).should.nan? + @zero.send(@method, @infinity_minus, *@object).should.nan? + @infinity.send(@method, @zero, *@object).should.nan? + @infinity_minus.send(@method, @zero, *@object).should.nan? end end diff --git a/spec/ruby/library/bigdecimal/shared/power.rb b/spec/ruby/library/bigdecimal/shared/power.rb index a4848fb2e2b6c4..568a08589b494f 100644 --- a/spec/ruby/library/bigdecimal/shared/power.rb +++ b/spec/ruby/library/bigdecimal/shared/power.rb @@ -53,8 +53,8 @@ end it "returns NaN if self is NaN" do - BigDecimal("NaN").send(@method, -5).nan?.should == true - BigDecimal("NaN").send(@method, 5).nan?.should == true + BigDecimal("NaN").send(@method, -5).should.nan? + BigDecimal("NaN").send(@method, 5).should.nan? end it "returns 0.0 if self is infinite and argument is negative" do diff --git a/spec/ruby/library/bigdecimal/shared/quo.rb b/spec/ruby/library/bigdecimal/shared/quo.rb index 4d6d64b7870b5d..46e6d62bf4bffd 100644 --- a/spec/ruby/library/bigdecimal/shared/quo.rb +++ b/spec/ruby/library/bigdecimal/shared/quo.rb @@ -49,8 +49,8 @@ end it "returns NaN if Infinity / ((+|-) Infinity)" do - @infinity.send(@method, @infinity_minus, *@object).nan?.should == true - @infinity_minus.send(@method, @infinity, *@object).nan?.should == true + @infinity.send(@method, @infinity_minus, *@object).should.nan? + @infinity_minus.send(@method, @infinity, *@object).should.nan? end it "returns (+|-) Infinity if divided by zero" do @@ -60,8 +60,8 @@ end it "returns NaN if zero is divided by zero" do - @zero.send(@method, @zero, *@object).nan?.should == true - @zero_minus.send(@method, @zero_plus, *@object).nan?.should == true - @zero_plus.send(@method, @zero_minus, *@object).nan?.should == true + @zero.send(@method, @zero, *@object).should.nan? + @zero_minus.send(@method, @zero_plus, *@object).should.nan? + @zero_plus.send(@method, @zero_minus, *@object).should.nan? end end diff --git a/spec/ruby/library/bigdecimal/sub_spec.rb b/spec/ruby/library/bigdecimal/sub_spec.rb index 29ec851193e1d5..bddfec2186d6a4 100644 --- a/spec/ruby/library/bigdecimal/sub_spec.rb +++ b/spec/ruby/library/bigdecimal/sub_spec.rb @@ -50,13 +50,13 @@ end it "returns NaN if NaN is involved" do - @one.sub(@nan, 1).nan?.should == true - @nan.sub(@one, 1).nan?.should == true + @one.sub(@nan, 1).should.nan? + @nan.sub(@one, 1).should.nan? end it "returns NaN if both values are infinite with the same signs" do - @infinity.sub(@infinity, 1).nan?.should == true - @infinity_minus.sub(@infinity_minus, 1).nan?.should == true + @infinity.sub(@infinity, 1).should.nan? + @infinity_minus.sub(@infinity_minus, 1).should.nan? end it "returns Infinity or -Infinity if these are involved" do diff --git a/spec/ruby/library/bigdecimal/to_f_spec.rb b/spec/ruby/library/bigdecimal/to_f_spec.rb index 1cc25d5c40c97c..84d4d49de23c15 100644 --- a/spec/ruby/library/bigdecimal/to_f_spec.rb +++ b/spec/ruby/library/bigdecimal/to_f_spec.rb @@ -41,7 +41,7 @@ @zero.to_f.should == 0 @zero.to_f.to_s.should == "0.0" - @nan.to_f.nan?.should == true + @nan.to_f.should.nan? @infinity.to_f.infinite?.should == 1 @infinity_minus.to_f.infinite?.should == -1 diff --git a/spec/ruby/library/bigdecimal/truncate_spec.rb b/spec/ruby/library/bigdecimal/truncate_spec.rb index d3a15f62c749e7..4ad9eb92d1e760 100644 --- a/spec/ruby/library/bigdecimal/truncate_spec.rb +++ b/spec/ruby/library/bigdecimal/truncate_spec.rb @@ -58,9 +58,9 @@ end it "returns NaN if self is NaN" do - @nan.truncate(-1).nan?.should == true - @nan.truncate(+1).nan?.should == true - @nan.truncate(0).nan?.should == true + @nan.truncate(-1).should.nan? + @nan.truncate(+1).should.nan? + @nan.truncate(0).should.nan? end it "returns Infinity if self is infinite" do diff --git a/spec/ruby/library/bigdecimal/uminus_spec.rb b/spec/ruby/library/bigdecimal/uminus_spec.rb index 5e2a786c4c66b6..c780cdfac5acae 100644 --- a/spec/ruby/library/bigdecimal/uminus_spec.rb +++ b/spec/ruby/library/bigdecimal/uminus_spec.rb @@ -53,6 +53,6 @@ @zero_neg.send(:-@).should == @zero @zero_neg.send(:-@).sign.should == 1 - @nan.send(:-@).nan?.should == true + @nan.send(:-@).should.nan? end end diff --git a/spec/ruby/library/bigdecimal/zero_spec.rb b/spec/ruby/library/bigdecimal/zero_spec.rb index c5d3acb8c3c56a..2563210939e251 100644 --- a/spec/ruby/library/bigdecimal/zero_spec.rb +++ b/spec/ruby/library/bigdecimal/zero_spec.rb @@ -6,22 +6,22 @@ it "returns true if self does equal zero" do really_small_zero = BigDecimal("0E-200000000") really_big_zero = BigDecimal("0E200000000000") - really_small_zero.zero?.should == true - really_big_zero.zero?.should == true - BigDecimal("0.000000000000000000000000").zero?.should == true - BigDecimal("0").zero?.should == true - BigDecimal("0E0").zero?.should == true - BigDecimal("+0").zero?.should == true - BigDecimal("-0").zero?.should == true + really_small_zero.should.zero? + really_big_zero.should.zero? + BigDecimal("0.000000000000000000000000").should.zero? + BigDecimal("0").should.zero? + BigDecimal("0E0").should.zero? + BigDecimal("+0").should.zero? + BigDecimal("-0").should.zero? end it "returns false otherwise" do - BigDecimal("0000000001").zero?.should == false - BigDecimal("2E40001").zero?.should == false - BigDecimal("3E-20001").zero?.should == false - BigDecimal("Infinity").zero?.should == false - BigDecimal("-Infinity").zero?.should == false - BigDecimal("NaN").zero?.should == false + BigDecimal("0000000001").should_not.zero? + BigDecimal("2E40001").should_not.zero? + BigDecimal("3E-20001").should_not.zero? + BigDecimal("Infinity").should_not.zero? + BigDecimal("-Infinity").should_not.zero? + BigDecimal("NaN").should_not.zero? end end diff --git a/spec/ruby/library/conditionvariable/signal_spec.rb b/spec/ruby/library/conditionvariable/signal_spec.rb index 11e49095013a08..86383073f1bde2 100644 --- a/spec/ruby/library/conditionvariable/signal_spec.rb +++ b/spec/ruby/library/conditionvariable/signal_spec.rb @@ -72,6 +72,6 @@ # Check that both threads terminated without exception t1.join t2.join - m.locked?.should == false + m.should_not.locked? end end diff --git a/spec/ruby/library/csv/liberal_parsing_spec.rb b/spec/ruby/library/csv/liberal_parsing_spec.rb index 2929d6e2aa7aa8..98786580271979 100644 --- a/spec/ruby/library/csv/liberal_parsing_spec.rb +++ b/spec/ruby/library/csv/liberal_parsing_spec.rb @@ -4,16 +4,16 @@ describe "CSV#liberal_parsing?" do it "returns true if illegal input is handled" do csv = CSV.new("", liberal_parsing: true) - csv.liberal_parsing?.should == true + csv.should.liberal_parsing? end it "returns false if illegal input is not handled" do csv = CSV.new("", liberal_parsing: false) - csv.liberal_parsing?.should == false + csv.should_not.liberal_parsing? end it "returns false by default" do csv = CSV.new("") - csv.liberal_parsing?.should == false + csv.should_not.liberal_parsing? end end diff --git a/spec/ruby/library/date/gregorian_spec.rb b/spec/ruby/library/date/gregorian_spec.rb index 8b7033fe754ffe..ea7ece2adef4f3 100644 --- a/spec/ruby/library/date/gregorian_spec.rb +++ b/spec/ruby/library/date/gregorian_spec.rb @@ -9,7 +9,7 @@ end it "marks a day after the calendar reform as Julian" do - Date.civil(2007, 2, 27).gregorian?.should == true + Date.civil(2007, 2, 27).should.gregorian? Date.civil(1607, 2, 27, Date.civil(1582, 1, 1).jd).gregorian?.should be_true end diff --git a/spec/ruby/library/date/infinity_spec.rb b/spec/ruby/library/date/infinity_spec.rb index 81d67ae249e774..721fd760664ecc 100644 --- a/spec/ruby/library/date/infinity_spec.rb +++ b/spec/ruby/library/date/infinity_spec.rb @@ -5,16 +5,16 @@ it "should be able to check whether Infinity is zero" do i = Date::Infinity.new - i.zero?.should == false + i.should_not.zero? end it "should be able to check whether Infinity is finite" do i1 = Date::Infinity.new - i1.finite?.should == false + i1.should_not.finite? i2 = Date::Infinity.new(-1) - i2.finite?.should == false + i2.should_not.finite? i3 = Date::Infinity.new(0) - i3.finite?.should == false + i3.should_not.finite? end it "should be able to check whether Infinity is infinite" do @@ -28,11 +28,11 @@ it "should be able to check whether Infinity is not a number" do i1 = Date::Infinity.new - i1.nan?.should == false + i1.should_not.nan? i2 = Date::Infinity.new(-1) - i2.nan?.should == false + i2.should_not.nan? i3 = Date::Infinity.new(0) - i3.nan?.should == true + i3.should.nan? end it "should be able to compare Infinity objects" do diff --git a/spec/ruby/library/date/julian_spec.rb b/spec/ruby/library/date/julian_spec.rb index 637a4739e5f519..db2629d1e733b6 100644 --- a/spec/ruby/library/date/julian_spec.rb +++ b/spec/ruby/library/date/julian_spec.rb @@ -4,12 +4,12 @@ describe "Date#julian?" do it "marks a day before the calendar reform as Julian" do - Date.civil(1007, 2, 27).julian?.should == true + Date.civil(1007, 2, 27).should.julian? Date.civil(1907, 2, 27, Date.civil(1930, 1, 1).jd).julian?.should be_true end it "marks a day after the calendar reform as Julian" do - Date.civil(2007, 2, 27).julian?.should == false + Date.civil(2007, 2, 27).should_not.julian? Date.civil(1607, 2, 27, Date.civil(1582, 1, 1).jd).julian?.should be_false end diff --git a/spec/ruby/library/date/shared/civil.rb b/spec/ruby/library/date/shared/civil.rb index 4c8ba23622def2..bbed4a88662eb4 100644 --- a/spec/ruby/library/date/shared/civil.rb +++ b/spec/ruby/library/date/shared/civil.rb @@ -5,7 +5,7 @@ d.year.should == -4712 d.month.should == 1 d.day.should == 1 - d.julian?.should == true + d.should.julian? d.jd.should == 0 end @@ -14,7 +14,7 @@ d.year.should == 2000 d.month.should == 3 d.day.should == 5 - d.julian?.should == false + d.should_not.julian? d.jd.should == 2451609 # Should also work with years far in the past and future @@ -23,14 +23,14 @@ d.year.should == -9000 d.month.should == 7 d.day.should == 5 - d.julian?.should == true + d.should.julian? d.jd.should == -1566006 d = Date.send(@method, 9000, 10, 14) d.year.should == 9000 d.month.should == 10 d.day.should == 14 - d.julian?.should == false + d.should_not.julian? d.jd.should == 5008529 end diff --git a/spec/ruby/library/getoptlong/terminated_spec.rb b/spec/ruby/library/getoptlong/terminated_spec.rb index 01a8feddeade89..6108a7f6e908e8 100644 --- a/spec/ruby/library/getoptlong/terminated_spec.rb +++ b/spec/ruby/library/getoptlong/terminated_spec.rb @@ -5,13 +5,13 @@ it "returns true if option processing has terminated" do argv [ "--size", "10k" ] do opts = GetoptLong.new(["--size", GetoptLong::REQUIRED_ARGUMENT]) - opts.terminated?.should == false + opts.should_not.terminated? opts.get.should == ["--size", "10k"] - opts.terminated?.should == false + opts.should_not.terminated? opts.get.should == nil - opts.terminated?.should == true + opts.should.terminated? end end end diff --git a/spec/ruby/library/ipaddr/ipv4_conversion_spec.rb b/spec/ruby/library/ipaddr/ipv4_conversion_spec.rb index 9d45055d76840c..1128c16dd20b0e 100644 --- a/spec/ruby/library/ipaddr/ipv4_conversion_spec.rb +++ b/spec/ruby/library/ipaddr/ipv4_conversion_spec.rb @@ -8,11 +8,11 @@ a.to_s.should == "::192.168.1.2" a.to_string.should == "0000:0000:0000:0000:0000:0000:c0a8:0102" a.family.should == Socket::AF_INET6 - a.ipv4_compat?.should == true + a.should.ipv4_compat? b = a.native b.to_s.should == "192.168.1.2" b.family.should == Socket::AF_INET - b.ipv4_compat?.should == false + b.should_not.ipv4_compat? a = IPAddr.new("192.168.1.2") b = a.ipv4_compat @@ -29,11 +29,11 @@ a.to_s.should == "::ffff:192.168.1.2" a.to_string.should == "0000:0000:0000:0000:0000:ffff:c0a8:0102" a.family.should == Socket::AF_INET6 - a.ipv4_mapped?.should == true + a.should.ipv4_mapped? b = a.native b.to_s.should == "192.168.1.2" b.family.should == Socket::AF_INET - b.ipv4_mapped?.should == false + b.should_not.ipv4_mapped? a = IPAddr.new("192.168.1.2") b = a.ipv4_mapped diff --git a/spec/ruby/library/ipaddr/new_spec.rb b/spec/ruby/library/ipaddr/new_spec.rb index c8c8bc80b3d0df..3148d6e39ca46e 100644 --- a/spec/ruby/library/ipaddr/new_spec.rb +++ b/spec/ruby/library/ipaddr/new_spec.rb @@ -27,8 +27,8 @@ a.to_s.should == "3ffe:505:2::" a.to_string.should == "3ffe:0505:0002:0000:0000:0000:0000:0000" a.family.should == Socket::AF_INET6 - a.ipv4?.should == false - a.ipv6?.should == true + a.should_not.ipv4? + a.should.ipv6? a.inspect.should == "#" end @@ -51,8 +51,8 @@ a.to_s.should == "192.168.1.2" a.to_string.should == "192.168.1.2" a.family.should == Socket::AF_INET - a.ipv4?.should == true - a.ipv6?.should == false + a.should.ipv4? + a.should_not.ipv6? end it "initializes IPAddr ipv4 address with / subnet notation" do diff --git a/spec/ruby/library/logger/logger/debug_spec.rb b/spec/ruby/library/logger/logger/debug_spec.rb index d92c3392324f41..9375ab0cc6a9b2 100644 --- a/spec/ruby/library/logger/logger/debug_spec.rb +++ b/spec/ruby/library/logger/logger/debug_spec.rb @@ -16,12 +16,12 @@ it "returns true if severity level allows debug messages" do @logger.level = Logger::DEBUG - @logger.debug?.should == true + @logger.should.debug? end it "returns false if severity level does not allow debug messages" do @logger.level = Logger::WARN - @logger.debug?.should == false + @logger.should_not.debug? end end diff --git a/spec/ruby/library/logger/logger/error_spec.rb b/spec/ruby/library/logger/logger/error_spec.rb index d5d0bd2d2f35dd..42f1dbd8832693 100644 --- a/spec/ruby/library/logger/logger/error_spec.rb +++ b/spec/ruby/library/logger/logger/error_spec.rb @@ -16,12 +16,12 @@ it "returns true if severity level allows printing errors" do @logger.level = Logger::INFO - @logger.error?.should == true + @logger.should.error? end it "returns false if severity level does not allow errors" do @logger.level = Logger::FATAL - @logger.error?.should == false + @logger.should_not.error? end end diff --git a/spec/ruby/library/logger/logger/fatal_spec.rb b/spec/ruby/library/logger/logger/fatal_spec.rb index 42d4341319286a..f12fa3a89fa9f3 100644 --- a/spec/ruby/library/logger/logger/fatal_spec.rb +++ b/spec/ruby/library/logger/logger/fatal_spec.rb @@ -16,12 +16,12 @@ it "returns true if severity level allows fatal messages" do @logger.level = Logger::FATAL - @logger.fatal?.should == true + @logger.should.fatal? end it "returns false if severity level does not allow fatal messages" do @logger.level = Logger::UNKNOWN - @logger.fatal?.should == false + @logger.should_not.fatal? end end diff --git a/spec/ruby/library/logger/logger/info_spec.rb b/spec/ruby/library/logger/logger/info_spec.rb index 21eacbbb318118..eb5dca48dd170b 100644 --- a/spec/ruby/library/logger/logger/info_spec.rb +++ b/spec/ruby/library/logger/logger/info_spec.rb @@ -16,12 +16,12 @@ it "returns true if severity level allows info messages" do @logger.level = Logger::INFO - @logger.info?.should == true + @logger.should.info? end it "returns false if severity level does not allow info messages" do @logger.level = Logger::FATAL - @logger.info?.should == false + @logger.should_not.info? end end diff --git a/spec/ruby/library/logger/logger/warn_spec.rb b/spec/ruby/library/logger/logger/warn_spec.rb index 6617b2b41a624b..0bca34824ade69 100644 --- a/spec/ruby/library/logger/logger/warn_spec.rb +++ b/spec/ruby/library/logger/logger/warn_spec.rb @@ -16,12 +16,12 @@ it "returns true if severity level allows printing warn messages" do @logger.level = Logger::WARN - @logger.warn?.should == true + @logger.should.warn? end it "returns false if severity level does not allow printing warn messages" do @logger.level = Logger::FATAL - @logger.warn?.should == false + @logger.should_not.warn? end end diff --git a/spec/ruby/library/matrix/normal_spec.rb b/spec/ruby/library/matrix/normal_spec.rb index ebd73aaf405714..a9e6c645faf75e 100644 --- a/spec/ruby/library/matrix/normal_spec.rb +++ b/spec/ruby/library/matrix/normal_spec.rb @@ -3,12 +3,12 @@ describe "Matrix.normal?" do # it "returns false for non normal matrices" do - # Matrix[[0, 1], [1, 2]].normal?.should == false + # Matrix[[0, 1], [1, 2]].should_not.normal? # end it "returns true for normal matrices" do - Matrix[[1, 1, 0], [0, 1, 1], [1, 0, 1]].normal?.should == true - Matrix[[0, Complex(0, 2)], [Complex(0, -2), 0]].normal?.should == true + Matrix[[1, 1, 0], [0, 1, 1], [1, 0, 1]].should.normal? + Matrix[[0, Complex(0, 2)], [Complex(0, -2), 0]].should.normal? end it "raises an error for rectangular matrices" do diff --git a/spec/ruby/library/matrix/orthogonal_spec.rb b/spec/ruby/library/matrix/orthogonal_spec.rb index 07b098a58d51e0..26afe89ff08e75 100644 --- a/spec/ruby/library/matrix/orthogonal_spec.rb +++ b/spec/ruby/library/matrix/orthogonal_spec.rb @@ -3,12 +3,12 @@ describe "Matrix.orthogonal?" do it "returns false for non orthogonal matrices" do - Matrix[[0, 1], [1, 2]].orthogonal?.should == false - Matrix[[1, 1, 0], [0, 1, 1], [1, 0, 1]].orthogonal?.should == false + Matrix[[0, 1], [1, 2]].should_not.orthogonal? + Matrix[[1, 1, 0], [0, 1, 1], [1, 0, 1]].should_not.orthogonal? end it "returns true for orthogonal matrices" do - Matrix[[0, 1], [1, 0]].orthogonal?.should == true + Matrix[[0, 1], [1, 0]].should.orthogonal? end it "raises an error for rectangular matrices" do diff --git a/spec/ruby/library/matrix/unitary_spec.rb b/spec/ruby/library/matrix/unitary_spec.rb index 9c2a106ea55eb9..af4b2bb442857e 100644 --- a/spec/ruby/library/matrix/unitary_spec.rb +++ b/spec/ruby/library/matrix/unitary_spec.rb @@ -3,14 +3,19 @@ describe "Matrix.unitary?" do it "returns false for non unitary matrices" do - Matrix[[0, 1], [1, 2]].unitary?.should == false - Matrix[[0, Complex(0, 2)], [Complex(0, 2), 0]].unitary?.should == false - Matrix[[0, Complex(0, 1)], [Complex(0, -1), 0]].unitary?.should == false - Matrix[[1, 1, 0], [0, 1, 1], [1, 0, 1]].unitary?.should == false + Matrix[[0, 1], [1, 2]].should_not.unitary? + Matrix[[0, Complex(0, 2)], [Complex(0, 2), 0]].should_not.unitary? + Matrix[[1, 1, 0], [0, 1, 1], [1, 0, 1]].should_not.unitary? end it "returns true for unitary matrices" do - Matrix[[0, Complex(0, 1)], [Complex(0, 1), 0]].unitary?.should == true + Matrix[[0, Complex(0, 1)], [Complex(0, 1), 0]].should.unitary? + end + + version_is((Matrix::const_defined?(:VERSION) ? Matrix::VERSION : "0.1.0"), "0.3.0") do + it "returns true for unitary matrices with a Complex and a negative #imag" do + Matrix[[0, Complex(0, 1)], [Complex(0, -1), 0]].should.unitary? + end end it "raises an error for rectangular matrices" do diff --git a/spec/ruby/library/matrix/zero_spec.rb b/spec/ruby/library/matrix/zero_spec.rb index 643c57acba1ce2..68e8567c260256 100644 --- a/spec/ruby/library/matrix/zero_spec.rb +++ b/spec/ruby/library/matrix/zero_spec.rb @@ -37,16 +37,16 @@ describe "Matrix.zero?" do it "returns true for empty matrices" do - Matrix.empty.zero?.should == true - Matrix.empty(3,0).zero?.should == true - Matrix.empty(0,3).zero?.should == true + Matrix.empty.should.zero? + Matrix.empty(3,0).should.zero? + Matrix.empty(0,3).should.zero? end it "returns true for matrices with zero entries" do - Matrix.zero(2,3).zero?.should == true + Matrix.zero(2,3).should.zero? end it "returns false for matrices with non zero entries" do - Matrix[[1]].zero?.should == false + Matrix[[1]].should_not.zero? end end diff --git a/spec/ruby/library/net/http/http/fixtures/http_server.rb b/spec/ruby/library/net/http/http/fixtures/http_server.rb index 49e8f437ccf39b..aeb0babda19564 100644 --- a/spec/ruby/library/net/http/http/fixtures/http_server.rb +++ b/spec/ruby/library/net/http/http/fixtures/http_server.rb @@ -53,10 +53,10 @@ def reply(req, res) end end - class << self - @server = nil - @server_thread = nil + @server = nil + @server_thread = nil + class << self def port raise "server not started" unless @server @server.config[:Port] @@ -89,8 +89,12 @@ def stop_server if @server begin @server.shutdown - rescue Errno::EPIPE + rescue Errno::EPIPE, Errno::EBADF # Because WEBrick is not thread-safe and only catches IOError + + # EBADF can happen because WEBrick @server_thread concurrently closes the shutdown pipe + # once @status = :Shutdown, while the current thread does write_nonblock("\0"). + # On MRI this EBADF is replaced by IOError due to the GIL around both #close and #write_nonblock. end @server = nil end diff --git a/spec/ruby/library/net/http/httpresponse/body_permitted_spec.rb b/spec/ruby/library/net/http/httpresponse/body_permitted_spec.rb index 68a0454f79974b..8ade46689fa9b1 100644 --- a/spec/ruby/library/net/http/httpresponse/body_permitted_spec.rb +++ b/spec/ruby/library/net/http/httpresponse/body_permitted_spec.rb @@ -3,11 +3,11 @@ describe "Net::HTTPResponse.body_permitted?" do it "returns true if this response type can have a response body" do - Net::HTTPUnknownResponse.body_permitted?.should == true - Net::HTTPInformation.body_permitted?.should == false - Net::HTTPSuccess.body_permitted?.should == true - Net::HTTPRedirection.body_permitted?.should == true - Net::HTTPClientError.body_permitted?.should == true - Net::HTTPServerError.body_permitted?.should == true + Net::HTTPUnknownResponse.should.body_permitted? + Net::HTTPInformation.should_not.body_permitted? + Net::HTTPSuccess.should.body_permitted? + Net::HTTPRedirection.should.body_permitted? + Net::HTTPClientError.should.body_permitted? + Net::HTTPServerError.should.body_permitted? end end diff --git a/spec/ruby/library/pathname/absolute_spec.rb b/spec/ruby/library/pathname/absolute_spec.rb index dce3ae72eee10d..109abb8ee9e49b 100644 --- a/spec/ruby/library/pathname/absolute_spec.rb +++ b/spec/ruby/library/pathname/absolute_spec.rb @@ -4,19 +4,19 @@ describe "Pathname#absolute?" do it "returns true for the root directory" do - Pathname.new('/').absolute?.should == true + Pathname.new('/').should.absolute? end it "returns true for a dir starting with a slash" do - Pathname.new('/usr/local/bin').absolute?.should == true + Pathname.new('/usr/local/bin').should.absolute? end it "returns false for a dir not starting with a slash" do - Pathname.new('fish').absolute?.should == false + Pathname.new('fish').should_not.absolute? end it "returns false for a dir not starting with a slash" do - Pathname.new('fish/dog/cow').absolute?.should == false + Pathname.new('fish/dog/cow').should_not.absolute? end end diff --git a/spec/ruby/library/pathname/new_spec.rb b/spec/ruby/library/pathname/new_spec.rb index dcb770149ff243..760fd8638f19aa 100644 --- a/spec/ruby/library/pathname/new_spec.rb +++ b/spec/ruby/library/pathname/new_spec.rb @@ -13,7 +13,7 @@ ruby_version_is ''...'2.7' do it "is tainted if path is tainted" do path = '/usr/local/bin'.taint - Pathname.new(path).tainted?.should == true + Pathname.new(path).should.tainted? end end diff --git a/spec/ruby/library/pathname/relative_spec.rb b/spec/ruby/library/pathname/relative_spec.rb index 1a08891e6cfee5..0fab9a7b9f19f8 100644 --- a/spec/ruby/library/pathname/relative_spec.rb +++ b/spec/ruby/library/pathname/relative_spec.rb @@ -4,19 +4,19 @@ describe "Pathname#relative?" do it "returns false for the root directory" do - Pathname.new('/').relative?.should == false + Pathname.new('/').should_not.relative? end it "returns false for a dir starting with a slash" do - Pathname.new('/usr/local/bin').relative?.should == false + Pathname.new('/usr/local/bin').should_not.relative? end it "returns true for a dir not starting with a slash" do - Pathname.new('fish').relative?.should == true + Pathname.new('fish').should.relative? end it "returns true for a dir not starting with a slash" do - Pathname.new('fish/dog/cow').relative?.should == true + Pathname.new('fish/dog/cow').should.relative? end end diff --git a/spec/ruby/library/pathname/root_spec.rb b/spec/ruby/library/pathname/root_spec.rb index 5fec0ee95699f3..cd2be24516e4d3 100644 --- a/spec/ruby/library/pathname/root_spec.rb +++ b/spec/ruby/library/pathname/root_spec.rb @@ -4,23 +4,23 @@ describe "Pathname#root?" do it "returns true for root directories" do - Pathname.new('/').root?.should == true + Pathname.new('/').should.root? end it "returns false for empty string" do - Pathname.new('').root?.should == false + Pathname.new('').should_not.root? end it "returns false for a top level directory" do - Pathname.new('/usr').root?.should == false + Pathname.new('/usr').should_not.root? end it "returns false for a top level with .. appended directory" do - Pathname.new('/usr/..').root?.should == false + Pathname.new('/usr/..').should_not.root? end it "returns false for a directory below top level" do - Pathname.new('/usr/local/bin/').root?.should == false + Pathname.new('/usr/local/bin/').should_not.root? end end diff --git a/spec/ruby/library/rbconfig/rbconfig_spec.rb b/spec/ruby/library/rbconfig/rbconfig_spec.rb index f88dc673e5dc9b..1aa12df7417e99 100644 --- a/spec/ruby/library/rbconfig/rbconfig_spec.rb +++ b/spec/ruby/library/rbconfig/rbconfig_spec.rb @@ -51,6 +51,22 @@ end end end + + platform_is :linux do + it "['AR'] exists and can be executed" do + ar = RbConfig::CONFIG.fetch('AR') + out = `#{ar} --version` + $?.should.success? + out.should_not be_empty + end + + it "['STRIP'] exists and can be executed" do + strip = RbConfig::CONFIG.fetch('STRIP') + out = `#{strip} --version` + $?.should.success? + out.should_not be_empty + end + end end describe "RbConfig::TOPDIR" do diff --git a/spec/ruby/library/rexml/element/cdatas_spec.rb b/spec/ruby/library/rexml/element/cdatas_spec.rb index 4cc592aae374eb..ecbca94f62814b 100644 --- a/spec/ruby/library/rexml/element/cdatas_spec.rb +++ b/spec/ruby/library/rexml/element/cdatas_spec.rb @@ -17,7 +17,7 @@ end it "freezes the returned array" do - @e.cdatas.frozen?.should == true + @e.cdatas.should.frozen? end it "returns an empty array if element has no cdata" do diff --git a/spec/ruby/library/rexml/element/comments_spec.rb b/spec/ruby/library/rexml/element/comments_spec.rb index 59a0b3e4fb33bb..26043366d3ef7d 100644 --- a/spec/ruby/library/rexml/element/comments_spec.rb +++ b/spec/ruby/library/rexml/element/comments_spec.rb @@ -17,7 +17,7 @@ end it "returns a frozen object" do - @e.comments.frozen?.should == true + @e.comments.should.frozen? end end end diff --git a/spec/ruby/library/rexml/node/parent_spec.rb b/spec/ruby/library/rexml/node/parent_spec.rb index 693ee9d5c200a9..0a31abaf0f4e95 100644 --- a/spec/ruby/library/rexml/node/parent_spec.rb +++ b/spec/ruby/library/rexml/node/parent_spec.rb @@ -6,18 +6,18 @@ describe "REXML::Node#parent?" do it "returns true for Elements" do e = REXML::Element.new("foo") - e.parent?.should == true + e.should.parent? end it "returns true for Documents" do e = REXML::Document.new - e.parent?.should == true + e.should.parent? end # This includes attributes, CDatas and declarations. it "returns false for Texts" do e = REXML::Text.new("foo") - e.parent?.should == false + e.should_not.parent? end end end diff --git a/spec/ruby/library/rexml/text/empty_spec.rb b/spec/ruby/library/rexml/text/empty_spec.rb index 392b536a4cf24c..18f31580adc255 100644 --- a/spec/ruby/library/rexml/text/empty_spec.rb +++ b/spec/ruby/library/rexml/text/empty_spec.rb @@ -5,11 +5,11 @@ describe "REXML::Text#empty?" do it "returns true if the text is empty" do - REXML::Text.new("").empty?.should == true + REXML::Text.new("").should.empty? end it "returns false if the text is not empty" do - REXML::Text.new("some_text").empty?.should == false + REXML::Text.new("some_text").should_not.empty? end end end diff --git a/spec/ruby/library/set/compare_by_identity_spec.rb b/spec/ruby/library/set/compare_by_identity_spec.rb index 28fe91309f1d4a..9ed16021897f2d 100644 --- a/spec/ruby/library/set/compare_by_identity_spec.rb +++ b/spec/ruby/library/set/compare_by_identity_spec.rb @@ -42,7 +42,7 @@ def o.hash; 123; end set = Set.new.compare_by_identity set << :foo set.compare_by_identity.should equal(set) - set.compare_by_identity?.should == true + set.should.compare_by_identity? set.to_a.should == [:foo] end @@ -124,20 +124,20 @@ def o.hash; 123; end describe "Set#compare_by_identity?" do it "returns false by default" do - Set.new.compare_by_identity?.should == false + Set.new.should_not.compare_by_identity? end it "returns true once #compare_by_identity has been invoked on self" do set = Set.new set.compare_by_identity - set.compare_by_identity?.should == true + set.should.compare_by_identity? end it "returns true when called multiple times on the same set" do set = Set.new set.compare_by_identity - set.compare_by_identity?.should == true - set.compare_by_identity?.should == true - set.compare_by_identity?.should == true + set.should.compare_by_identity? + set.should.compare_by_identity? + set.should.compare_by_identity? end end diff --git a/spec/ruby/library/socket/addrinfo/ipv4_loopback_spec.rb b/spec/ruby/library/socket/addrinfo/ipv4_loopback_spec.rb index f5bab711db4058..10ad084fc93bb4 100644 --- a/spec/ruby/library/socket/addrinfo/ipv4_loopback_spec.rb +++ b/spec/ruby/library/socket/addrinfo/ipv4_loopback_spec.rb @@ -3,10 +3,10 @@ describe "Addrinfo#ipv4_loopback?" do describe "for an ipv4 socket" do it "returns true for the loopback address" do - Addrinfo.ip('127.0.0.1').ipv4_loopback?.should == true - Addrinfo.ip('127.0.0.2').ipv4_loopback?.should == true - Addrinfo.ip('127.255.0.1').ipv4_loopback?.should == true - Addrinfo.ip('127.255.255.255').ipv4_loopback?.should == true + Addrinfo.ip('127.0.0.1').should.ipv4_loopback? + Addrinfo.ip('127.0.0.2').should.ipv4_loopback? + Addrinfo.ip('127.255.0.1').should.ipv4_loopback? + Addrinfo.ip('127.255.255.255').should.ipv4_loopback? end it "returns false for another address" do diff --git a/spec/ruby/library/socket/addrinfo/ipv4_multicast_spec.rb b/spec/ruby/library/socket/addrinfo/ipv4_multicast_spec.rb index bdd14c1b000a00..f7fead86409680 100644 --- a/spec/ruby/library/socket/addrinfo/ipv4_multicast_spec.rb +++ b/spec/ruby/library/socket/addrinfo/ipv4_multicast_spec.rb @@ -2,17 +2,17 @@ describe "Addrinfo#ipv4_multicast?" do it 'returns true for a multicast address' do - Addrinfo.ip('224.0.0.0').ipv4_multicast?.should == true - Addrinfo.ip('224.0.0.9').ipv4_multicast?.should == true - Addrinfo.ip('239.255.255.250').ipv4_multicast?.should == true + Addrinfo.ip('224.0.0.0').should.ipv4_multicast? + Addrinfo.ip('224.0.0.9').should.ipv4_multicast? + Addrinfo.ip('239.255.255.250').should.ipv4_multicast? end it 'returns false for a regular address' do - Addrinfo.ip('8.8.8.8').ipv4_multicast?.should == false + Addrinfo.ip('8.8.8.8').should_not.ipv4_multicast? end it 'returns false for an IPv6 address' do - Addrinfo.ip('::1').ipv4_multicast?.should == false + Addrinfo.ip('::1').should_not.ipv4_multicast? end with_feature :unix_socket do diff --git a/spec/ruby/library/socket/addrinfo/ipv4_private_spec.rb b/spec/ruby/library/socket/addrinfo/ipv4_private_spec.rb index 733577609e746a..e5a33b4953f38f 100644 --- a/spec/ruby/library/socket/addrinfo/ipv4_private_spec.rb +++ b/spec/ruby/library/socket/addrinfo/ipv4_private_spec.rb @@ -8,14 +8,14 @@ end it "returns true for a private address" do - Addrinfo.ip('10.0.0.0').ipv4_private?.should == true - Addrinfo.ip('10.0.0.5').ipv4_private?.should == true + Addrinfo.ip('10.0.0.0').should.ipv4_private? + Addrinfo.ip('10.0.0.5').should.ipv4_private? - Addrinfo.ip('172.16.0.0').ipv4_private?.should == true - Addrinfo.ip('172.16.0.5').ipv4_private?.should == true + Addrinfo.ip('172.16.0.0').should.ipv4_private? + Addrinfo.ip('172.16.0.5').should.ipv4_private? - Addrinfo.ip('192.168.0.0').ipv4_private?.should == true - Addrinfo.ip('192.168.0.5').ipv4_private?.should == true + Addrinfo.ip('192.168.0.0').should.ipv4_private? + Addrinfo.ip('192.168.0.5').should.ipv4_private? end it "returns false for a public address" do diff --git a/spec/ruby/library/socket/addrinfo/ipv6_linklocal_spec.rb b/spec/ruby/library/socket/addrinfo/ipv6_linklocal_spec.rb index 291b4d7d6b7737..bfef3963813cf7 100644 --- a/spec/ruby/library/socket/addrinfo/ipv6_linklocal_spec.rb +++ b/spec/ruby/library/socket/addrinfo/ipv6_linklocal_spec.rb @@ -5,19 +5,19 @@ describe 'Addrinfo#ipv6_linklocal?' do platform_is_not :aix do it 'returns true for a link-local address' do - Addrinfo.ip('fe80::').ipv6_linklocal?.should == true - Addrinfo.ip('fe81::').ipv6_linklocal?.should == true - Addrinfo.ip('fe8f::').ipv6_linklocal?.should == true - Addrinfo.ip('fe80::1').ipv6_linklocal?.should == true + Addrinfo.ip('fe80::').should.ipv6_linklocal? + Addrinfo.ip('fe81::').should.ipv6_linklocal? + Addrinfo.ip('fe8f::').should.ipv6_linklocal? + Addrinfo.ip('fe80::1').should.ipv6_linklocal? end end it 'returns false for a regular address' do - Addrinfo.ip('::1').ipv6_linklocal?.should == false + Addrinfo.ip('::1').should_not.ipv6_linklocal? end it 'returns false for an IPv4 address' do - Addrinfo.ip('127.0.0.1').ipv6_linklocal?.should == false + Addrinfo.ip('127.0.0.1').should_not.ipv6_linklocal? end end end diff --git a/spec/ruby/library/socket/addrinfo/ipv6_mc_global_spec.rb b/spec/ruby/library/socket/addrinfo/ipv6_mc_global_spec.rb index 9c8e4dccb446f5..01fa0992ba8ce0 100644 --- a/spec/ruby/library/socket/addrinfo/ipv6_mc_global_spec.rb +++ b/spec/ruby/library/socket/addrinfo/ipv6_mc_global_spec.rb @@ -2,19 +2,19 @@ describe 'Addrinfo#ipv6_mc_global?' do it 'returns true for a multi-cast address in the global scope' do - Addrinfo.ip('ff1e::').ipv6_mc_global?.should == true - Addrinfo.ip('fffe::').ipv6_mc_global?.should == true - Addrinfo.ip('ff0e::').ipv6_mc_global?.should == true - Addrinfo.ip('ff1e::1').ipv6_mc_global?.should == true + Addrinfo.ip('ff1e::').should.ipv6_mc_global? + Addrinfo.ip('fffe::').should.ipv6_mc_global? + Addrinfo.ip('ff0e::').should.ipv6_mc_global? + Addrinfo.ip('ff1e::1').should.ipv6_mc_global? end it 'returns false for a regular IPv6 address' do - Addrinfo.ip('::1').ipv6_mc_global?.should == false - Addrinfo.ip('ff1a::').ipv6_mc_global?.should == false - Addrinfo.ip('ff1f::1').ipv6_mc_global?.should == false + Addrinfo.ip('::1').should_not.ipv6_mc_global? + Addrinfo.ip('ff1a::').should_not.ipv6_mc_global? + Addrinfo.ip('ff1f::1').should_not.ipv6_mc_global? end it 'returns false for an IPv4 address' do - Addrinfo.ip('127.0.0.1').ipv6_mc_global?.should == false + Addrinfo.ip('127.0.0.1').should_not.ipv6_mc_global? end end diff --git a/spec/ruby/library/socket/addrinfo/ipv6_mc_linklocal_spec.rb b/spec/ruby/library/socket/addrinfo/ipv6_mc_linklocal_spec.rb index dd52a9ad8bd4dd..a1298919eb4a45 100644 --- a/spec/ruby/library/socket/addrinfo/ipv6_mc_linklocal_spec.rb +++ b/spec/ruby/library/socket/addrinfo/ipv6_mc_linklocal_spec.rb @@ -2,18 +2,18 @@ describe 'Addrinfo#ipv6_mc_linklocal?' do it 'returns true for a multi-cast link-local address' do - Addrinfo.ip('ff12::').ipv6_mc_linklocal?.should == true - Addrinfo.ip('ff02::').ipv6_mc_linklocal?.should == true - Addrinfo.ip('fff2::').ipv6_mc_linklocal?.should == true - Addrinfo.ip('ff12::1').ipv6_mc_linklocal?.should == true + Addrinfo.ip('ff12::').should.ipv6_mc_linklocal? + Addrinfo.ip('ff02::').should.ipv6_mc_linklocal? + Addrinfo.ip('fff2::').should.ipv6_mc_linklocal? + Addrinfo.ip('ff12::1').should.ipv6_mc_linklocal? end it 'returns false for a regular IPv6 address' do - Addrinfo.ip('::1').ipv6_mc_linklocal?.should == false - Addrinfo.ip('fff1::').ipv6_mc_linklocal?.should == false + Addrinfo.ip('::1').should_not.ipv6_mc_linklocal? + Addrinfo.ip('fff1::').should_not.ipv6_mc_linklocal? end it 'returns false for an IPv4 address' do - Addrinfo.ip('127.0.0.1').ipv6_mc_linklocal?.should == false + Addrinfo.ip('127.0.0.1').should_not.ipv6_mc_linklocal? end end diff --git a/spec/ruby/library/socket/addrinfo/ipv6_mc_nodelocal_spec.rb b/spec/ruby/library/socket/addrinfo/ipv6_mc_nodelocal_spec.rb index b3cf5ffbabb3aa..0aee952d88df3d 100644 --- a/spec/ruby/library/socket/addrinfo/ipv6_mc_nodelocal_spec.rb +++ b/spec/ruby/library/socket/addrinfo/ipv6_mc_nodelocal_spec.rb @@ -2,17 +2,17 @@ describe 'Addrinfo#ipv6_mc_nodelocal?' do it 'returns true for a multi-cast node-local address' do - Addrinfo.ip('ff11::').ipv6_mc_nodelocal?.should == true - Addrinfo.ip('ff01::').ipv6_mc_nodelocal?.should == true - Addrinfo.ip('fff1::').ipv6_mc_nodelocal?.should == true - Addrinfo.ip('ff11::1').ipv6_mc_nodelocal?.should == true + Addrinfo.ip('ff11::').should.ipv6_mc_nodelocal? + Addrinfo.ip('ff01::').should.ipv6_mc_nodelocal? + Addrinfo.ip('fff1::').should.ipv6_mc_nodelocal? + Addrinfo.ip('ff11::1').should.ipv6_mc_nodelocal? end it 'returns false for a regular IPv6 address' do - Addrinfo.ip('::1').ipv6_mc_nodelocal?.should == false + Addrinfo.ip('::1').should_not.ipv6_mc_nodelocal? end it 'returns false for an IPv4 address' do - Addrinfo.ip('127.0.0.1').ipv6_mc_nodelocal?.should == false + Addrinfo.ip('127.0.0.1').should_not.ipv6_mc_nodelocal? end end diff --git a/spec/ruby/library/socket/addrinfo/ipv6_mc_orglocal_spec.rb b/spec/ruby/library/socket/addrinfo/ipv6_mc_orglocal_spec.rb index 90653dd49c9ddd..2977a98d30e2bf 100644 --- a/spec/ruby/library/socket/addrinfo/ipv6_mc_orglocal_spec.rb +++ b/spec/ruby/library/socket/addrinfo/ipv6_mc_orglocal_spec.rb @@ -2,17 +2,17 @@ describe 'Addrinfo#ipv6_mc_orglocal?' do it 'returns true for a multi-cast org-local address' do - Addrinfo.ip('ff18::').ipv6_mc_orglocal?.should == true - Addrinfo.ip('ff08::').ipv6_mc_orglocal?.should == true - Addrinfo.ip('fff8::').ipv6_mc_orglocal?.should == true - Addrinfo.ip('ff18::1').ipv6_mc_orglocal?.should == true + Addrinfo.ip('ff18::').should.ipv6_mc_orglocal? + Addrinfo.ip('ff08::').should.ipv6_mc_orglocal? + Addrinfo.ip('fff8::').should.ipv6_mc_orglocal? + Addrinfo.ip('ff18::1').should.ipv6_mc_orglocal? end it 'returns false for a regular IPv6 address' do - Addrinfo.ip('::1').ipv6_mc_orglocal?.should == false + Addrinfo.ip('::1').should_not.ipv6_mc_orglocal? end it 'returns false for an IPv4 address' do - Addrinfo.ip('127.0.0.1').ipv6_mc_orglocal?.should == false + Addrinfo.ip('127.0.0.1').should_not.ipv6_mc_orglocal? end end diff --git a/spec/ruby/library/socket/addrinfo/ipv6_mc_sitelocal_spec.rb b/spec/ruby/library/socket/addrinfo/ipv6_mc_sitelocal_spec.rb index 686b625e0d98ac..58e5976a409b39 100644 --- a/spec/ruby/library/socket/addrinfo/ipv6_mc_sitelocal_spec.rb +++ b/spec/ruby/library/socket/addrinfo/ipv6_mc_sitelocal_spec.rb @@ -2,17 +2,17 @@ describe 'Addrinfo#ipv6_mc_sitelocal?' do it 'returns true for a multi-cast site-local address' do - Addrinfo.ip('ff15::').ipv6_mc_sitelocal?.should == true - Addrinfo.ip('ff05::').ipv6_mc_sitelocal?.should == true - Addrinfo.ip('fff5::').ipv6_mc_sitelocal?.should == true - Addrinfo.ip('ff15::1').ipv6_mc_sitelocal?.should == true + Addrinfo.ip('ff15::').should.ipv6_mc_sitelocal? + Addrinfo.ip('ff05::').should.ipv6_mc_sitelocal? + Addrinfo.ip('fff5::').should.ipv6_mc_sitelocal? + Addrinfo.ip('ff15::1').should.ipv6_mc_sitelocal? end it 'returns false for a regular IPv6 address' do - Addrinfo.ip('::1').ipv6_mc_sitelocal?.should == false + Addrinfo.ip('::1').should_not.ipv6_mc_sitelocal? end it 'returns false for an IPv4 address' do - Addrinfo.ip('127.0.0.1').ipv6_mc_sitelocal?.should == false + Addrinfo.ip('127.0.0.1').should_not.ipv6_mc_sitelocal? end end diff --git a/spec/ruby/library/socket/addrinfo/ipv6_multicast_spec.rb b/spec/ruby/library/socket/addrinfo/ipv6_multicast_spec.rb index c25322869c4c8b..2c987b59210acf 100644 --- a/spec/ruby/library/socket/addrinfo/ipv6_multicast_spec.rb +++ b/spec/ruby/library/socket/addrinfo/ipv6_multicast_spec.rb @@ -18,19 +18,19 @@ describe "for an ipv6 socket" do it "returns true for a multicast address" do - Addrinfo.ip('ff00::').ipv6_multicast?.should == true - Addrinfo.ip('ff00::1').ipv6_multicast?.should == true - Addrinfo.ip('ff08::1').ipv6_multicast?.should == true - Addrinfo.ip('fff8::1').ipv6_multicast?.should == true - - Addrinfo.ip('ff02::').ipv6_multicast?.should == true - Addrinfo.ip('ff02::1').ipv6_multicast?.should == true - Addrinfo.ip('ff0f::').ipv6_multicast?.should == true + Addrinfo.ip('ff00::').should.ipv6_multicast? + Addrinfo.ip('ff00::1').should.ipv6_multicast? + Addrinfo.ip('ff08::1').should.ipv6_multicast? + Addrinfo.ip('fff8::1').should.ipv6_multicast? + + Addrinfo.ip('ff02::').should.ipv6_multicast? + Addrinfo.ip('ff02::1').should.ipv6_multicast? + Addrinfo.ip('ff0f::').should.ipv6_multicast? end it "returns false for another address" do - Addrinfo.ip('::1').ipv6_multicast?.should == false - Addrinfo.ip('fe80::').ipv6_multicast?.should == false + Addrinfo.ip('::1').should_not.ipv6_multicast? + Addrinfo.ip('fe80::').should_not.ipv6_multicast? end end diff --git a/spec/ruby/library/socket/addrinfo/ipv6_sitelocal_spec.rb b/spec/ruby/library/socket/addrinfo/ipv6_sitelocal_spec.rb index dd202a1749f2f0..9158eb58099efa 100644 --- a/spec/ruby/library/socket/addrinfo/ipv6_sitelocal_spec.rb +++ b/spec/ruby/library/socket/addrinfo/ipv6_sitelocal_spec.rb @@ -5,19 +5,19 @@ describe 'Addrinfo#ipv6_sitelocal?' do platform_is_not :aix do it 'returns true for a site-local address' do - Addrinfo.ip('feef::').ipv6_sitelocal?.should == true - Addrinfo.ip('fee0::').ipv6_sitelocal?.should == true - Addrinfo.ip('fee2::').ipv6_sitelocal?.should == true - Addrinfo.ip('feef::1').ipv6_sitelocal?.should == true + Addrinfo.ip('feef::').should.ipv6_sitelocal? + Addrinfo.ip('fee0::').should.ipv6_sitelocal? + Addrinfo.ip('fee2::').should.ipv6_sitelocal? + Addrinfo.ip('feef::1').should.ipv6_sitelocal? end end it 'returns false for a regular IPv6 address' do - Addrinfo.ip('::1').ipv6_sitelocal?.should == false + Addrinfo.ip('::1').should_not.ipv6_sitelocal? end it 'returns false for an IPv4 address' do - Addrinfo.ip('127.0.0.1').ipv6_sitelocal?.should == false + Addrinfo.ip('127.0.0.1').should_not.ipv6_sitelocal? end end end diff --git a/spec/ruby/library/socket/addrinfo/ipv6_unique_local_spec.rb b/spec/ruby/library/socket/addrinfo/ipv6_unique_local_spec.rb index b80a15fcb0db3e..22f0fa3b75ccbe 100644 --- a/spec/ruby/library/socket/addrinfo/ipv6_unique_local_spec.rb +++ b/spec/ruby/library/socket/addrinfo/ipv6_unique_local_spec.rb @@ -2,17 +2,17 @@ describe 'Addrinfo#ipv6_unique_local?' do it 'returns true for an unique local IPv6 address' do - Addrinfo.ip('fc00::').ipv6_unique_local?.should == true - Addrinfo.ip('fd00::').ipv6_unique_local?.should == true - Addrinfo.ip('fcff::').ipv6_unique_local?.should == true + Addrinfo.ip('fc00::').should.ipv6_unique_local? + Addrinfo.ip('fd00::').should.ipv6_unique_local? + Addrinfo.ip('fcff::').should.ipv6_unique_local? end it 'returns false for a regular IPv6 address' do - Addrinfo.ip('::1').ipv6_unique_local?.should == false - Addrinfo.ip('fe00::').ipv6_unique_local?.should == false + Addrinfo.ip('::1').should_not.ipv6_unique_local? + Addrinfo.ip('fe00::').should_not.ipv6_unique_local? end it 'returns false for an IPv4 address' do - Addrinfo.ip('127.0.0.1').ipv6_unique_local?.should == false + Addrinfo.ip('127.0.0.1').should_not.ipv6_unique_local? end end diff --git a/spec/ruby/library/socket/addrinfo/ipv6_unspecified_spec.rb b/spec/ruby/library/socket/addrinfo/ipv6_unspecified_spec.rb index dd79d57503a670..d63979cedaa8b1 100644 --- a/spec/ruby/library/socket/addrinfo/ipv6_unspecified_spec.rb +++ b/spec/ruby/library/socket/addrinfo/ipv6_unspecified_spec.rb @@ -2,14 +2,14 @@ describe 'Addrinfo#ipv6_unspecified?' do it 'returns true for an unspecified IPv6 address' do - Addrinfo.ip('::').ipv6_unspecified?.should == true + Addrinfo.ip('::').should.ipv6_unspecified? end it 'returns false for a regular IPv6 address' do - Addrinfo.ip('::1').ipv6_unspecified?.should == false + Addrinfo.ip('::1').should_not.ipv6_unspecified? end it 'returns false for an IPv4 address' do - Addrinfo.ip('127.0.0.1').ipv6_unspecified?.should == false + Addrinfo.ip('127.0.0.1').should_not.ipv6_unspecified? end end diff --git a/spec/ruby/library/socket/addrinfo/ipv6_v4compat_spec.rb b/spec/ruby/library/socket/addrinfo/ipv6_v4compat_spec.rb index ab8388a21bc2b4..21ca85af999912 100644 --- a/spec/ruby/library/socket/addrinfo/ipv6_v4compat_spec.rb +++ b/spec/ruby/library/socket/addrinfo/ipv6_v4compat_spec.rb @@ -2,19 +2,19 @@ describe 'Addrinfo#ipv6_v4compat?' do it 'returns true for an IPv4 compatible address' do - Addrinfo.ip('::127.0.0.1').ipv6_v4compat?.should == true - Addrinfo.ip('::192.168.1.1').ipv6_v4compat?.should == true + Addrinfo.ip('::127.0.0.1').should.ipv6_v4compat? + Addrinfo.ip('::192.168.1.1').should.ipv6_v4compat? end it 'returns false for an IPv4 mapped address' do - Addrinfo.ip('::ffff:192.168.1.1').ipv6_v4compat?.should == false + Addrinfo.ip('::ffff:192.168.1.1').should_not.ipv6_v4compat? end it 'returns false for a regular IPv6 address' do - Addrinfo.ip('::1').ipv6_v4compat?.should == false + Addrinfo.ip('::1').should_not.ipv6_v4compat? end it 'returns false for an IPv4 address' do - Addrinfo.ip('127.0.0.1').ipv6_v4compat?.should == false + Addrinfo.ip('127.0.0.1').should_not.ipv6_v4compat? end end diff --git a/spec/ruby/library/socket/addrinfo/ipv6_v4mapped_spec.rb b/spec/ruby/library/socket/addrinfo/ipv6_v4mapped_spec.rb index 82b272c1650d9c..7dac0e75dbbe84 100644 --- a/spec/ruby/library/socket/addrinfo/ipv6_v4mapped_spec.rb +++ b/spec/ruby/library/socket/addrinfo/ipv6_v4mapped_spec.rb @@ -2,19 +2,19 @@ describe 'Addrinfo#ipv6_v4mapped?' do it 'returns true for an IPv4 compatible address' do - Addrinfo.ip('::ffff:192.168.1.1').ipv6_v4mapped?.should == true + Addrinfo.ip('::ffff:192.168.1.1').should.ipv6_v4mapped? end it 'returns false for an IPv4 compatible address' do - Addrinfo.ip('::192.168.1.1').ipv6_v4mapped?.should == false - Addrinfo.ip('::127.0.0.1').ipv6_v4mapped?.should == false + Addrinfo.ip('::192.168.1.1').should_not.ipv6_v4mapped? + Addrinfo.ip('::127.0.0.1').should_not.ipv6_v4mapped? end it 'returns false for a regular IPv6 address' do - Addrinfo.ip('::1').ipv6_v4mapped?.should == false + Addrinfo.ip('::1').should_not.ipv6_v4mapped? end it 'returns false for an IPv4 address' do - Addrinfo.ip('127.0.0.1').ipv6_v4mapped?.should == false + Addrinfo.ip('127.0.0.1').should_not.ipv6_v4mapped? end end diff --git a/spec/ruby/library/socket/addrinfo/listen_spec.rb b/spec/ruby/library/socket/addrinfo/listen_spec.rb index 714a96ed6c0759..931093f7325c85 100644 --- a/spec/ruby/library/socket/addrinfo/listen_spec.rb +++ b/spec/ruby/library/socket/addrinfo/listen_spec.rb @@ -29,6 +29,6 @@ socket = sock end - socket.closed?.should == true + socket.should.closed? end end diff --git a/spec/ruby/library/socket/basicsocket/read_nonblock_spec.rb b/spec/ruby/library/socket/basicsocket/read_nonblock_spec.rb index 4986fffbc5fdc9..b8def7e93033ba 100644 --- a/spec/ruby/library/socket/basicsocket/read_nonblock_spec.rb +++ b/spec/ruby/library/socket/basicsocket/read_nonblock_spec.rb @@ -24,20 +24,20 @@ platform_is :linux do it 'does not set the IO in nonblock mode' do require 'io/nonblock' - @r.nonblock?.should == false + @r.should_not.nonblock? IO.select([@r], nil, nil, 2) @r.read_nonblock(3).should == "aaa" - @r.nonblock?.should == false + @r.should_not.nonblock? end end platform_is_not :linux, :windows do it 'sets the IO in nonblock mode' do require 'io/nonblock' - @r.nonblock?.should == false + @r.should_not.nonblock? IO.select([@r], nil, nil, 2) @r.read_nonblock(3).should == "aaa" - @r.nonblock?.should == true + @r.should.nonblock? end end end diff --git a/spec/ruby/library/socket/basicsocket/write_nonblock_spec.rb b/spec/ruby/library/socket/basicsocket/write_nonblock_spec.rb index 95ec08a6c7be1c..c385beab24a589 100644 --- a/spec/ruby/library/socket/basicsocket/write_nonblock_spec.rb +++ b/spec/ruby/library/socket/basicsocket/write_nonblock_spec.rb @@ -25,18 +25,18 @@ platform_is :linux do it 'does not set the IO in nonblock mode' do require 'io/nonblock' - @w.nonblock?.should == false + @w.should_not.nonblock? @w.write_nonblock("aaa").should == 3 - @w.nonblock?.should == false + @w.should_not.nonblock? end end platform_is_not :linux, :windows do it 'sets the IO in nonblock mode' do require 'io/nonblock' - @w.nonblock?.should == false + @w.should_not.nonblock? @w.write_nonblock("aaa").should == 3 - @w.nonblock?.should == true + @w.should.nonblock? end end end diff --git a/spec/ruby/library/socket/socket/tcp_server_sockets_spec.rb b/spec/ruby/library/socket/socket/tcp_server_sockets_spec.rb index 10c030a8ce89e4..bd496d301560b3 100644 --- a/spec/ruby/library/socket/socket/tcp_server_sockets_spec.rb +++ b/spec/ruby/library/socket/socket/tcp_server_sockets_spec.rb @@ -32,7 +32,7 @@ Socket.tcp_server_sockets(0) { |socks| sockets = socks } sockets.each do |socket| - socket.closed?.should == true + socket.should.closed? end end end diff --git a/spec/ruby/library/socket/socket/tcp_spec.rb b/spec/ruby/library/socket/socket/tcp_spec.rb index d36e3e6adb66dd..faf020b1ead615 100644 --- a/spec/ruby/library/socket/socket/tcp_spec.rb +++ b/spec/ruby/library/socket/socket/tcp_spec.rb @@ -36,7 +36,7 @@ @socket = socket end - @socket.closed?.should == true + @socket.should.closed? end it 'binds to a local address and port when specified' do diff --git a/spec/ruby/library/socket/socket/udp_server_sockets_spec.rb b/spec/ruby/library/socket/socket/udp_server_sockets_spec.rb index 3aeb472dda5a51..f8be672612aa8f 100644 --- a/spec/ruby/library/socket/socket/udp_server_sockets_spec.rb +++ b/spec/ruby/library/socket/socket/udp_server_sockets_spec.rb @@ -32,7 +32,7 @@ Socket.udp_server_sockets(0) { |socks| sockets = socks } sockets.each do |socket| - socket.closed?.should == true + socket.should.closed? end end end diff --git a/spec/ruby/library/socket/socket/unix_spec.rb b/spec/ruby/library/socket/socket/unix_spec.rb index add54a097d4560..4bff59bd4b3d44 100644 --- a/spec/ruby/library/socket/socket/unix_spec.rb +++ b/spec/ruby/library/socket/socket/unix_spec.rb @@ -38,7 +38,7 @@ socket = sock end - socket.closed?.should == true + socket.should.closed? end end end diff --git a/spec/ruby/library/socket/unixsocket/open_spec.rb b/spec/ruby/library/socket/unixsocket/open_spec.rb index ad5048fedd15a6..99ad151bb83072 100644 --- a/spec/ruby/library/socket/unixsocket/open_spec.rb +++ b/spec/ruby/library/socket/unixsocket/open_spec.rb @@ -21,7 +21,7 @@ it "opens a unix socket on the specified file and yields it to the block" do UNIXSocket.open(@path) do |client| client.addr[0].should == "AF_UNIX" - client.closed?.should == false + client.should_not.closed? end end end diff --git a/spec/ruby/library/socket/unixsocket/shared/new.rb b/spec/ruby/library/socket/unixsocket/shared/new.rb index 76a4e1701ece0f..bfb7ed3886f5f6 100644 --- a/spec/ruby/library/socket/unixsocket/shared/new.rb +++ b/spec/ruby/library/socket/unixsocket/shared/new.rb @@ -18,7 +18,7 @@ @client = UNIXSocket.send(@method, @path) @client.addr[0].should == "AF_UNIX" - @client.closed?.should == false + @client.should_not.closed? end end end diff --git a/spec/ruby/library/stringio/reopen_spec.rb b/spec/ruby/library/stringio/reopen_spec.rb index ab0a3331d25930..99439783777103 100644 --- a/spec/ruby/library/stringio/reopen_spec.rb +++ b/spec/ruby/library/stringio/reopen_spec.rb @@ -283,7 +283,7 @@ new_io = StringIO.new("tainted") new_io.taint @io.reopen(new_io) - @io.tainted?.should == true + @io.should.tainted? end end diff --git a/spec/ruby/library/syslog/close_spec.rb b/spec/ruby/library/syslog/close_spec.rb index 8186ecf1257365..8c3b67c05bd8d6 100644 --- a/spec/ruby/library/syslog/close_spec.rb +++ b/spec/ruby/library/syslog/close_spec.rb @@ -30,7 +30,7 @@ -> { Syslog.open { |s| s.close } }.should raise_error(RuntimeError) - Syslog.opened?.should == false + Syslog.should_not.opened? end it "sets the identity to nil" do diff --git a/spec/ruby/library/syslog/ident_spec.rb b/spec/ruby/library/syslog/ident_spec.rb index e8345ebb490029..3b083271406a68 100644 --- a/spec/ruby/library/syslog/ident_spec.rb +++ b/spec/ruby/library/syslog/ident_spec.rb @@ -21,7 +21,7 @@ end it "returns nil if the log is closed" do - Syslog.opened?.should == false + Syslog.should_not.opened? Syslog.ident.should == nil end diff --git a/spec/ruby/library/syslog/mask_spec.rb b/spec/ruby/library/syslog/mask_spec.rb index 6581f6a756f7f0..b3f1250b24ac9d 100644 --- a/spec/ruby/library/syslog/mask_spec.rb +++ b/spec/ruby/library/syslog/mask_spec.rb @@ -32,7 +32,7 @@ end it "returns nil if the log is closed" do - Syslog.opened?.should == false + Syslog.should_not.opened? Syslog.mask.should == nil end diff --git a/spec/ruby/library/weakref/weakref_alive_spec.rb b/spec/ruby/library/weakref/weakref_alive_spec.rb index 173ea0148592a1..1ebf9c1ee39821 100644 --- a/spec/ruby/library/weakref/weakref_alive_spec.rb +++ b/spec/ruby/library/weakref/weakref_alive_spec.rb @@ -5,7 +5,7 @@ it "returns true if the object is reachable" do obj = Object.new ref = WeakRef.new(obj) - ref.weakref_alive?.should == true + ref.weakref_alive?.should be_true end it "returns a falsy value if the object is no longer reachable" do diff --git a/spec/ruby/library/win32ole/win32ole_param/input_spec.rb b/spec/ruby/library/win32ole/win32ole_param/input_spec.rb index a0022fef131d2e..e2a90daa5663fd 100644 --- a/spec/ruby/library/win32ole/win32ole_param/input_spec.rb +++ b/spec/ruby/library/win32ole/win32ole_param/input_spec.rb @@ -13,7 +13,7 @@ end it "returns true for 3rd parameter of FileSystemObject's 'CopyFile' method" do - @param_overwritefiles.input?.should == true + @param_overwritefiles.should.input? end end diff --git a/spec/ruby/library/zlib/gzipfile/close_spec.rb b/spec/ruby/library/zlib/gzipfile/close_spec.rb index 870870f2fa4306..964b5ffb4dcd44 100644 --- a/spec/ruby/library/zlib/gzipfile/close_spec.rb +++ b/spec/ruby/library/zlib/gzipfile/close_spec.rb @@ -8,7 +8,7 @@ Zlib::GzipWriter.wrap io do |gzio| gzio.close - gzio.closed?.should == true + gzio.should.closed? -> { gzio.orig_name }.should \ raise_error(Zlib::GzipFile::Error, 'closed gzip stream') diff --git a/spec/ruby/library/zlib/gzipfile/closed_spec.rb b/spec/ruby/library/zlib/gzipfile/closed_spec.rb index b885add485d0db..726f391b4150e1 100644 --- a/spec/ruby/library/zlib/gzipfile/closed_spec.rb +++ b/spec/ruby/library/zlib/gzipfile/closed_spec.rb @@ -6,11 +6,11 @@ it "returns the closed status" do io = StringIO.new Zlib::GzipWriter.wrap io do |gzio| - gzio.closed?.should == false + gzio.should_not.closed? gzio.close - gzio.closed?.should == true + gzio.should.closed? end end end diff --git a/spec/ruby/library/zlib/zstream/flush_next_out_spec.rb b/spec/ruby/library/zlib/zstream/flush_next_out_spec.rb index 59a0622903eb07..63676a82032ae4 100644 --- a/spec/ruby/library/zlib/zstream/flush_next_out_spec.rb +++ b/spec/ruby/library/zlib/zstream/flush_next_out_spec.rb @@ -8,7 +8,7 @@ zs << [120, 156, 75, 203, 207, 7, 0, 2, 130, 1, 69].pack('C*') zs.flush_next_out.should == 'foo' - zs.finished?.should == true + zs.should.finished? zs.flush_next_out.should == '' end end diff --git a/spec/ruby/optional/capi/class_spec.rb b/spec/ruby/optional/capi/class_spec.rb index 0b03fb9e6c8c19..c2424668b91f53 100644 --- a/spec/ruby/optional/capi/class_spec.rb +++ b/spec/ruby/optional/capi/class_spec.rb @@ -1,5 +1,6 @@ require_relative 'spec_helper' require_relative 'fixtures/class' +require_relative '../../core/module/fixtures/classes' load_extension("class") compile_extension("class_under_autoload") @@ -39,6 +40,69 @@ @s = CApiClassSpecs.new end + describe "rb_class_instance_methods" do + it "returns the public and protected methods of self and its ancestors" do + methods = @s.rb_class_instance_methods(ModuleSpecs::Basic) + methods.should include(:protected_module, :public_module) + + methods = @s.rb_class_instance_methods(ModuleSpecs::Basic, true) + methods.should include(:protected_module, :public_module) + end + + it "when passed false as a parameter, returns the instance methods of the class" do + methods = @s.rb_class_instance_methods(ModuleSpecs::Child, false) + methods.should include(:protected_child, :public_child) + end + end + + describe "rb_class_public_instance_methods" do + it "returns a list of public methods in module and its ancestors" do + methods = @s.rb_class_public_instance_methods(ModuleSpecs::CountsChild) + methods.should include(:public_3) + methods.should include(:public_2) + methods.should include(:public_1) + + methods = @s.rb_class_public_instance_methods(ModuleSpecs::CountsChild, true) + methods.should include(:public_3) + methods.should include(:public_2) + methods.should include(:public_1) + end + + it "when passed false as a parameter, should return only methods defined in that module" do + @s.rb_class_public_instance_methods(ModuleSpecs::CountsChild, false).should == [:public_1] + end + end + + describe "rb_class_protected_instance_methods" do + it "returns a list of protected methods in module and its ancestors" do + methods = @s.rb_class_protected_instance_methods(ModuleSpecs::CountsChild) + methods.should include(:protected_3) + methods.should include(:protected_2) + methods.should include(:protected_1) + + methods = @s.rb_class_protected_instance_methods(ModuleSpecs::CountsChild, true) + methods.should include(:protected_3) + methods.should include(:protected_2) + methods.should include(:protected_1) + end + + it "when passed false as a parameter, should return only methods defined in that module" do + @s.rb_class_public_instance_methods(ModuleSpecs::CountsChild, false).should == [:public_1] + end + end + + describe "rb_class_private_instance_methods" do + it "returns a list of private methods in module and its ancestors" do + @s.rb_class_private_instance_methods(ModuleSpecs::CountsChild).should == ModuleSpecs::CountsChild.private_instance_methods + @s.rb_class_private_instance_methods(ModuleSpecs::CountsChild, true).should == ModuleSpecs::CountsChild.private_instance_methods + end + + it "when passed false as a parameter, should return only methods defined in that module" do + methods = @s.rb_class_private_instance_methods(ModuleSpecs::CountsChild, false) + methods.should == [:private_1] + end + end + describe "rb_class_new_instance" do it "allocates and initializes a new object" do o = @s.rb_class_new_instance(0, nil, CApiClassSpecs::Alloc) @@ -338,7 +402,7 @@ end describe "rb_class_new" do - it "returns an new subclass of the superclass" do + it "returns a new subclass of the superclass" do subclass = @s.rb_class_new(CApiClassSpecs::NewClass) CApiClassSpecs::NewClass.should be_ancestor_of(subclass) end diff --git a/spec/ruby/optional/capi/ext/class_spec.c b/spec/ruby/optional/capi/ext/class_spec.c index e62b9efe2e0ca9..36b8c8f2f30a7b 100644 --- a/spec/ruby/optional/capi/ext/class_spec.c +++ b/spec/ruby/optional/capi/ext/class_spec.c @@ -37,6 +37,26 @@ static VALUE class_spec_rb_path_to_class(VALUE self, VALUE path) { return rb_path_to_class(path); } +static VALUE class_spec_rb_class_instance_methods(int argc, VALUE* argv, VALUE self) { + VALUE mod = argv[0]; + return rb_class_instance_methods(--argc, ++argv, mod); +} + +static VALUE class_spec_rb_class_public_instance_methods(int argc, VALUE* argv, VALUE self) { + VALUE mod = argv[0]; + return rb_class_public_instance_methods(--argc, ++argv, mod); +} + +static VALUE class_spec_rb_class_protected_instance_methods(int argc, VALUE* argv, VALUE self) { + VALUE mod = argv[0]; + return rb_class_protected_instance_methods(--argc, ++argv, mod); +} + +static VALUE class_spec_rb_class_private_instance_methods(int argc, VALUE* argv, VALUE self) { + VALUE mod = argv[0]; + return rb_class_private_instance_methods(--argc, ++argv, mod); +} + static VALUE class_spec_rb_class_new(VALUE self, VALUE super) { return rb_class_new(super); } @@ -146,6 +166,10 @@ void Init_class_spec(void) { rb_define_method(cls, "rb_class2name", class_spec_rb_class2name, 1); rb_define_method(cls, "rb_path2class", class_spec_rb_path2class, 1); rb_define_method(cls, "rb_path_to_class", class_spec_rb_path_to_class, 1); + rb_define_method(cls, "rb_class_instance_methods", class_spec_rb_class_instance_methods, -1); + rb_define_method(cls, "rb_class_public_instance_methods", class_spec_rb_class_public_instance_methods, -1); + rb_define_method(cls, "rb_class_protected_instance_methods", class_spec_rb_class_protected_instance_methods, -1); + rb_define_method(cls, "rb_class_private_instance_methods", class_spec_rb_class_private_instance_methods, -1); rb_define_method(cls, "rb_class_new", class_spec_rb_class_new, 1); rb_define_method(cls, "rb_class_new_instance", class_spec_rb_class_new_instance, 3); rb_define_method(cls, "rb_class_real", class_spec_rb_class_real, 1); diff --git a/spec/ruby/optional/capi/ext/rbasic_spec.c b/spec/ruby/optional/capi/ext/rbasic_spec.c new file mode 100644 index 00000000000000..c08c821a385901 --- /dev/null +++ b/spec/ruby/optional/capi/ext/rbasic_spec.c @@ -0,0 +1,79 @@ +#include "ruby.h" +#include "rubyspec.h" + +#ifdef __cplusplus +extern "C" { +#endif + +static const VALUE VISIBLE_BITS = FL_TAINT | FL_FREEZE | ~(FL_USER0 - 1); + +VALUE rbasic_spec_taint_flag(VALUE self) { + return INT2FIX(RUBY_FL_TAINT); +} + +VALUE rbasic_spec_freeze_flag(VALUE self) { + return INT2FIX(RUBY_FL_FREEZE); +} + +static VALUE spec_get_flags(const struct RBasic *b) { + VALUE flags = b->flags & VISIBLE_BITS; + return INT2FIX(flags); +} + +static VALUE spec_set_flags(struct RBasic *b, VALUE flags) { + flags &= VISIBLE_BITS; + b->flags = (b->flags & ~VISIBLE_BITS) | flags; + return INT2FIX(flags); +} + +VALUE rbasic_spec_get_flags(VALUE self, VALUE val) { + return spec_get_flags(RBASIC(val)); +} + +VALUE rbasic_spec_set_flags(VALUE self, VALUE val, VALUE flags) { + return spec_set_flags(RBASIC(val), FIX2INT(flags)); +} + +VALUE rbasic_spec_copy_flags(VALUE self, VALUE to, VALUE from) { + return spec_set_flags(RBASIC(to), RBASIC(from)->flags); +} + +VALUE rbasic_spec_get_klass(VALUE self, VALUE val) { + return RBASIC(val)->klass; +} + +VALUE rbasic_rdata_spec_get_flags(VALUE self, VALUE structure) { + return spec_get_flags(&RDATA(structure)->basic); +} + +VALUE rbasic_rdata_spec_set_flags(VALUE self, VALUE structure, VALUE flags) { + return spec_set_flags(&RDATA(structure)->basic, FIX2INT(flags)); +} + +VALUE rbasic_rdata_spec_copy_flags(VALUE self, VALUE to, VALUE from) { + return spec_set_flags(&RDATA(to)->basic, RDATA(from)->basic.flags); +} + +VALUE rbasic_rdata_spec_get_klass(VALUE self, VALUE structure) { + return RDATA(structure)->basic.klass; +} + +void Init_rbasic_spec(void) { + VALUE cls = rb_define_class("CApiRBasicSpecs", rb_cObject); + rb_define_method(cls, "taint_flag", rbasic_spec_taint_flag, 0); + rb_define_method(cls, "freeze_flag", rbasic_spec_freeze_flag, 0); + rb_define_method(cls, "get_flags", rbasic_spec_get_flags, 1); + rb_define_method(cls, "set_flags", rbasic_spec_set_flags, 2); + rb_define_method(cls, "copy_flags", rbasic_spec_copy_flags, 2); + rb_define_method(cls, "get_klass", rbasic_spec_get_klass, 1); + + cls = rb_define_class("CApiRBasicRDataSpecs", rb_cObject); + rb_define_method(cls, "get_flags", rbasic_rdata_spec_get_flags, 1); + rb_define_method(cls, "set_flags", rbasic_rdata_spec_set_flags, 2); + rb_define_method(cls, "copy_flags", rbasic_rdata_spec_copy_flags, 2); + rb_define_method(cls, "get_klass", rbasic_rdata_spec_get_klass, 1); +} + +#ifdef __cplusplus +} +#endif diff --git a/spec/ruby/optional/capi/ext/symbol_spec.c b/spec/ruby/optional/capi/ext/symbol_spec.c index d2ca62d81ed760..7d9a7b4379554a 100644 --- a/spec/ruby/optional/capi/ext/symbol_spec.c +++ b/spec/ruby/optional/capi/ext/symbol_spec.c @@ -75,6 +75,10 @@ VALUE symbol_spec_rb_sym2str(VALUE self, VALUE sym) { return rb_sym2str(sym); } +VALUE symbol_spec_rb_to_symbol(VALUE self, VALUE val) { + return rb_to_symbol(val); +} + void Init_symbol_spec(void) { VALUE cls = rb_define_class("CApiSymbolSpecs", rb_cObject); rb_define_method(cls, "SYMBOL_P", symbol_spec_SYMBOL_P, 1); @@ -93,6 +97,7 @@ void Init_symbol_spec(void) { rb_define_method(cls, "rb_is_const_id", symbol_spec_rb_is_const_id, 1); rb_define_method(cls, "rb_is_instance_id", symbol_spec_rb_is_instance_id, 1); rb_define_method(cls, "rb_sym2str", symbol_spec_rb_sym2str, 1); + rb_define_method(cls, "rb_to_symbol", symbol_spec_rb_to_symbol, 1); } #ifdef __cplusplus diff --git a/spec/ruby/optional/capi/ext/tracepoint_spec.c b/spec/ruby/optional/capi/ext/tracepoint_spec.c new file mode 100644 index 00000000000000..78c459d6cbe1f7 --- /dev/null +++ b/spec/ruby/optional/capi/ext/tracepoint_spec.c @@ -0,0 +1,49 @@ +#include "ruby.h" +#include "rubyspec.h" + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +static VALUE callback_called = Qnil; + +static void callback(VALUE tpval, void *data) { + callback_called = (VALUE) data; +} + +static VALUE tracepoint_spec_rb_tracepoint_new(VALUE self, VALUE data) { + return rb_tracepoint_new(Qnil, RUBY_EVENT_LINE, callback, (void*) data); +} + +static VALUE tracepoint_spec_callback_called(VALUE self){ + return callback_called; +} + +static VALUE tracepoint_spec_rb_tracepoint_disable(VALUE self, VALUE trace) { + rb_tracepoint_disable(trace); + return rb_tracepoint_enabled_p(trace); +} + +static VALUE tracepoint_spec_rb_tracepoint_enable(VALUE self, VALUE trace) { + rb_tracepoint_enable(trace); + return rb_tracepoint_enabled_p(trace); +} + +static VALUE tracepoint_spec_rb_tracepoint_enabled_p(VALUE self, VALUE trace) { + return rb_tracepoint_enabled_p(trace); +} + +void Init_tracepoint_spec(void) { + VALUE cls = rb_define_class("CApiTracePointSpecs", rb_cObject); + rb_define_method(cls, "rb_tracepoint_new", tracepoint_spec_rb_tracepoint_new, 1); + rb_define_method(cls, "rb_tracepoint_disable", tracepoint_spec_rb_tracepoint_disable, 1); + rb_define_method(cls, "rb_tracepoint_enable", tracepoint_spec_rb_tracepoint_enable, 1); + rb_define_method(cls, "rb_tracepoint_enabled_p", tracepoint_spec_rb_tracepoint_enabled_p, 1); + rb_define_method(cls, "callback_called?", tracepoint_spec_callback_called, 0); +} + +#ifdef __cplusplus +} +#endif diff --git a/spec/ruby/optional/capi/kernel_spec.rb b/spec/ruby/optional/capi/kernel_spec.rb index ff882035010726..cbd0a50deaaba4 100644 --- a/spec/ruby/optional/capi/kernel_spec.rb +++ b/spec/ruby/optional/capi/kernel_spec.rb @@ -9,7 +9,7 @@ describe "rb_block_given_p" do it "returns false if no block is passed" do - @s.rb_block_given_p.should == false + @s.should_not.rb_block_given_p end it "returns true if a block is passed" do @@ -483,7 +483,7 @@ def proc_caller proc = @s.rb_block_proc { 1+1 } proc.should be_kind_of(Proc) proc.call.should == 2 - proc.lambda?.should == false + proc.should_not.lambda? end it "passes through an existing lambda and does not convert to a proc" do @@ -491,7 +491,7 @@ def proc_caller proc = @s.rb_block_proc(&b) proc.should equal(b) proc.call.should == 2 - proc.lambda?.should == true + proc.should.lambda? end end @@ -500,7 +500,7 @@ def proc_caller proc = @s.rb_block_lambda { 1+1 } proc.should be_kind_of(Proc) proc.call.should == 2 - proc.lambda?.should == true + proc.should.lambda? end it "passes through an existing Proc and does not convert to a lambda" do @@ -508,7 +508,7 @@ def proc_caller proc = @s.rb_block_lambda(&b) proc.should equal(b) proc.call.should == 2 - proc.lambda?.should == false + proc.should_not.lambda? end end diff --git a/spec/ruby/optional/capi/object_spec.rb b/spec/ruby/optional/capi/object_spec.rb index 8b9e8bbc251174..bbcaec2ba8a05d 100644 --- a/spec/ruby/optional/capi/object_spec.rb +++ b/spec/ruby/optional/capi/object_spec.rb @@ -675,9 +675,9 @@ def reach ruby_version_is ''...'2.7' do it "marks the object passed as tainted" do obj = "" - obj.tainted?.should == false + obj.should_not.tainted? @o.rb_obj_taint(obj) - obj.tainted?.should == true + obj.should.tainted? end it "raises a FrozenError if the object passed is frozen" do diff --git a/spec/ruby/optional/capi/rbasic_spec.rb b/spec/ruby/optional/capi/rbasic_spec.rb new file mode 100644 index 00000000000000..283e70db706adc --- /dev/null +++ b/spec/ruby/optional/capi/rbasic_spec.rb @@ -0,0 +1,22 @@ +require_relative 'spec_helper' +require_relative 'shared/rbasic' +load_extension("rbasic") +load_extension("data") +load_extension("array") + +describe "RBasic support for regular objects" do + before :all do + @specs = CApiRBasicSpecs.new + @data = -> { [Object.new, Object.new] } + end + it_should_behave_like :rbasic +end + +describe "RBasic support for RData" do + before :all do + @specs = CApiRBasicRDataSpecs.new + @wrapping = CApiWrappedStructSpecs.new + @data = -> { [@wrapping.wrap_struct(1024), @wrapping.wrap_struct(1025)] } + end + it_should_behave_like :rbasic +end diff --git a/spec/ruby/optional/capi/shared/rbasic.rb b/spec/ruby/optional/capi/shared/rbasic.rb new file mode 100644 index 00000000000000..c25733f862bef6 --- /dev/null +++ b/spec/ruby/optional/capi/shared/rbasic.rb @@ -0,0 +1,83 @@ +describe :rbasic, shared: true do + + before :all do + specs = CApiRBasicSpecs.new + @taint = specs.taint_flag + @freeze = specs.freeze_flag + end + + it "reports the appropriate FREEZE flag for the object when reading" do + obj, _ = @data.call + initial = @specs.get_flags(obj) + obj.freeze + @specs.get_flags(obj).should == @freeze | initial + end + + it "supports setting the FREEZE flag" do + obj, _ = @data.call + initial = @specs.get_flags(obj) + @specs.set_flags(obj, @freeze | initial).should == @freeze | initial + obj.should.frozen? + end + + ruby_version_is ""..."2.7" do + it "reports the appropriate FREEZE and TAINT flags for the object when reading" do + obj, _ = @data.call + initial = @specs.get_flags(obj) + obj.taint + @specs.get_flags(obj).should == @taint | initial + obj.untaint + @specs.get_flags(obj).should == initial + obj.freeze + @specs.get_flags(obj).should == @freeze | initial + + obj, _ = @data.call + obj.taint + obj.freeze + @specs.get_flags(obj).should == @freeze | @taint | initial + end + + it "supports setting the FREEZE and TAINT flags" do + obj, _ = @data.call + initial = @specs.get_flags(obj) + @specs.set_flags(obj, @taint | initial).should == @taint | initial + obj.should.tainted? + @specs.set_flags(obj, initial).should == initial + obj.should_not.tainted? + @specs.set_flags(obj, @freeze | initial).should == @freeze | initial + obj.should.frozen? + + obj, _ = @data.call + @specs.set_flags(obj, @freeze | @taint | initial).should == @freeze | @taint | initial + obj.should.tainted? + obj.should.frozen? + end + end + + it "supports user flags" do + obj, _ = @data.call + initial = @specs.get_flags(obj) + @specs.set_flags(obj, 1 << 14 | 1 << 16 | initial).should == 1 << 14 | 1 << 16 | initial + @specs.get_flags(obj).should == 1 << 14 | 1 << 16 | initial + @specs.set_flags(obj, initial).should == initial + end + + it "supports copying the flags from one object over to the other" do + obj1, obj2 = @data.call + initial = @specs.get_flags(obj1) + @specs.get_flags(obj2).should == initial + @specs.set_flags(obj1, @taint | 1 << 14 | 1 << 16 | initial) + @specs.copy_flags(obj2, obj1) + @specs.get_flags(obj2).should == @taint | 1 << 14 | 1 << 16 | initial + @specs.set_flags(obj1, initial) + @specs.copy_flags(obj2, obj1) + @specs.get_flags(obj2).should == initial + end + + it "supports retrieving the (meta)class" do + obj, _ = @data.call + @specs.get_klass(obj).should == obj.class + obj.singleton_class # ensure the singleton class exists + @specs.get_klass(obj).should == obj.singleton_class + end +end diff --git a/spec/ruby/optional/capi/string_spec.rb b/spec/ruby/optional/capi/string_spec.rb index 224d63f8860fe5..57ac9545f44155 100644 --- a/spec/ruby/optional/capi/string_spec.rb +++ b/spec/ruby/optional/capi/string_spec.rb @@ -76,7 +76,7 @@ def inspect it "invalidates the code range" do @s.rb_str_set_len(@str, 4) - @str.ascii_only?.should == true + @str.should.ascii_only? end it "updates the string's attributes visible in C code" do @@ -183,7 +183,7 @@ def inspect ruby_version_is ''...'2.7' do it "returns a non-tainted string" do - @s.rb_str_new("hello", 5).tainted?.should == false + @s.rb_str_new("hello", 5).should_not.tainted? end end @@ -288,8 +288,8 @@ def inspect str2 = @s.rb_str_new4 str1 str1.should == str2 str1.should equal(str2) - str1.frozen?.should == true - str2.frozen?.should == true + str1.should.frozen? + str2.should.frozen? end it "returns a frozen copy of the string" do @@ -297,7 +297,7 @@ def inspect str2 = @s.rb_str_new4 str1 str1.should == str2 str1.should_not equal(str2) - str2.frozen?.should == true + str2.should.frozen? end end diff --git a/spec/ruby/optional/capi/symbol_spec.rb b/spec/ruby/optional/capi/symbol_spec.rb index 0d71c1c7114a2b..b8fda34c0ed09f 100644 --- a/spec/ruby/optional/capi/symbol_spec.rb +++ b/spec/ruby/optional/capi/symbol_spec.rb @@ -153,4 +153,20 @@ @s.rb_sym2str(:bacon).should == "bacon" end end + + describe "rb_to_symbol" do + it "returns a Symbol for a Symbol" do + @s.rb_to_symbol(:foo).should == :foo + end + + it "returns a Symbol for a String" do + @s.rb_to_symbol("foo").should == :foo + end + + it "coerces to Symbol using to_str" do + o = mock('o') + o.should_receive(:to_str).and_return("foo") + @s.rb_to_symbol(o).should == :foo + end + end end diff --git a/spec/ruby/optional/capi/tracepoint_spec.rb b/spec/ruby/optional/capi/tracepoint_spec.rb new file mode 100644 index 00000000000000..2043b7c9418d71 --- /dev/null +++ b/spec/ruby/optional/capi/tracepoint_spec.rb @@ -0,0 +1,56 @@ +require_relative 'spec_helper' + +load_extension("tracepoint") + +describe "CApiTracePointSpecs" do + before :each do + @s = CApiTracePointSpecs.new + end + + after :each do + @trace.disable if @trace and @trace.enabled? + end + + describe "rb_tracepoint_new" do + it "returns a tracepoint object" do + @trace = @s.rb_tracepoint_new(7) + @trace.should be_an_instance_of(TracePoint) + @trace.should_not.enabled? + end + + it "traces lines when given RUBY_EVENT_LINE" do + @trace = @s.rb_tracepoint_new(8) + @trace.enable + @s.callback_called?.should == 8 + end + end + + describe "rb_tracepoint_disable" do + it "disables an enabled TracePoint" do + @trace = @s.rb_tracepoint_new(9) + @trace.should_not.enabled? + @trace.enable + @trace.should.enabled? + @s.rb_tracepoint_disable(@trace).should == false + @trace.should_not.enabled? + end + end + + describe "rb_tracepoint_enable" do + it "enables a disabled TracePoint" do + @trace = @s.rb_tracepoint_new(10) + @trace.should_not.enabled? + @s.rb_tracepoint_enable(@trace).should == true + @trace.should.enabled? + end + end + + describe "rb_tracepoint_enabled_p" do + it "returns correct enabled status" do + @trace = @s.rb_tracepoint_new(11) + @s.rb_tracepoint_enabled_p(@trace).should == false + @trace.enable + @s.rb_tracepoint_enabled_p(@trace).should == true + end + end +end diff --git a/spec/ruby/security/cve_2020_10663_spec.rb b/spec/ruby/security/cve_2020_10663_spec.rb index e305c0b593d4d2..634afda52557c6 100644 --- a/spec/ruby/security/cve_2020_10663_spec.rb +++ b/spec/ruby/security/cve_2020_10663_spec.rb @@ -26,7 +26,7 @@ def to_json(*args) describe "CVE-2020-10663 is resisted by" do it "only creating custom objects if passed create_additions: true or using JSON.load" do obj = JSONSpecs::MyClass.new("bar") - JSONSpecs::MyClass.json_creatable?.should == true + JSONSpecs::MyClass.should.json_creatable? json = JSON.dump(obj) JSON.parse(json, create_additions: true).class.should == JSONSpecs::MyClass diff --git a/spec/ruby/shared/file/world_readable.rb b/spec/ruby/shared/file/world_readable.rb index 85761e633f2be4..c2c62646277fd9 100644 --- a/spec/ruby/shared/file/world_readable.rb +++ b/spec/ruby/shared/file/world_readable.rb @@ -35,7 +35,7 @@ end it "returns a Fixnum if the file is a directory and chmod 644" do - dir = rand().to_s + '-ww' + dir = tmp(rand().to_s + '-ww') Dir.mkdir(dir) Dir.should.exist?(dir) File.chmod(0644, dir) diff --git a/spec/ruby/shared/file/world_writable.rb b/spec/ruby/shared/file/world_writable.rb index 61b691bcb6d162..84d7deb5d3eba1 100644 --- a/spec/ruby/shared/file/world_writable.rb +++ b/spec/ruby/shared/file/world_writable.rb @@ -34,7 +34,7 @@ end it "returns a Fixnum if the file is a directory and chmod 777" do - dir = rand().to_s + '-ww' + dir = tmp(rand().to_s + '-ww') Dir.mkdir(dir) Dir.should.exist?(dir) File.chmod(0777, dir) diff --git a/spec/ruby/shared/string/times.rb b/spec/ruby/shared/string/times.rb index 6b45f7aa1e7e83..6827db22713844 100644 --- a/spec/ruby/shared/string/times.rb +++ b/spec/ruby/shared/string/times.rb @@ -38,7 +38,7 @@ class MyString < String; end str.taint [0, 1, 2].each do |arg| - @object.call(str, arg).tainted?.should == true + @object.call(str, arg).should.tainted? end end end diff --git a/string.c b/string.c index b17d41158cfef4..97c7a048288b41 100644 --- a/string.c +++ b/string.c @@ -76,8 +76,6 @@ #undef rb_str_cat_cstr #undef rb_fstring_cstr -static VALUE rb_str_clear(VALUE str); - VALUE rb_cString; VALUE rb_cSymbol; diff --git a/test/-ext-/debug/test_profile_frames.rb b/test/-ext-/debug/test_profile_frames.rb index 5ea506046e45d7..f2e28b7ce95ef9 100644 --- a/test/-ext-/debug/test_profile_frames.rb +++ b/test/-ext-/debug/test_profile_frames.rb @@ -5,11 +5,19 @@ class SampleClassForTestProfileFrames class Sample2 def baz(block) - instance_eval "def zab(block) block.call end" + instance_eval "def zab(block) Sample3.qux(block) end" [self, zab(block)] end end + module Sample3 + class << self + def qux(block) + block.call + end + end + end + def self.bar(block) Sample2.new.baz(block) end diff --git a/test/irb/test_cmd.rb b/test/irb/test_cmd.rb new file mode 100644 index 00000000000000..e50d036f1976f8 --- /dev/null +++ b/test/irb/test_cmd.rb @@ -0,0 +1,122 @@ +# frozen_string_literal: false +require "test/unit" +require "irb" +require "irb/extend-command" + +module TestIRB + class ExtendCommand < Test::Unit::TestCase + def setup + @pwd = Dir.pwd + @tmpdir = File.join(Dir.tmpdir, "test_reline_config_#{$$}") + begin + Dir.mkdir(@tmpdir) + rescue Errno::EEXIST + FileUtils.rm_rf(@tmpdir) + Dir.mkdir(@tmpdir) + end + Dir.chdir(@tmpdir) + @home_backup = ENV["HOME"] + ENV["HOME"] = @tmpdir + @default_encoding = [Encoding.default_external, Encoding.default_internal] + end + + def teardown + ENV["HOME"] = @home_backup + Dir.chdir(@pwd) + FileUtils.rm_rf(@tmpdir) + EnvUtil.suppress_warning { + Encoding.default_external, Encoding.default_internal = *@default_encoding + } + end + + def test_irb_info_multiline + FileUtils.touch("#{@tmpdir}/.inputrc") + FileUtils.touch("#{@tmpdir}/.irbrc") + IRB.setup(__FILE__, argv: []) + IRB.conf[:USE_MULTILINE] = true + IRB.conf[:USE_SINGLELINE] = false + IRB.conf[:VERBOSE] = false + workspace = IRB::WorkSpace.new(self) + irb = IRB::Irb.new(workspace) + IRB.conf[:MAIN_CONTEXT] = irb.context + expected = %r{ + Ruby\sversion: .+\n + IRB\sversion:\sirb .+\n + InputMethod:\sReidlineInputMethod\swith\sReline .+ and .+\n + \.irbrc\spath: .+ + }x + assert_match expected, irb.context.main.irb_info.to_s + end + + def test_irb_info_singleline + FileUtils.touch("#{@tmpdir}/.inputrc") + FileUtils.touch("#{@tmpdir}/.irbrc") + IRB.setup(__FILE__, argv: []) + IRB.conf[:USE_MULTILINE] = false + IRB.conf[:USE_SINGLELINE] = true + IRB.conf[:VERBOSE] = false + workspace = IRB::WorkSpace.new(self) + irb = IRB::Irb.new(workspace) + IRB.conf[:MAIN_CONTEXT] = irb.context + expected = %r{ + Ruby\sversion: .+\n + IRB\sversion:\sirb .+\n + InputMethod:\sReadlineInputMethod\swith .+ and .+\n + \.irbrc\spath: .+ + }x + assert_match expected, irb.context.main.irb_info.to_s + end + + def test_irb_info_multiline_without_rc_files + inputrc_backup = ENV["INPUTRC"] + ENV["INPUTRC"] = "unkown_inpurc" + ext_backup = IRB::IRBRC_EXT + IRB.__send__(:remove_const, :IRBRC_EXT) + IRB.const_set(:IRBRC_EXT, "unkown_ext") + IRB.setup(__FILE__, argv: []) + IRB.conf[:USE_MULTILINE] = true + IRB.conf[:USE_SINGLELINE] = false + IRB.conf[:VERBOSE] = false + workspace = IRB::WorkSpace.new(self) + irb = IRB::Irb.new(workspace) + IRB.conf[:MAIN_CONTEXT] = irb.context + expected = %r{ + Ruby\sversion: .+\n + IRB\sversion:\sirb .+\n + InputMethod:\sReidlineInputMethod\swith\sReline\s[^ ]+(?!\sand\s.+)\n + \z + }x + assert_match expected, irb.context.main.irb_info.to_s + ensure + ENV["INPUTRC"] = inputrc_backup + IRB.__send__(:remove_const, :IRBRC_EXT) + IRB.const_set(:IRBRC_EXT, ext_backup) + end + + def test_irb_info_singleline_without_rc_files + inputrc_backup = ENV["INPUTRC"] + ENV["INPUTRC"] = "unkown_inpurc" + ext_backup = IRB::IRBRC_EXT + IRB.__send__(:remove_const, :IRBRC_EXT) + IRB.const_set(:IRBRC_EXT, "unkown_ext") + IRB.setup(__FILE__, argv: []) + IRB.conf[:USE_MULTILINE] = false + IRB.conf[:USE_SINGLELINE] = true + IRB.conf[:VERBOSE] = false + workspace = IRB::WorkSpace.new(self) + irb = IRB::Irb.new(workspace) + IRB.conf[:MAIN_CONTEXT] = irb.context + expected = %r{ + Ruby\sversion: .+\n + IRB\sversion:\sirb .+\n + InputMethod:\sReadlineInputMethod\swith\s(?~.*\sand\s.+)\n + \z + }x + assert_match expected, irb.context.main.irb_info.to_s + ensure + ENV["INPUTRC"] = inputrc_backup + IRB.__send__(:remove_const, :IRBRC_EXT) + IRB.const_set(:IRBRC_EXT, ext_backup) + end + end +end diff --git a/test/lib/jit_support.rb b/test/lib/jit_support.rb index b26a5febe43ba9..4232f01a8e2011 100644 --- a/test/lib/jit_support.rb +++ b/test/lib/jit_support.rb @@ -9,9 +9,11 @@ module JITSupport %r[\A.*/bin/intel64/icc\b], %r[\A/opt/developerstudio\d+\.\d+/bin/cc\z], ] + # debian-riscv64: "gcc: internal compiler error: Segmentation fault signal terminated program cc1" https://rubyci.org/logs/rubyci.s3.amazonaws.com/debian-riscv64/ruby-master/log/20200420T083601Z.fail.html.gz # freebsd12: cc1 internal failure https://rubyci.org/logs/rubyci.s3.amazonaws.com/freebsd12/ruby-master/log/20200306T103003Z.fail.html.gz # rhel8: one or more PCH files were found, but they were invalid https://rubyci.org/logs/rubyci.s3.amazonaws.com/rhel8/ruby-master/log/20200306T153003Z.fail.html.gz PENDING_RUBYCI_NICKNAMES = %w[ + debian-riscv64 freebsd12 rhel8 ] @@ -52,21 +54,21 @@ def eval_with_jit_without_retry(env = nil, script, verbose: 0, min_calls: 5, sav def supported? return @supported if defined?(@supported) - @supported = UNSUPPORTED_COMPILERS.all? do |regexp| + @supported = RbConfig::CONFIG["MJIT_SUPPORT"] != 'no' && UNSUPPORTED_COMPILERS.all? do |regexp| !regexp.match?(RbConfig::CONFIG['MJIT_CC']) - end && RbConfig::CONFIG["MJIT_SUPPORT"] != 'no' && !PENDING_RUBYCI_NICKNAMES.include?(ENV['RUBYCI_NICKNAME']) && !vs120_pdb_corrupted? + end && !appveyor_pdb_corrupted? && !PENDING_RUBYCI_NICKNAMES.include?(ENV['RUBYCI_NICKNAME']) end - # AppVeyor's Visual Studio 2013 is known to spuriously generate broken pch / pdb, like: + # AppVeyor's Visual Studio 2013 / 2015 are known to spuriously generate broken pch / pdb, like: # error C2859: c:\projects\ruby\x64-mswin_120\include\ruby-2.8.0\x64-mswin64_120\rb_mjit_header-2.8.0.pdb # is not the pdb file that was used when this precompiled header was created, recreate the precompiled header. # https://ci.appveyor.com/project/ruby/ruby/builds/32159878/job/l2p38snw8yxxpp8h # # Until we figure out why, this allows us to skip testing JIT when it happens. - def vs120_pdb_corrupted? + def appveyor_pdb_corrupted? return false unless ENV.key?('APPVEYOR') - _stdout, stderr, status = eval_with_jit_without_retry('proc {}.call', verbose: 2, min_calls: 1) - !status.success? && stderr.include?('x64-mswin64_120') && stderr.include?('.pdb is not the pdb file that was used when this precompiled header was created, recreate the precompiled header.') + stdout, _stderr, _status = eval_with_jit_without_retry('proc {}.call', verbose: 2, min_calls: 1) + stdout.include?('.pdb is not the pdb file that was used when this precompiled header was created, recreate the precompiled header.') end def remove_mjit_logs(stderr) diff --git a/test/matrix/test_matrix.rb b/test/matrix/test_matrix.rb index 7dbb1000d9faee..b134bfb3a10ab0 100644 --- a/test/matrix/test_matrix.rb +++ b/test/matrix/test_matrix.rb @@ -18,6 +18,7 @@ def setup @a3 = Matrix[[4, 1, -3], [0, 3, 7], [11, -4, 2]] @a5 = Matrix[[2, 0, 9, 3, 9], [8, 7, 0, 1, 9], [7, 5, 6, 6, 5], [0, 7, 8, 3, 0], [7, 8, 2, 3, 1]] @b3 = Matrix[[-7, 7, -10], [9, -3, -2], [-1, 3, 9]] + @rot = Matrix[[0, -1, 0], [1, 0, 0], [0, 0, -1]] end def test_matrix @@ -792,4 +793,23 @@ def test_eigenvalues_and_eigenvectors_nonsymmetric assert_in_epsilon(vectors[0][0], vectors[0][1]) assert_in_epsilon(-4 * vectors[1][0], vectors[1][1]) end + + def test_unitary? + assert_equal true, @rot.unitary? + assert_equal true, ((0+1i) * @rot).unitary? + assert_equal false, @a3.unitary? + assert_raise(Matrix::ErrDimensionMismatch) { @m1.unitary? } + end + + def test_orthogonal + assert_equal true, @rot.orthogonal? + assert_equal false, ((0+1i) * @rot).orthogonal? + assert_equal false, @a3.orthogonal? + assert_raise(Matrix::ErrDimensionMismatch) { @m1.orthogonal? } + end + + def test_adjoint + assert_equal(Matrix[[(1-2i), 1], [(0-1i), 2], [0, 3]], @c1.adjoint) + assert_equal(Matrix.empty(0,2), @e1.adjoint) + end end diff --git a/test/rdoc/support/test_case.rb b/test/rdoc/support/test_case.rb index 9a4f04b76e654d..bce480252ff123 100644 --- a/test/rdoc/support/test_case.rb +++ b/test/rdoc/support/test_case.rb @@ -49,6 +49,9 @@ class RDoc::TestCase < Test::Unit::TestCase def setup super + @orig_home = ENV["HOME"] + ENV["HOME"] = Dir.tmpdir + @top_level = nil @RM = RDoc::Markup @@ -69,6 +72,15 @@ def g.file_dir() end RDoc::Markup::PreProcess.reset end + ## + # Abstract test-case teardown + + def teardown + ENV["HOME"] = @orig_home + + super + end + ## # Asserts +path+ is a file diff --git a/test/rdoc/test_rdoc_markdown.rb b/test/rdoc/test_rdoc_markdown.rb index 021d94297be014..9c7a406224d4b9 100644 --- a/test/rdoc/test_rdoc_markdown.rb +++ b/test/rdoc/test_rdoc_markdown.rb @@ -8,6 +8,8 @@ class TestRDocMarkdown < RDoc::TestCase def setup + super + @RM = RDoc::Markup @parser = RDoc::Markdown.new diff --git a/test/rdoc/test_rdoc_parser_changelog.rb b/test/rdoc/test_rdoc_parser_changelog.rb index cb6406259c5509..d93cb7decae70d 100644 --- a/test/rdoc/test_rdoc_parser_changelog.rb +++ b/test/rdoc/test_rdoc_parser_changelog.rb @@ -14,6 +14,8 @@ def setup def teardown @tempfile.close! + + super end def test_class_can_parse diff --git a/test/rdoc/test_rdoc_ri_driver.rb b/test/rdoc/test_rdoc_ri_driver.rb index 6f17fecec919ba..f79d17b1cd087c 100644 --- a/test/rdoc/test_rdoc_ri_driver.rb +++ b/test/rdoc/test_rdoc_ri_driver.rb @@ -13,8 +13,9 @@ def setup FileUtils.mkdir_p @home_ri @orig_ri = ENV['RI'] - @orig_home = ENV['HOME'] ENV['HOME'] = @tmpdir + @rdoc_home = File.join ENV["HOME"], ".rdoc" + FileUtils.mkdir_p @rdoc_home ENV.delete 'RI' @options = RDoc::RI::Driver.default_options @@ -31,11 +32,10 @@ def setup end def teardown - super - - ENV['HOME'] = @orig_home ENV['RI'] = @orig_ri FileUtils.rm_rf @tmpdir + + super end DUMMY_PAGER = ":;\n" @@ -81,7 +81,7 @@ def test_add_also_in @RM::Rule.new(1), @RM::Paragraph.new('Also found in:'), @RM::Verbatim.new("ruby core", "\n", - "~/.rdoc", "\n")) + @rdoc_home, "\n")) assert_equal expected, out end @@ -231,7 +231,7 @@ def test_add_method doc( head(1, 'Foo::Bar#blah'), blank_line, - para('(from ~/.rdoc)'), + para("(from #{@rdoc_home})"), head(3, 'Implementation from Bar'), rule(1), verb("blah(5) => 5\n", @@ -254,7 +254,7 @@ def test_add_method_that_is_alias_for_original doc( head(1, 'Qux#aliased'), blank_line, - para('(from ~/.rdoc)'), + para("(from #{@rdoc_home})"), rule(1), blank_line, para('alias comment'), @@ -280,7 +280,7 @@ def test_add_method_attribute doc( head(1, 'Foo::Bar#attr'), blank_line, - para('(from ~/.rdoc)'), + para("(from #{@rdoc_home})"), rule(1), blank_line, blank_line) @@ -299,7 +299,7 @@ def test_add_method_inherited doc( head(1, 'Bar#inherit'), blank_line, - para('(from ~/.rdoc)'), + para("(from #{@rdoc_home})"), head(3, 'Implementation from Foo'), rule(1), blank_line, @@ -343,13 +343,13 @@ def test_add_method_documentation doc( head(1, 'Foo#inherit'), blank_line, - para('(from ~/.rdoc)'), + para("(from #{@rdoc_home})"), rule(1), blank_line, blank_line, head(1, 'Foo#override'), blank_line, - para('(from ~/.rdoc)'), + para("(from #{@rdoc_home})"), rule(1), blank_line, para('must not be displayed in Bar#override'), @@ -802,7 +802,7 @@ def test_display_page_ambiguous @driver.display_page 'home:README' end - assert_match %r%= README pages in ~/\.rdoc%, out + assert_match %r%= README pages in #{@rdoc_home}%, out assert_match %r%README\.rdoc%, out assert_match %r%README\.md%, out end @@ -856,7 +856,7 @@ def test_display_page_missing @driver.display_page_list @store1 end - assert_match %r%= Pages in ~/\.rdoc%, out + assert_match %r%= Pages in #{@rdoc_home}%, out assert_match %r%README\.rdoc%, out end @@ -876,7 +876,7 @@ def test_display_page_list @driver.display_page_list @store1 end - assert_match %r%= Pages in ~/\.rdoc%, out + assert_match %r%= Pages in #{@rdoc_home}%, out assert_match %r%README\.rdoc%, out assert_match %r%OTHER\.rdoc%, out end diff --git a/test/rdoc/test_rdoc_ri_paths.rb b/test/rdoc/test_rdoc_ri_paths.rb index 726922daf01d0f..c01a4711ee9e47 100644 --- a/test/rdoc/test_rdoc_ri_paths.rb +++ b/test/rdoc/test_rdoc_ri_paths.rb @@ -36,12 +36,12 @@ def setup end def teardown - super - Gem.use_paths(*@orig_gem_path) Gem::Specification.reset FileUtils.rm_rf @tempdir ENV.replace(@orig_env) + + super end def test_class_each @@ -51,7 +51,7 @@ def test_class_each assert_equal RDoc::RI::Paths.system_dir, path.shift assert_equal RDoc::RI::Paths.site_dir, path.shift - assert_equal RDoc::RI::Paths.home_dir, path.shift + assert_equal RDoc::RI::Paths.home_dir, path.shift if RDoc::RI::Paths.home_dir assert_equal File.join(@nodoc.doc_dir, 'ri'), path.shift assert_equal File.join(@rake_10.doc_dir, 'ri'), path.shift assert_equal File.join(@rdoc_4_0.doc_dir, 'ri'), path.shift @@ -128,7 +128,7 @@ def test_class_raw_path assert_equal RDoc::RI::Paths.system_dir, path.shift assert_equal RDoc::RI::Paths.site_dir, path.shift - assert_equal RDoc::RI::Paths.home_dir, path.shift + assert_equal RDoc::RI::Paths.home_dir, path.shift if RDoc::RI::Paths.home_dir assert_equal File.join(@rake_10.doc_dir, 'ri'), path.shift end @@ -138,7 +138,7 @@ def test_class_raw_path_extra_dirs assert_equal '/nonexistent', path.shift assert_equal RDoc::RI::Paths.system_dir, path.shift assert_equal RDoc::RI::Paths.site_dir, path.shift - assert_equal RDoc::RI::Paths.home_dir, path.shift + assert_equal RDoc::RI::Paths.home_dir, path.shift if RDoc::RI::Paths.home_dir assert_equal File.join(@rake_10.doc_dir, 'ri'), path.shift end diff --git a/test/rdoc/test_rdoc_servlet.rb b/test/rdoc/test_rdoc_servlet.rb index 1127408193a32d..977251308aca75 100644 --- a/test/rdoc/test_rdoc_servlet.rb +++ b/test/rdoc/test_rdoc_servlet.rb @@ -45,7 +45,8 @@ def @req.path= path @orig_base = RDoc::RI::Paths::BASE RDoc::RI::Paths::BASE.replace @base @orig_ri_path_homedir = RDoc::RI::Paths::HOMEDIR - RDoc::RI::Paths::HOMEDIR.replace @home_dir + RDoc::RI::Paths.send :remove_const, :HOMEDIR + RDoc::RI::Paths.const_set :HOMEDIR, @home_dir RDoc::RI::Paths.instance_variable_set \ :@gemdirs, %w[/nonexistent/gems/example-1.0/ri] @@ -60,7 +61,8 @@ def teardown FileUtils.rm_rf @tempdir RDoc::RI::Paths::BASE.replace @orig_base - RDoc::RI::Paths::HOMEDIR.replace @orig_ri_path_homedir + RDoc::RI::Paths.send :remove_const, :HOMEDIR + RDoc::RI::Paths.const_set :HOMEDIR, @orig_ri_path_homedir RDoc::RI::Paths.instance_variable_set :@gemdirs, nil end diff --git a/test/rdoc/test_rdoc_store.rb b/test/rdoc/test_rdoc_store.rb index 8332d9233ed911..076b8e7d4e4ba3 100644 --- a/test/rdoc/test_rdoc_store.rb +++ b/test/rdoc/test_rdoc_store.rb @@ -317,6 +317,9 @@ def test_find_text_page end def test_friendly_path + @orig_xdg_data_home = ENV['XDG_DATA_HOME'] + ENV.delete('XDG_DATA_HOME') + @s.path = @tmpdir @s.type = nil assert_equal @s.path, @s.friendly_path @@ -331,11 +334,13 @@ def test_friendly_path assert_equal "ruby site", @s.friendly_path @s.type = :home - assert_equal "~/.rdoc", @s.friendly_path + assert_equal File.expand_path("~/.local/share/rdoc"), @s.friendly_path @s.type = :gem @s.path = "#{@tmpdir}/gem_repository/doc/gem_name-1.0/ri" assert_equal "gem gem_name-1.0", @s.friendly_path + ensure + ENV['XDG_DATA_HOME'] = @orig_xdg_data_home end def test_dry_run diff --git a/test/reline/test_config.rb b/test/reline/test_config.rb index cecb364f898bad..d24d4e837e7101 100644 --- a/test/reline/test_config.rb +++ b/test/reline/test_config.rb @@ -213,6 +213,68 @@ def test_empty_inputrc_env assert_nothing_raised do @config.read end + ensure ENV['INPUTRC'] = inputrc_backup end + + def test_inputrc + inputrc_backup = ENV['INPUTRC'] + expected = "#{@tmpdir}/abcde" + ENV['INPUTRC'] = expected + assert_equal expected, @config.inputrc_path + ensure + ENV['INPUTRC'] = inputrc_backup + end + + def test_xdg_config_home + home_backup = ENV['HOME'] + xdg_config_home_backup = ENV['XDG_CONFIG_HOME'] + xdg_config_home = File.expand_path("#{@tmpdir}/.config/example_dir") + expected = File.expand_path("#{xdg_config_home}/readline/inputrc") + FileUtils.mkdir_p(File.dirname(expected)) + FileUtils.touch(expected) + ENV['HOME'] = @tmpdir + ENV['XDG_CONFIG_HOME'] = xdg_config_home + assert_equal expected, @config.inputrc_path + ensure + FileUtils.rm(expected) + ENV['XDG_CONFIG_HOME'] = xdg_config_home_backup + ENV['HOME'] = home_backup + end + + def test_empty_xdg_config_home + home_backup = ENV['HOME'] + xdg_config_home_backup = ENV['XDG_CONFIG_HOME'] + ENV['HOME'] = @tmpdir + ENV['XDG_CONFIG_HOME'] = '' + expected = File.expand_path('~/.config/readline/inputrc') + FileUtils.mkdir_p(File.dirname(expected)) + FileUtils.touch(expected) + assert_equal expected, @config.inputrc_path + ensure + FileUtils.rm(expected) + ENV['XDG_CONFIG_HOME'] = xdg_config_home_backup + ENV['HOME'] = home_backup + end + + def test_relative_xdg_config_home + home_backup = ENV['HOME'] + xdg_config_home_backup = ENV['XDG_CONFIG_HOME'] + ENV['HOME'] = @tmpdir + expected = File.expand_path('~/.config/readline/inputrc') + FileUtils.mkdir_p(File.dirname(expected)) + FileUtils.touch(expected) + result = Dir.chdir(@tmpdir) do + xdg_config_home = ".config/example_dir" + ENV['XDG_CONFIG_HOME'] = xdg_config_home + inputrc = "#{xdg_config_home}/readline/inputrc" + FileUtils.mkdir_p(File.dirname(inputrc)) + FileUtils.touch(inputrc) + @config.inputrc_path + end + assert_equal expected, result + FileUtils.rm(expected) + ENV['XDG_CONFIG_HOME'] = xdg_config_home_backup + ENV['HOME'] = home_backup + end end diff --git a/test/reline/test_history.rb b/test/reline/test_history.rb index 189f2db86d583e..58c240fc962287 100644 --- a/test/reline/test_history.rb +++ b/test/reline/test_history.rb @@ -242,6 +242,26 @@ def test_delete_at__out_of_range end end + def test_history_size_zero + history = history_new(history_size: 0) + assert_equal 0, history.size + history << 'aa' + history << 'bb' + assert_equal 0, history.size + history.push(*%w{aa bb cc}) + assert_equal 0, history.size + end + + def test_history_size_negative_unlimited + history = history_new(history_size: -1) + assert_equal 0, history.size + history << 'aa' + history << 'bb' + assert_equal 2, history.size + history.push(*%w{aa bb cc}) + assert_equal 5, history.size + end + private def history_new(history_size: 10) diff --git a/test/reline/test_key_actor_emacs.rb b/test/reline/test_key_actor_emacs.rb index ed096f062da330..a1e40159994cbe 100644 --- a/test/reline/test_key_actor_emacs.rb +++ b/test/reline/test_key_actor_emacs.rb @@ -1625,7 +1625,7 @@ def test_em_kill_region_mbchar assert_line('') end - def test_ed_search_prev_history + def test_vi_search_prev Reline::HISTORY.concat(%w{abc 123 AAA}) assert_line('') assert_byte_pointer_size('') @@ -1912,6 +1912,149 @@ def test_modify_lines_with_wrong_rs $VERBOSE = verbose end + def test_ed_search_prev_history + Reline::HISTORY.concat([ + '12356', # old + '12aaa', + '12345' # new + ]) + input_keys('123') + # The ed_search_prev_history doesn't have default binding + @line_editor.__send__(:ed_search_prev_history, "\C-p".ord) + assert_byte_pointer_size('123') + assert_cursor(3) + assert_cursor_max(5) + assert_line('12345') + @line_editor.__send__(:ed_search_prev_history, "\C-p".ord) + assert_byte_pointer_size('123') + assert_cursor(3) + assert_cursor_max(5) + assert_line('12356') + @line_editor.__send__(:ed_search_prev_history, "\C-p".ord) + assert_byte_pointer_size('123') + assert_cursor(3) + assert_cursor_max(5) + assert_line('12356') + end + + def test_ed_search_prev_history_with_empty + Reline::HISTORY.concat([ + '12356', # old + '12aaa', + '12345' # new + ]) + # The ed_search_prev_history doesn't have default binding + @line_editor.__send__(:ed_search_prev_history, "\C-p".ord) + assert_byte_pointer_size('') + assert_cursor(0) + assert_cursor_max(5) + assert_line('12345') + @line_editor.__send__(:ed_search_prev_history, "\C-p".ord) + assert_byte_pointer_size('') + assert_cursor(0) + assert_cursor_max(5) + assert_line('12aaa') + @line_editor.__send__(:ed_search_prev_history, "\C-p".ord) + assert_byte_pointer_size('') + assert_cursor(0) + assert_cursor_max(5) + assert_line('12356') + @line_editor.__send__(:ed_search_prev_history, "\C-p".ord) + assert_byte_pointer_size('') + assert_cursor(0) + assert_cursor_max(5) + assert_line('12356') + end + + def test_ed_search_prev_history_without_match + Reline::HISTORY.concat([ + '12356', # old + '12aaa', + '12345' # new + ]) + input_keys('ABC') + # The ed_search_prev_history doesn't have default binding + @line_editor.__send__(:ed_search_prev_history, "\C-p".ord) + assert_byte_pointer_size('ABC') + assert_cursor(3) + assert_cursor_max(3) + assert_line('ABC') + end + + def test_ed_search_next_history + Reline::HISTORY.concat([ + '12356', # old + '12aaa', + '12345' # new + ]) + input_keys('123') + # The ed_search_prev_history and ed_search_next_history doesn't have default binding + @line_editor.__send__(:ed_search_prev_history, "\C-p".ord) + assert_byte_pointer_size('123') + assert_cursor(3) + assert_cursor_max(5) + assert_line('12345') + @line_editor.__send__(:ed_search_prev_history, "\C-p".ord) + assert_byte_pointer_size('123') + assert_cursor(3) + assert_cursor_max(5) + assert_line('12356') + @line_editor.__send__(:ed_search_prev_history, "\C-p".ord) + assert_byte_pointer_size('123') + assert_cursor(3) + assert_cursor_max(5) + assert_line('12356') + @line_editor.__send__(:ed_search_next_history, "\C-n".ord) + assert_byte_pointer_size('123') + assert_cursor(3) + assert_cursor_max(5) + assert_line('12345') + @line_editor.__send__(:ed_search_next_history, "\C-n".ord) + assert_byte_pointer_size('123') + assert_cursor(3) + assert_cursor_max(5) + assert_line('12345') + end + + def test_ed_search_next_history_with_empty + Reline::HISTORY.concat([ + '12356', # old + '12aaa', + '12345' # new + ]) + # The ed_search_prev_history and ed_search_next_history doesn't have default binding + @line_editor.__send__(:ed_search_prev_history, "\C-p".ord) + assert_byte_pointer_size('') + assert_cursor(0) + assert_cursor_max(5) + assert_line('12345') + @line_editor.__send__(:ed_search_prev_history, "\C-p".ord) + assert_byte_pointer_size('') + assert_cursor(0) + assert_cursor_max(5) + assert_line('12aaa') + @line_editor.__send__(:ed_search_prev_history, "\C-p".ord) + assert_byte_pointer_size('') + assert_cursor(0) + assert_cursor_max(5) + assert_line('12356') + @line_editor.__send__(:ed_search_next_history, "\C-n".ord) + assert_byte_pointer_size('') + assert_cursor(0) + assert_cursor_max(5) + assert_line('12aaa') + @line_editor.__send__(:ed_search_next_history, "\C-n".ord) + assert_byte_pointer_size('') + assert_cursor(0) + assert_cursor_max(5) + assert_line('12345') + @line_editor.__send__(:ed_search_next_history, "\C-n".ord) + assert_byte_pointer_size('') + assert_cursor(0) + assert_cursor_max(0) + assert_line('') + end + =begin # TODO: move KeyStroke instance from Reline to LineEditor def test_key_delete input_keys('ab') diff --git a/test/ripper/test_parser_events.rb b/test/ripper/test_parser_events.rb index feb3db05d85d4f..b6eeb77cda4b2c 100644 --- a/test/ripper/test_parser_events.rb +++ b/test/ripper/test_parser_events.rb @@ -1490,16 +1490,9 @@ def test_local_variables end def test_block_variables - assert_equal("[fcall(proc,[],&block([],[void()]))]", parse("proc{|;y|}")) - if defined?(Process::RLIMIT_AS) - dir = File.dirname(__FILE__) - as = 100 * 1024 * 1024 # 100MB - as *= 2 if RubyVM::MJIT.enabled? # space for compiler - assert_in_out_err(%W(-I#{dir} -rdummyparser), - "Process.setrlimit(Process::RLIMIT_AS,#{as}); "\ - "puts DummyParser.new('proc{|;y|!y}').parse", - ["[fcall(proc,[],&block([],[unary(!,ref(y))]))]"], [], '[ruby-dev:39423]') - end + bug4159 = '[ruby-dev:39423]' + assert_equal("[fcall(proc,[],&block([],[void()]))]", parse("proc{|;y|}"), bug4159) + assert_equal("[fcall(proc,[],&block([],[unary(!,ref(y))]))]", parse("proc{|;y|!y}"), bug4159) end def test_unterminated_regexp diff --git a/test/ruby/test_defined.rb b/test/ruby/test_defined.rb index 9976db3b6f7202..267744ef08f0cb 100644 --- a/test/ruby/test_defined.rb +++ b/test/ruby/test_defined.rb @@ -23,24 +23,30 @@ def defined_test return !defined?(yield) end - def test_defined + def test_defined_gloval_variable $x = nil assert(defined?($x)) # global variable assert_equal('global-variable', defined?($x))# returns description + end + def test_defined_local_variable assert_nil(defined?(foo)) # undefined foo=5 assert(defined?(foo)) # local variable + end + def test_defined_constant assert(defined?(Array)) # constant assert(defined?(::Array)) # toplevel constant assert(defined?(File::Constants)) # nested constant + end + + def test_defined_method assert(defined?(Object.new)) # method assert(defined?(Object::new)) # method assert(!defined?(Object.print)) # private method assert(defined?(1 == 2)) # operator expression - f = Foo.new assert_nil(defined?(f.foo)) # protected method f.bar(f) { |v| assert(v) } @@ -53,10 +59,22 @@ def test_defined assert_nil(defined?(quux(x))) assert(defined?(f.attr = 1)) f.attrasgn_test { |v| assert(v) } + end + def test_defined_undef + x = Object.new + def x.foo; end + assert(defined?(x.foo)) + x.instance_eval {undef :foo} + assert(!defined?(x.foo), "undefed method should not be defined?") + end + + def test_defined_yield assert(defined_test) # not iterator assert(!defined_test{}) # called as iterator + end + def test_defined_matchdata /a/ =~ '' assert_equal nil, defined?($&) assert_equal nil, defined?($`) @@ -85,12 +103,16 @@ def test_defined assert_equal 'global-variable', defined?($+) assert_equal 'global-variable', defined?($1) assert_equal nil, defined?($2) + end + def test_defined_literal assert_equal("nil", defined?(nil)) assert_equal("true", defined?(true)) assert_equal("false", defined?(false)) assert_equal("expression", defined?(1)) + end + def test_defined_empty_paren_expr bug8224 = '[ruby-core:54024] [Bug #8224]' (1..3).each do |level| expr = "("*level+")"*level diff --git a/test/ruby/test_env.rb b/test/ruby/test_env.rb index f93cd503d84649..6d5fc889151307 100644 --- a/test/ruby/test_env.rb +++ b/test/ruby/test_env.rb @@ -406,8 +406,8 @@ def test_reject def check(as, bs) if IGNORE_CASE - as = as.map {|xs| xs.map {|x| x.upcase } } - bs = bs.map {|xs| xs.map {|x| x.upcase } } + as = as.map {|k, v| [k.upcase, v] } + bs = bs.map {|k, v| [k.upcase, v] } end assert_equal(as.sort, bs.sort) end @@ -433,6 +433,8 @@ def test_replace ENV["foo"] = "xxx" ENV.replace({"foo"=>"bar", "baz"=>"qux"}) check(ENV.to_hash.to_a, [%w(foo bar), %w(baz qux)]) + ENV.replace({"Foo"=>"Bar", "Baz"=>"Qux"}) + check(ENV.to_hash.to_a, [%w(Foo Bar), %w(Baz Qux)]) end def test_update diff --git a/test/ruby/test_exception.rb b/test/ruby/test_exception.rb index 9d7ffd882559b0..9529fc80133c66 100644 --- a/test/ruby/test_exception.rb +++ b/test/ruby/test_exception.rb @@ -1156,13 +1156,11 @@ def test_full_message if Exception.to_tty? assert_match(/\e/, message) message = message.gsub(/\e\[[\d;]*m/, '') - assert_operator(message, :start_with?, remark) - assert_operator(message, :end_with?, bottom) else assert_not_match(/\e/, message) - assert_operator(message, :start_with?, bottom) - assert_operator(message, :end_with?, top) end + assert_operator(message, :start_with?, bottom) + assert_operator(message, :end_with?, top) end def test_exception_in_message diff --git a/test/ruby/test_fiber.rb b/test/ruby/test_fiber.rb index 947e75aa2c990c..7070fdf03c7f56 100644 --- a/test/ruby/test_fiber.rb +++ b/test/ruby/test_fiber.rb @@ -360,6 +360,7 @@ def invoke_rec script, vm_stack_size, machine_stack_size, use_length = true end def test_stack_size + skip 'too unstable on riscv' if RUBY_PLATFORM =~ /riscv/ h_default = eval(invoke_rec('p RubyVM::DEFAULT_PARAMS', nil, nil, false)) h_0 = eval(invoke_rec('p RubyVM::DEFAULT_PARAMS', 0, 0, false)) h_large = eval(invoke_rec('p RubyVM::DEFAULT_PARAMS', 1024 * 1024 * 5, 1024 * 1024 * 10, false)) diff --git a/test/ruby/test_jit.rb b/test/ruby/test_jit.rb index ebf4a222e2318b..a5d5fb45a96827 100644 --- a/test/ruby/test_jit.rb +++ b/test/ruby/test_jit.rb @@ -14,6 +14,7 @@ class TestJIT < Test::Unit::TestCase ] MAX_CACHE_PATTERNS = [ /\AJIT compaction \([^)]+\): .+\n\z/, + /\AToo many JIT code, but skipped unloading units for JIT compaction\n\z/, /\ANo units can be unloaded -- .+\n\z/, ] @@ -695,17 +696,22 @@ def mjit#{i} debug_info = %Q[stdout:\n"""\n#{out}\n"""\n\nstderr:\n"""\n#{err}"""\n] assert_equal('012345678910', out, debug_info) compactions, errs = err.lines.partition do |l| - l.match?(/\AJIT compaction \(\d+\.\dms\): Compacted \d+ methods ->/) + l.match?(/\AJIT compaction \(\d+\.\dms\): Compacted \d+ methods /) end 10.times do |i| assert_match(/\A#{JIT_SUCCESS_PREFIX}: mjit#{i}@\(eval\):/, errs[i], debug_info) end - assert_equal("Too many JIT code -- 1 units unloaded\n", errs[10], debug_info) - assert_match(/\A#{JIT_SUCCESS_PREFIX}: mjit10@\(eval\):/, errs[11], debug_info) # On --jit-wait, when the number of JIT-ed code reaches --jit-max-cache, # it should trigger compaction. - unless RUBY_PLATFORM.match?(/mswin|mingw/) # compaction is not supported on Windows yet + if RUBY_PLATFORM.match?(/mswin|mingw/) # compaction is not supported on Windows yet + assert_equal("Too many JIT code -- 1 units unloaded\n", errs[10], debug_info) + assert_match(/\A#{JIT_SUCCESS_PREFIX}: mjit10@\(eval\):/, errs[11], debug_info) + else + assert_equal("Too many JIT code, but skipped unloading units for JIT compaction\n", errs[10], debug_info) + assert_equal("No units can be unloaded -- incremented max-cache-size to 11 for --jit-wait\n", errs[11], debug_info) + assert_match(/\A#{JIT_SUCCESS_PREFIX}: mjit10@\(eval\):/, errs[12], debug_info) + assert_equal(3, compactions.size, debug_info) end @@ -713,12 +719,22 @@ def mjit#{i} # "Permission Denied" error is preventing to remove so file on AppVeyor/RubyCI. skip 'Removing so file is randomly failing on AppVeyor/RubyCI mswin due to Permission Denied.' else - # verify .o files are deleted on unload_units + # verify .c files are deleted on unload_units assert_send([Dir, :empty?, dir], debug_info) end end end + def test_newarraykwsplat_on_stack + assert_eval_with_jit("#{<<~"begin;"}\n#{<<~"end;"}", stdout: "[nil, [{:type=>:development}]]\n", success_count: 1, insns: %i[newarraykwsplat]) + begin; + def arr + [nil, [:type => :development]] + end + p arr + end; + end + def test_local_stack_on_exception assert_eval_with_jit("#{<<~"begin;"}\n#{<<~"end;"}", stdout: '3', success_count: 2) begin; diff --git a/test/ruby/test_jit_debug.rb b/test/ruby/test_jit_debug.rb index 3efc72d6fd2079..179512fec68cd7 100644 --- a/test/ruby/test_jit_debug.rb +++ b/test/ruby/test_jit_debug.rb @@ -8,6 +8,7 @@ class TestJITDebug < TestJIT def setup + super # let `#eval_with_jit` use --jit-debug @jit_debug = true end diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb index e5586edc6d1d1e..e3cd62713f9cc8 100644 --- a/test/ruby/test_module.rb +++ b/test/ruby/test_module.rb @@ -2161,6 +2161,22 @@ def test_class_variables assert_equal([:@@bar], m2.class_variables(false)) end + def test_class_variable_in_dup_class + a = Class.new do + @@a = 'A' + def a=(x) + @@a = x + end + def a + @@a + end + end + + b = a.dup + b.new.a = 'B' + assert_equal 'A', a.new.a, '[ruby-core:17019]' + end + Bug6891 = '[ruby-core:47241]' def test_extend_module_with_protected_method diff --git a/test/ruby/test_process.rb b/test/ruby/test_process.rb index a5eb0a58441d06..7bcfa48f4fc588 100644 --- a/test/ruby/test_process.rb +++ b/test/ruby/test_process.rb @@ -338,6 +338,13 @@ def test_execopts_env ensure ENV["hmm"] = old end + + assert_raise_with_message(ArgumentError, /fo=fo/) { + system({"fo=fo"=>"ha"}, *ENVCOMMAND) + } + assert_raise_with_message(ArgumentError, /\u{30c0}=\u{30e1}/) { + system({"\u{30c0}=\u{30e1}"=>"ha"}, *ENVCOMMAND) + } end def test_execopt_env_path @@ -1598,6 +1605,28 @@ def test_setegid rescue NotImplementedError end + if Process::UID.respond_to?(:from_name) + def test_uid_from_name + if u = Etc.getpwuid(Process.uid) + assert_equal(Process.uid, Process::UID.from_name(u.name), u.name) + end + assert_raise_with_message(ArgumentError, /\u{4e0d 5b58 5728}/) { + Process::UID.from_name("\u{4e0d 5b58 5728}") + } + end + end + + if Process::GID.respond_to?(:from_name) && !RUBY_PLATFORM.include?("android") + def test_gid_from_name + if g = Etc.getgrgid(Process.gid) + assert_equal(Process.gid, Process::GID.from_name(g.name), g.name) + end + assert_raise_with_message(ArgumentError, /\u{4e0d 5b58 5728}/) { + Process::GID.from_name("\u{4e0d 5b58 5728}") + } + end + end + def test_uid_re_exchangeable_p r = Process::UID.re_exchangeable? assert_include([true, false], r) diff --git a/test/ruby/test_refinement.rb b/test/ruby/test_refinement.rb index 1f2a67eeb22c1d..51231bd56cf856 100644 --- a/test/ruby/test_refinement.rb +++ b/test/ruby/test_refinement.rb @@ -920,7 +920,7 @@ def test_prepend_after_refine_wb_miss #{PrependAfterRefine_CODE} undef PrependAfterRefine } - }, timeout: 30 + }, timeout: 60 end def test_prepend_after_refine diff --git a/test/ruby/test_require.rb b/test/ruby/test_require.rb index fa2f2ec5d0a124..30c07b9e5c2139 100644 --- a/test/ruby/test_require.rb +++ b/test/ruby/test_require.rb @@ -770,6 +770,8 @@ def test_loading_fifo_threading_success end if File.respond_to?(:mkfifo) def test_loading_fifo_fd_leak + skip if RUBY_PLATFORM =~ /android/ # https://rubyci.org/logs/rubyci.s3.amazonaws.com/android29-x86_64/ruby-master/log/20200419T124100Z.fail.html.gz + Tempfile.create(%w'fifo .rb') {|f| f.close File.unlink(f.path) diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb index ddb813fef9ba29..df6c2e383fb51b 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -1415,11 +1415,14 @@ def test_method_call_location end def test_methoddef_endless - assert_valid_syntax('private def foo = 42') + assert_syntax_error('private def foo = 42', /unexpected '='/) + assert_valid_syntax('private def foo() = 42') assert_valid_syntax('private def inc(x) = x + 1') - assert_valid_syntax('private def obj.foo = 42') + assert_syntax_error('private def obj.foo = 42', /unexpected '='/) + assert_valid_syntax('private def obj.foo() = 42') assert_valid_syntax('private def obj.inc(x) = x + 1') - assert_valid_syntax('private def obj.inc(x) = x + 1 => @x') + eval('def self.inc(x) = x + 1 => @x') + assert_equal(:inc, @x) end def test_methoddef_in_cond diff --git a/test/rubygems/test_deprecate.rb b/test/rubygems/test_deprecate.rb index f5cd83ee8908c3..6d36b673dfd47d 100644 --- a/test/rubygems/test_deprecate.rb +++ b/test/rubygems/test_deprecate.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true require 'rubygems/test_case' -# require 'rubygems/builder' -# require 'rubygems/package' require 'rubygems/deprecate' class TestDeprecate < Gem::TestCase @@ -9,7 +7,6 @@ class TestDeprecate < Gem::TestCase def setup super - # Gem::Deprecate.saved_warnings.clear @original_skip = Gem::Deprecate.skip Gem::Deprecate.skip = false end @@ -17,7 +14,6 @@ def setup def teardown super - # Gem::Deprecate.saved_warnings.clear Gem::Deprecate.skip = @original_skip end diff --git a/test/rubygems/test_gem.rb b/test/rubygems/test_gem.rb index 1f5e0e6768dbfb..5f70a2ac6b1c3a 100644 --- a/test/rubygems/test_gem.rb +++ b/test/rubygems/test_gem.rb @@ -1359,6 +1359,8 @@ def test_self_user_dir parts = [@userhome, '.gem', Gem.ruby_engine] parts << RbConfig::CONFIG['ruby_version'] unless RbConfig::CONFIG['ruby_version'].empty? + FileUtils.mkdir_p File.join(parts) + assert_equal File.join(parts), Gem.user_dir end diff --git a/test/rubygems/test_gem_commands_build_command.rb b/test/rubygems/test_gem_commands_build_command.rb index a2e8f284eb2393..9dfba75cf51c20 100644 --- a/test/rubygems/test_gem_commands_build_command.rb +++ b/test/rubygems/test_gem_commands_build_command.rb @@ -17,8 +17,13 @@ def setup readme_file = File.join(@tempdir, 'README.md') - File.open readme_file, 'w' do |f| - f.write 'My awesome gem' + begin + umask_orig = File.umask(2) + File.open readme_file, 'w' do |f| + f.write 'My awesome gem' + end + ensure + File.umask(umask_orig) end @gem = util_spec 'some_gem' do |s| @@ -376,7 +381,6 @@ def test_build_signed_gem_with_cert_expiration_length_days skip 'openssl is missing' unless defined?(OpenSSL::SSL) && !java_platform? gem_path = File.join Gem.user_home, ".gem" - Dir.mkdir gem_path Gem::Security.trust_dir @@ -420,7 +424,6 @@ def test_build_auto_resign_cert skip 'openssl is missing' unless defined?(OpenSSL::SSL) && !java_platform? gem_path = File.join Gem.user_home, ".gem" - Dir.mkdir gem_path Gem::Security.trust_dir diff --git a/test/rubygems/test_gem_commands_cert_command.rb b/test/rubygems/test_gem_commands_cert_command.rb index fd1e66b915d9e5..bb9ed9e630ba33 100644 --- a/test/rubygems/test_gem_commands_cert_command.rb +++ b/test/rubygems/test_gem_commands_cert_command.rb @@ -597,7 +597,6 @@ def test_execute_sign_no_key def test_execute_re_sign gem_path = File.join Gem.user_home, ".gem" - Dir.mkdir gem_path path = File.join @tempdir, 'cert.pem' Gem::Security.write EXPIRED_PUBLIC_CERT, path, 0600 @@ -628,9 +627,6 @@ def test_execute_re_sign end def test_execute_re_sign_with_cert_expiration_length_days - gem_path = File.join Gem.user_home, ".gem" - Dir.mkdir gem_path - path = File.join @tempdir, 'cert.pem' Gem::Security.write EXPIRED_PUBLIC_CERT, path, 0600 diff --git a/test/rubygems/test_gem_commands_signout_command.rb b/test/rubygems/test_gem_commands_signout_command.rb index 814b55cf4f2803..9a47dafe7cd6f0 100644 --- a/test/rubygems/test_gem_commands_signout_command.rb +++ b/test/rubygems/test_gem_commands_signout_command.rb @@ -8,6 +8,7 @@ class TestGemCommandsSignoutCommand < Gem::TestCase def setup super + File.delete Gem.configuration.credentials_path if File.exist?(Gem.configuration.credentials_path) @cmd = Gem::Commands::SignoutCommand.new end diff --git a/test/rubygems/test_gem_config_file.rb b/test/rubygems/test_gem_config_file.rb index 260a94953e3acc..d31d55eba1270b 100644 --- a/test/rubygems/test_gem_config_file.rb +++ b/test/rubygems/test_gem_config_file.rb @@ -170,7 +170,7 @@ def test_api_keys assert_nil @cfg.instance_variable_get :@api_keys temp_cred = File.join Gem.user_home, '.gem', 'credentials' - FileUtils.mkdir File.dirname(temp_cred) + FileUtils.mkdir_p File.dirname(temp_cred) File.open temp_cred, 'w', 0600 do |fp| fp.puts ':rubygems_api_key: 701229f217cdf23b1344c7b4b54ca97' end @@ -296,7 +296,7 @@ def test_handle_arguments_norc def test_load_api_keys temp_cred = File.join Gem.user_home, '.gem', 'credentials' - FileUtils.mkdir File.dirname(temp_cred) + FileUtils.mkdir_p File.dirname(temp_cred) File.open temp_cred, 'w', 0600 do |fp| fp.puts ":rubygems_api_key: 701229f217cdf23b1344c7b4b54ca97" fp.puts ":other: a5fdbb6ba150cbb83aad2bb2fede64c" diff --git a/test/rubygems/test_gem_installer.rb b/test/rubygems/test_gem_installer.rb index 89fcecb68d449e..34759a8fd04fda 100644 --- a/test/rubygems/test_gem_installer.rb +++ b/test/rubygems/test_gem_installer.rb @@ -2200,7 +2200,7 @@ def util_conflict_executable(wrappers) end def mask - 0100755 & (~File.umask) + 0100755 end end diff --git a/test/rubygems/test_gem_source.rb b/test/rubygems/test_gem_source.rb index 05e443c7f1b672..24b8edb055e156 100644 --- a/test/rubygems/test_gem_source.rb +++ b/test/rubygems/test_gem_source.rb @@ -230,7 +230,7 @@ def test_update_cache_eh end def test_update_cache_eh_home_nonexistent - FileUtils.rmdir Gem.user_home + FileUtils.rm_rf Gem.user_home refute @source.update_cache? end diff --git a/test/rubygems/test_gem_spec_fetcher.rb b/test/rubygems/test_gem_spec_fetcher.rb index b7547112bbd020..d1633c4e3cc225 100644 --- a/test/rubygems/test_gem_spec_fetcher.rb +++ b/test/rubygems/test_gem_spec_fetcher.rb @@ -33,7 +33,7 @@ def test_initialize_source end def test_initialize_nonexistent_home_dir - FileUtils.rmdir Gem.user_home + FileUtils.rm_rf Gem.user_home assert Gem::SpecFetcher.new end diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb index 1df7d71d8e56cf..1848e52e169f92 100644 --- a/test/rubygems/test_gem_specification.rb +++ b/test/rubygems/test_gem_specification.rb @@ -3823,12 +3823,17 @@ def util_setup_validate FileUtils.mkdir_p "test" FileUtils.mkdir_p "bin" - FileUtils.touch File.join("ext", "a", "extconf.rb") - FileUtils.touch File.join("lib", "code.rb") - FileUtils.touch File.join("test", "suite.rb") - - File.open "bin/exec", "w", 0755 do |fp| - fp.puts "#!#{Gem.ruby}" + begin + umask_orig = File.umask(2) + FileUtils.touch File.join("ext", "a", "extconf.rb") + FileUtils.touch File.join("lib", "code.rb") + FileUtils.touch File.join("test", "suite.rb") + + File.open "bin/exec", "w", 0755 do |fp| + fp.puts "#!#{Gem.ruby}" + end + ensure + File.umask(umask_orig) end end end diff --git a/test/socket/test_unix.rb b/test/socket/test_unix.rb index 6efb1d60ee87cb..e9c90be1673743 100644 --- a/test/socket/test_unix.rb +++ b/test/socket/test_unix.rb @@ -542,16 +542,20 @@ def test_getcred_ucred def test_getcred_xucred return if /freebsd|darwin/ !~ RUBY_PLATFORM - Dir.mktmpdir {|d| + Dir.mktmpdir do |d| sockpath = "#{d}/sock" serv = Socket.unix_server_socket(sockpath) - Socket.unix(sockpath) + u = Socket.unix(sockpath) s, = serv.accept cred = s.getsockopt(0, Socket::LOCAL_PEERCRED) inspect = cred.inspect assert_match(/ euid=#{Process.euid} /, inspect) assert_match(/ \(xucred\)/, inspect) - } + ensure + s&.close + u&.close + serv&.close + end end def test_sendcred_ucred diff --git a/test/uri/test_generic.rb b/test/uri/test_generic.rb index 90f779c88c2cbe..b449a0a0d1fb6c 100644 --- a/test/uri/test_generic.rb +++ b/test/uri/test_generic.rb @@ -865,34 +865,30 @@ def test_find_proxy_get end def test_find_proxy_no_proxy + getaddress = IPSocket.method(:getaddress) + example_address = nil + IPSocket.singleton_class.class_eval do + undef getaddress + define_method(:getaddress) do |host| + case host + when "example.org", "www.example.org" + example_address + when /\A\d+(?:\.\d+){3}\z/ + host + else + raise host + end + end + end + with_proxy_env('http_proxy'=>'http://127.0.0.1:8080', 'no_proxy'=>'192.0.2.2') {|env| assert_equal(URI('http://127.0.0.1:8080'), URI("http://192.0.2.1/").find_proxy(env)) assert_nil(URI("http://192.0.2.2/").find_proxy(env)) - getaddress = IPSocket.method(:getaddress) - begin - class << IPSocket - undef getaddress - def getaddress(host) - host == "example.org" or raise - "192.0.2.1" - end - end - assert_equal(URI('http://127.0.0.1:8080'), URI.parse("http://example.org").find_proxy(env)) - class << IPSocket - undef getaddress - def getaddress(host) - host == "example.org" or raise - "192.0.2.2" - end - end - assert_nil(URI.parse("http://example.org").find_proxy(env)) - ensure - IPSocket.singleton_class.class_eval do - undef getaddress - define_method(:getaddress, getaddress) - end - end + example_address = "192.0.2.1" + assert_equal(URI('http://127.0.0.1:8080'), URI.parse("http://example.org").find_proxy(env)) + example_address = "192.0.2.2" + assert_nil(URI.parse("http://example.org").find_proxy(env)) } with_proxy_env('http_proxy'=>'http://127.0.0.1:8080', 'no_proxy'=>'example.org') {|env| assert_nil(URI("http://example.org/").find_proxy(env)) @@ -902,6 +898,11 @@ def getaddress(host) assert_equal(URI('http://127.0.0.1:8080'), URI("http://example.org/").find_proxy(env)) assert_nil(URI("http://www.example.org/").find_proxy(env)) } + ensure + IPSocket.singleton_class.class_eval do + undef getaddress + define_method(:getaddress, getaddress) + end end def test_find_proxy_no_proxy_cidr diff --git a/test/uri/test_ldap.rb b/test/uri/test_ldap.rb index adad4454b594e4..64845e487ac3e3 100644 --- a/test/uri/test_ldap.rb +++ b/test/uri/test_ldap.rb @@ -95,6 +95,10 @@ def test_select u.select(:scheme, :host, :not_exist, :port) end end + + def test_parse_invalid_uri + assert_raise(URI::InvalidURIError) {URI.parse("ldap:https://example.com")} + end end diff --git a/thread_pthread.c b/thread_pthread.c index b9ac63f298cb91..ee2f7bc9091231 100644 --- a/thread_pthread.c +++ b/thread_pthread.c @@ -1572,6 +1572,18 @@ setup_communication_pipe_internal(int pipes[2]) # define SET_CURRENT_THREAD_NAME(name) prctl(PR_SET_NAME, name) #endif +enum { + THREAD_NAME_MAX = +#if defined(__linux__) + 16 +#elif defined(__APPLE__) +/* Undocumented, and main thread seems unlimited */ + 64 +#else + 16 +#endif +}; + static VALUE threadptr_invoke_proc_location(rb_thread_t *th); static void @@ -1584,14 +1596,14 @@ native_set_thread_name(rb_thread_t *th) } else if ((loc = threadptr_invoke_proc_location(th)) != Qnil) { char *name, *p; - char buf[16]; + char buf[THREAD_NAME_MAX]; size_t len; int n; name = RSTRING_PTR(RARRAY_AREF(loc, 0)); p = strrchr(name, '/'); /* show only the basename of the path. */ if (p && p[1]) - name = p + 1; + name = p + 1; n = snprintf(buf, sizeof(buf), "%s:%d", name, NUM2INT(RARRAY_AREF(loc, 1))); rb_gc_force_recycle(loc); /* acts as a GC guard, too */ @@ -1606,15 +1618,30 @@ native_set_thread_name(rb_thread_t *th) #endif } -static VALUE +static void native_set_another_thread_name(rb_nativethread_id_t thread_id, VALUE name) { -#ifdef SET_ANOTHER_THREAD_NAME +#if defined SET_ANOTHER_THREAD_NAME || defined SET_CURRENT_THREAD_NAME + char buf[THREAD_NAME_MAX]; const char *s = ""; - if (!NIL_P(name)) s = RSTRING_PTR(name); +# if !defined SET_ANOTHER_THREAD_NAME + if (!pthread_equal(pthread_self(), thread_id)) return; +# endif + if (!NIL_P(name)) { + long n; + RSTRING_GETMEM(name, s, n); + if (n >= (int)sizeof(buf)) { + memcpy(buf, s, sizeof(buf)-1); + buf[sizeof(buf)-1] = '\0'; + s = buf; + } + } +# if defined SET_ANOTHER_THREAD_NAME SET_ANOTHER_THREAD_NAME(thread_id, s); +# elif defined SET_CURRENT_THREAD_NAME + SET_CURRENT_THREAD_NAME(s); +# endif #endif - return name; } static void diff --git a/tool/fetch-bundled_gems.rb b/tool/fetch-bundled_gems.rb index 28ae3d43275395..4ba1848d00604a 100755 --- a/tool/fetch-bundled_gems.rb +++ b/tool/fetch-bundled_gems.rb @@ -17,8 +17,9 @@ puts "retrieving #{n} ..." system(*%W"git clone #{u} #{n}") or abort end -unless system(*%W"git checkout #{v.sub(/\A(?=\d)/, 'v')}", chdir: n) - unless /\A\d/ =~ v and system(*%W"git checkout #{v}", chdir: n) +checkout = %w"git -c advice.detachedHead=false checkout" +unless system(*checkout, v.sub(/\A(?=\d)/, 'v'), chdir: n) + unless /\A\d/ =~ v and system(*checkout, v, chdir: n) abort end end diff --git a/tool/lib/envutil.rb b/tool/lib/envutil.rb index 2faf48385e42a4..0dd86dff5cfa75 100644 --- a/tool/lib/envutil.rb +++ b/tool/lib/envutil.rb @@ -137,8 +137,10 @@ def invoke_ruby(args, stdin_data = "", capture_stdout = false, capture_stderr = args = [args] if args.kind_of?(String) pid = spawn(child_env, *precommand, rubybin, *args, **opt) in_c.close - out_c.close if capture_stdout - err_c.close if capture_stderr && capture_stderr != :merge_to_stdout + out_c&.close + out_c = nil + err_c&.close + err_c = nil if block_given? return yield in_p, out_p, err_p, pid else @@ -242,7 +244,11 @@ def with_default_internal(enc) def labeled_module(name, &block) Module.new do - singleton_class.class_eval {define_method(:to_s) {name}; alias inspect to_s} + singleton_class.class_eval { + define_method(:to_s) {name} + alias inspect to_s + alias name to_s + } class_eval(&block) if block end end @@ -250,7 +256,11 @@ def labeled_module(name, &block) def labeled_class(name, superclass = Object, &block) Class.new(superclass) do - singleton_class.class_eval {define_method(:to_s) {name}; alias inspect to_s} + singleton_class.class_eval { + define_method(:to_s) {name} + alias inspect to_s + alias name to_s + } class_eval(&block) if block end end diff --git a/tool/lib/leakchecker.rb b/tool/lib/leakchecker.rb index 03eb5391c49f93..a94d7a79b262f0 100644 --- a/tool/lib/leakchecker.rb +++ b/tool/lib/leakchecker.rb @@ -35,19 +35,19 @@ def find_fds if IO.respond_to?(:console) and (m = IO.method(:console)).arity.nonzero? m[:close] end - fd_dir = "/proc/self/fd" - if File.directory?(fd_dir) - fds = Dir.open(fd_dir) {|d| - a = d.grep(/\A\d+\z/, &:to_i) - if d.respond_to? :fileno - a -= [d.fileno] - end - a - } - fds.sort - else - [] + %w"/proc/self/fd /dev/fd".each do |fd_dir| + if File.directory?(fd_dir) + fds = Dir.open(fd_dir) {|d| + a = d.grep(/\A\d+\z/, &:to_i) + if d.respond_to? :fileno + a -= [d.fileno] + end + a + } + return fds.sort + end end + [] end def check_fd_leak(test_name) @@ -89,6 +89,19 @@ def check_fd_leak(test_name) }.sort.each {|s| str << s } + else + begin + io = IO.for_fd(fd, autoclose: false) + s = io.stat + rescue Errno::EBADF + # something un-stat-able + next + else + next if /darwin/ =~ RUBY_PLATFORM and [0, -1].include?(s.dev) + str << ' ' << s.inspect + ensure + io&.close + end end puts "Leaked file descriptor: #{test_name}: #{fd}#{str}" puts " The IO was created at #{pos}" if pos diff --git a/tool/lib/minitest/unit.rb b/tool/lib/minitest/unit.rb index c85b41e5fc44a7..7090f8af3f4bc2 100644 --- a/tool/lib/minitest/unit.rb +++ b/tool/lib/minitest/unit.rb @@ -779,6 +779,7 @@ def options @@installed_at_exit ||= false @@out = $stdout @@after_tests = [] + @@current_repeat_count = 0 ## # A simple hook allowing you to run a block of code after _all_ of diff --git a/tool/lib/test/unit.rb b/tool/lib/test/unit.rb index 376ca8d3d43d3d..a2ee464ff1444c 100644 --- a/tool/lib/test/unit.rb +++ b/tool/lib/test/unit.rb @@ -527,7 +527,7 @@ def _run_parallel suites, type, result parallel = @options[:parallel] @options[:parallel] = false suites, rep = rep.partition {|r| r[:testcase] && r[:file] && r[:report].any? {|e| !e[2].is_a?(MiniTest::Skip)}} - suites.map {|r| r[:file]}.uniq.each {|file| require file} + suites.map {|r| File.realpath(r[:file])}.uniq.each {|file| require file} suites.map! {|r| eval("::"+r[:testcase])} del_status_line or puts unless suites.empty? diff --git a/tool/lib/test/unit/core_assertions.rb b/tool/lib/test/unit/core_assertions.rb index e5f741fafbfe2f..127ff49166b362 100644 --- a/tool/lib/test/unit/core_assertions.rb +++ b/tool/lib/test/unit/core_assertions.rb @@ -291,6 +291,7 @@ def assert_separately(args, file = nil, line = nil, src, ignore_stderr: nil, **o args = args.dup args.insert((Hash === args.first ? 1 : 0), "-w", "--disable=gems", *$:.map {|l| "-I#{l}"}) stdout, stderr, status = EnvUtil.invoke_ruby(args, src, capture_stdout, true, **opt) + ensure if res_c res_c.close res = res_p.read @@ -298,6 +299,7 @@ def assert_separately(args, file = nil, line = nil, src, ignore_stderr: nil, **o else res = stdout end + raise if $! abort = status.coredump? || (status.signaled? && ABORT_SIGNALS.include?(status.termsig)) assert(!abort, FailDesc[status, nil, stderr]) self._assertions += res[/^assertions=(\d+)/, 1].to_i diff --git a/tool/lib/test/unit/parallel.rb b/tool/lib/test/unit/parallel.rb index 15f9ac575a2b3e..afb0d0167a706d 100644 --- a/tool/lib/test/unit/parallel.rb +++ b/tool/lib/test/unit/parallel.rb @@ -43,10 +43,9 @@ def _run_suite(suite, type) # :nodoc: th = Thread.new do begin while buf = (self.verbose ? i.gets : i.readpartial(1024)) - _report "p", buf + _report "p", buf or break end rescue IOError - rescue Errno::EPIPE end end @@ -77,9 +76,7 @@ def _run_suite(suite, type) # :nodoc: result << ($: - @old_loadpath) result << suite.name - begin - _report "done", Marshal.dump(result) - rescue Errno::EPIPE; end + _report "done", Marshal.dump(result) return result ensure MiniTest::Unit.output = orig_stdout @@ -128,32 +125,25 @@ def run(args = []) # :nodoc: _run_suites MiniTest::Unit::TestCase.test_suites-suites, $2.to_sym if @need_exit - begin - _report "bye" - rescue Errno::EPIPE; end + _report "bye" exit else _report "ready" end when /^quit$/ - begin - _report "bye" - rescue Errno::EPIPE; end + _report "bye" exit end end - rescue Errno::EPIPE rescue Exception => e - begin - trace = e.backtrace || ['unknown method'] - err = ["#{trace.shift}: #{e.message} (#{e.class})"] + trace.map{|t| "\t" + t } + trace = e.backtrace || ['unknown method'] + err = ["#{trace.shift}: #{e.message} (#{e.class})"] + trace.map{|t| "\t" + t } - if @stdout - _report "bye", Marshal.dump(err.join("\n")) - else - raise "failed to report a failure due to lack of @stdout" - end - rescue Errno::EPIPE;end + if @stdout + _report "bye", Marshal.dump(err.join("\n")) + else + raise "failed to report a failure due to lack of @stdout" + end exit ensure @stdin.close if @stdin @@ -163,6 +153,8 @@ def run(args = []) # :nodoc: def _report(res, *args) # :nodoc: @stdout.write(args.empty? ? "#{res}\n" : "#{res} #{args.pack("m0")}\n") + true + rescue Errno::EPIPE rescue TypeError => e abort("#{e.inspect} in _report(#{res.inspect}, #{args.inspect})\n#{e.backtrace.join("\n")}") end diff --git a/tool/pure_parser.rb b/tool/pure_parser.rb index e4aedfa81b775c..d07df681be9c3b 100755 --- a/tool/pure_parser.rb +++ b/tool/pure_parser.rb @@ -18,3 +18,4 @@ ARGV.push(file) } $_.sub!(/^%define\s+api\.pure/, '%pure-parser') +$_.sub!(/^%define\s+.*/, '') diff --git a/tool/ruby_vm/views/_mjit_compile_insn_body.erb b/tool/ruby_vm/views/_mjit_compile_insn_body.erb index a2a750fbdc3f39..bc77b02b71d1ae 100644 --- a/tool/ruby_vm/views/_mjit_compile_insn_body.erb +++ b/tool/ruby_vm/views/_mjit_compile_insn_body.erb @@ -101,7 +101,7 @@ % # #define STACK_ADDR_FROM_TOP(n) (GET_SP()-(n)) % num = Regexp.last_match[:num] fprintf(f, <%= to_cstr.call(line.sub(/\bSTACK_ADDR_FROM_TOP\(([^)]+)\)/, '%s')) %>, - (status->local_stack_p ? "stack + (stack_size - (<%= num %>))" : "STACK_ADDR_FROM_TOP(<%= num %>)")); + (status->local_stack_p ? "(stack + (stack_size - (<%= num %>)))" : "STACK_ADDR_FROM_TOP(<%= num %>)")); % when /\bTOPN\((?[^)]+)\)/ % # #define TOPN(n) (*(GET_SP()-(n)-1)) % num = Regexp.last_match[:num] diff --git a/tool/ruby_vm/views/_mjit_compile_send.erb b/tool/ruby_vm/views/_mjit_compile_send.erb index 2b1ecdb2f3c903..d1f4692b5f549d 100644 --- a/tool/ruby_vm/views/_mjit_compile_send.erb +++ b/tool/ruby_vm/views/_mjit_compile_send.erb @@ -50,7 +50,7 @@ fprintf(f, " {\n"); fprintf(f, " VALUE orig_self = reg_cfp->self;\n"); fprintf(f, " reg_cfp->self = stack[%d];\n", b->stack_size + sp_inc - 1); - fprintf(f, " stack[%d] = _mjit_inlined_%d(ec, reg_cfp, orig_self, original_iseq);\n", b->stack_size + sp_inc - 1, pos); + fprintf(f, " stack[%d] = _mjit%d_inlined_%d(ec, reg_cfp, orig_self, original_iseq);\n", b->stack_size + sp_inc - 1, status->compiled_id, pos); fprintf(f, " reg_cfp->self = orig_self;\n"); fprintf(f, " }\n"); } diff --git a/tool/sync_default_gems.rb b/tool/sync_default_gems.rb index d034e723a45363..504c3b1980689c 100644 --- a/tool/sync_default_gems.rb +++ b/tool/sync_default_gems.rb @@ -374,11 +374,14 @@ def sync_default_gems_with_commits(gem, range) if result.empty? skipped = true - elsif result.start_with?("CONFLICT") + elsif /^CONFLICT/ =~ result result = IO.popen(%W"git status --porcelain", &:readlines).each(&:chomp!) - ignore = result.map {|line| /^DU / =~ line and IGNORE_FILE_PATTERN =~ (name = $') and name} + ignore = result.map {|line| /^.U / =~ line and IGNORE_FILE_PATTERN =~ (name = $') and name} ignore.compact! - system(*%W"git reset", *ignore) unless ignore.empty? + unless ignore.empty? + system(*%W"git reset HEAD --", *ignore) + system(*%W"git checkout HEAD --", *ignore) + end skipped = !system({"GIT_EDITOR"=>"true"}, *%W"git cherry-pick --no-edit --continue") end @@ -443,12 +446,12 @@ def update_default_gems(gem) end `git fetch ruby-core master --no-tags` unless `git branch`.match(/ruby\-core/) - `git co ruby-core/master` + `git checkout ruby-core/master` `git branch ruby-core` end - `git co ruby-core` + `git checkout ruby-core` `git rebase ruby-core/master` - `git co master` + `git checkout master` `git fetch origin master` `git rebase origin/master` end diff --git a/tool/ytab.sed b/tool/ytab.sed index ba7566ac7fab57..95a9b3e1eb3315 100755 --- a/tool/ytab.sed +++ b/tool/ytab.sed @@ -14,6 +14,7 @@ a\ } /^yydestruct.*yymsg/,/{/{ /^yydestruct/{ + /,$/N /[, *]p)/!{ H s/^/ruby_parser_&/ diff --git a/version.h b/version.h index 0149e01d04e962..8f72bf9cdedd44 100644 --- a/version.h +++ b/version.h @@ -15,8 +15,8 @@ #define RUBY_PATCHLEVEL -1 #define RUBY_RELEASE_YEAR 2020 -#define RUBY_RELEASE_MONTH 4 -#define RUBY_RELEASE_DAY 16 +#define RUBY_RELEASE_MONTH 5 +#define RUBY_RELEASE_DAY 6 #include "ruby/version.h" diff --git a/vm_dump.c b/vm_dump.c index f9edd05b99b251..01f54490fa82bc 100644 --- a/vm_dump.c +++ b/vm_dump.c @@ -36,12 +36,6 @@ #include "iseq.h" #include "vm_core.h" - -/* see vm_insnhelper.h for the values */ -#ifndef VMDEBUG -#define VMDEBUG 0 -#endif - #define MAX_POSBUF 128 #define VM_CFP_CNT(ec, cfp) \ @@ -761,7 +755,7 @@ rb_print_backtrace(void) #define MAX_NATIVE_TRACE 1024 static void *trace[MAX_NATIVE_TRACE]; int n = (int)backtrace(trace, MAX_NATIVE_TRACE); -#if (defined(USE_ELF) || defined(HAVE_MACH_O_LOADER_H)) && defined(HAVE_DLADDR) && !defined(__sparc) +#if (defined(USE_ELF) || defined(HAVE_MACH_O_LOADER_H)) && defined(HAVE_DLADDR) && !defined(__sparc) && !defined(__riscv) rb_dump_backtrace_with_lines(n, trace); #else char **syms = backtrace_symbols(trace, n); diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 70c957cd9a9f13..0fb208446960e8 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -96,6 +96,8 @@ callable_class_p(VALUE klass) #if VM_CHECK_MODE >= 2 if (!klass) return FALSE; switch (RB_BUILTIN_TYPE(klass)) { + default: + break; case T_ICLASS: if (!RB_TYPE_P(RCLASS_SUPER(klass), T_MODULE)) break; case T_MODULE: diff --git a/vm_method.c b/vm_method.c index afda598aa1127c..150fc9d55fe5da 100644 --- a/vm_method.c +++ b/vm_method.c @@ -936,7 +936,7 @@ search_method_protect(VALUE klass, ID id, VALUE *defined_class_ptr) MJIT_FUNC_EXPORTED const rb_method_entry_t * rb_method_entry(VALUE klass, ID id) { - return search_method(klass, id, NULL); + return search_method_protect(klass, id, NULL); } static inline const rb_callable_method_entry_t *