summaryrefslogtreecommitdiff
path: root/spec/ruby/command_line
diff options
context:
space:
mode:
authoreregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-08-27 14:25:00 +0000
committereregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-08-27 14:25:00 +0000
commit8180b5bfc0fe4d4b91b590de9110687294552a8f (patch)
treefb6b2270b710d2a8390a1cb0d0bb76b9cbc1c6ad /spec/ruby/command_line
parenta6413848153e6c37f6b0fea64e3e871460732e34 (diff)
Update to ruby/spec@09fa86c
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64565 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/command_line')
-rw-r--r--spec/ruby/command_line/dash_a_spec.rb2
-rw-r--r--spec/ruby/command_line/dash_encoding_spec.rb33
-rw-r--r--spec/ruby/command_line/dash_external_encoding_spec.rb15
-rw-r--r--spec/ruby/command_line/dash_internal_encoding_spec.rb15
-rw-r--r--spec/ruby/command_line/dash_n_spec.rb2
-rw-r--r--spec/ruby/command_line/dash_p_spec.rb2
-rw-r--r--spec/ruby/command_line/dash_upper_e_spec.rb2
-rw-r--r--spec/ruby/command_line/dash_upper_f_spec.rb2
-rw-r--r--spec/ruby/command_line/dash_upper_k_spec.rb77
-rw-r--r--spec/ruby/command_line/dash_upper_u_spec.rb2
-rw-r--r--spec/ruby/command_line/dash_x_spec.rb2
-rwxr-xr-x[-rw-r--r--]spec/ruby/command_line/fixtures/bin/launcher.rb0
12 files changed, 132 insertions, 22 deletions
diff --git a/spec/ruby/command_line/dash_a_spec.rb b/spec/ruby/command_line/dash_a_spec.rb
index 65f79ec208..9ea135dc76 100644
--- a/spec/ruby/command_line/dash_a_spec.rb
+++ b/spec/ruby/command_line/dash_a_spec.rb
@@ -1,3 +1,5 @@
+require_relative '../spec_helper'
+
describe "The -a command line option" do
before :each do
@names = fixture __FILE__, "full_names.txt"
diff --git a/spec/ruby/command_line/dash_encoding_spec.rb b/spec/ruby/command_line/dash_encoding_spec.rb
new file mode 100644
index 0000000000..e7889b4def
--- /dev/null
+++ b/spec/ruby/command_line/dash_encoding_spec.rb
@@ -0,0 +1,33 @@
+require_relative '../spec_helper'
+
+describe 'The --encoding command line option' do
+ before :each do
+ @test_string = "print [Encoding.default_external.name, Encoding.default_internal&.name].inspect"
+ end
+
+ describe 'sets Encoding.default_external and optionally Encoding.default_internal' do
+ it "if given a single encoding with an =" do
+ ruby_exe(@test_string, options: '--disable-gems --encoding=big5').should == [Encoding::Big5.name, nil].inspect
+ end
+
+ it "if given a single encoding as a separate argument" do
+ ruby_exe(@test_string, options: '--disable-gems --encoding big5').should == [Encoding::Big5.name, nil].inspect
+ end
+
+ it "if given two encodings with an =" do
+ ruby_exe(@test_string, options: '--disable-gems --encoding=big5:utf-32be').should == [Encoding::Big5.name, Encoding::UTF_32BE.name].inspect
+ end
+
+ it "if given two encodings as a separate argument" do
+ ruby_exe(@test_string, options: '--disable-gems --encoding big5:utf-32be').should == [Encoding::Big5.name, Encoding::UTF_32BE.name].inspect
+ end
+
+ it "if given two encodings as a separate argument" do
+ ruby_exe(@test_string, options: '--disable-gems --encoding big5:utf-32be').should == [Encoding::Big5.name, Encoding::UTF_32BE.name].inspect
+ end
+ end
+
+ it "does not accept a third encoding" do
+ ruby_exe(@test_string, options: '--disable-gems --encoding big5:utf-32be:utf-32le', args: '2>&1').should =~ /extra argument for --encoding: utf-32le/
+ end
+end
diff --git a/spec/ruby/command_line/dash_external_encoding_spec.rb b/spec/ruby/command_line/dash_external_encoding_spec.rb
new file mode 100644
index 0000000000..f052674dc8
--- /dev/null
+++ b/spec/ruby/command_line/dash_external_encoding_spec.rb
@@ -0,0 +1,15 @@
+require_relative '../spec_helper'
+
+describe 'The --external-encoding command line option sets Encoding.default_external' do
+ before :each do
+ @test_string = "print Encoding.default_external.name"
+ end
+
+ it "if given an encoding with an =" do
+ ruby_exe(@test_string, options: '--external-encoding=big5').should == Encoding::Big5.name
+ end
+
+ it "if given an encoding as a separate argument" do
+ ruby_exe(@test_string, options: '--external-encoding big5').should == Encoding::Big5.name
+ end
+end
diff --git a/spec/ruby/command_line/dash_internal_encoding_spec.rb b/spec/ruby/command_line/dash_internal_encoding_spec.rb
new file mode 100644
index 0000000000..3049040bb4
--- /dev/null
+++ b/spec/ruby/command_line/dash_internal_encoding_spec.rb
@@ -0,0 +1,15 @@
+require_relative '../spec_helper'
+
+describe 'The --internal-encoding command line option sets Encoding.default_internal' do
+ before :each do
+ @test_string = "print Encoding.default_internal.name"
+ end
+
+ it "if given an encoding with an =" do
+ ruby_exe(@test_string, options: '--internal-encoding=big5').should == Encoding::Big5.name
+ end
+
+ it "if given an encoding as a separate argument" do
+ ruby_exe(@test_string, options: '--internal-encoding big5').should == Encoding::Big5.name
+ end
+end
diff --git a/spec/ruby/command_line/dash_n_spec.rb b/spec/ruby/command_line/dash_n_spec.rb
index f4dd9f1851..9d331d6065 100644
--- a/spec/ruby/command_line/dash_n_spec.rb
+++ b/spec/ruby/command_line/dash_n_spec.rb
@@ -1,3 +1,5 @@
+require_relative '../spec_helper'
+
describe "The -n command line option" do
before :each do
@names = fixture __FILE__, "names.txt"
diff --git a/spec/ruby/command_line/dash_p_spec.rb b/spec/ruby/command_line/dash_p_spec.rb
index 67562b5bc3..39827c3868 100644
--- a/spec/ruby/command_line/dash_p_spec.rb
+++ b/spec/ruby/command_line/dash_p_spec.rb
@@ -1,3 +1,5 @@
+require_relative '../spec_helper'
+
describe "The -p command line option" do
before :each do
@names = fixture __FILE__, "names.txt"
diff --git a/spec/ruby/command_line/dash_upper_e_spec.rb b/spec/ruby/command_line/dash_upper_e_spec.rb
index 39ffa001a3..b3c6ce262b 100644
--- a/spec/ruby/command_line/dash_upper_e_spec.rb
+++ b/spec/ruby/command_line/dash_upper_e_spec.rb
@@ -1,3 +1,5 @@
+require_relative '../spec_helper'
+
describe "ruby -E" do
it "sets the external encoding with '-E external'" do
result = ruby_exe("print Encoding.default_external", options: '-E euc-jp')
diff --git a/spec/ruby/command_line/dash_upper_f_spec.rb b/spec/ruby/command_line/dash_upper_f_spec.rb
index 020968b1f9..967acc2ece 100644
--- a/spec/ruby/command_line/dash_upper_f_spec.rb
+++ b/spec/ruby/command_line/dash_upper_f_spec.rb
@@ -1,3 +1,5 @@
+require_relative '../spec_helper'
+
describe "the -F command line option" do
before :each do
@passwd = fixture __FILE__, "passwd_file.txt"
diff --git a/spec/ruby/command_line/dash_upper_k_spec.rb b/spec/ruby/command_line/dash_upper_k_spec.rb
index 3c3b9fa4d3..d7e16d6ede 100644
--- a/spec/ruby/command_line/dash_upper_k_spec.rb
+++ b/spec/ruby/command_line/dash_upper_k_spec.rb
@@ -1,33 +1,66 @@
-describe 'The -K command line option sets __ENCODING__' do
- it "to Encoding::ASCII_8BIT with -Ka" do
- ruby_exe("print __ENCODING__", options: '-Ka').should == Encoding::ASCII_8BIT.to_s
- end
+require_relative '../spec_helper'
- it "to Encoding::ASCII_8BIT with -KA" do
- ruby_exe("print __ENCODING__", options: '-KA').should == Encoding::ASCII_8BIT.to_s
+describe 'The -K command line option' do
+ before :each do
+ @test_string = "print [__ENCODING__&.name, Encoding.default_external&.name, Encoding.default_internal&.name].inspect"
end
- it "to Encoding::EUC_JP with -Ke" do
- ruby_exe("print __ENCODING__", options: '-Ke').should == Encoding::EUC_JP.to_s
- end
+ describe 'sets __ENCODING__ and Encoding.default_external' do
+ it "to Encoding::ASCII_8BIT with -Ka" do
+ ruby_exe(@test_string, options: '-Ka').should ==
+ [Encoding::ASCII_8BIT.name, Encoding::ASCII_8BIT.name, nil].inspect
+ end
- it "to Encoding::EUC_JP with -KE" do
- ruby_exe("print __ENCODING__", options: '-KE').should == Encoding::EUC_JP.to_s
- end
+ it "to Encoding::ASCII_8BIT with -KA" do
+ ruby_exe(@test_string, options: '-KA').should ==
+ [Encoding::ASCII_8BIT.name, Encoding::ASCII_8BIT.name, nil].inspect
+ end
- it "to Encoding::UTF_8 with -Ku" do
- ruby_exe("print __ENCODING__", options: '-Ku').should == Encoding::UTF_8.to_s
- end
+ it "to Encoding::ASCII_8BIT with -Kn" do
+ ruby_exe(@test_string, options: '-Kn').should ==
+ [Encoding::ASCII_8BIT.name, Encoding::ASCII_8BIT.name, nil].inspect
+ end
- it "to Encoding::UTF_8 with -KU" do
- ruby_exe("print __ENCODING__", options: '-KU').should == Encoding::UTF_8.to_s
- end
+ it "to Encoding::ASCII_8BIT with -KN" do
+ ruby_exe(@test_string, options: '-KN').should ==
+ [Encoding::ASCII_8BIT.name, Encoding::ASCII_8BIT.name, nil].inspect
+ end
+
+ it "to Encoding::EUC_JP with -Ke" do
+ ruby_exe(@test_string, options: '-Ke').should ==
+ [Encoding::EUC_JP.name, Encoding::EUC_JP.name, nil].inspect
+ end
+
+ it "to Encoding::EUC_JP with -KE" do
+ ruby_exe(@test_string, options: '-KE').should ==
+ [Encoding::EUC_JP.name, Encoding::EUC_JP.name, nil].inspect
+ end
+
+ it "to Encoding::UTF_8 with -Ku" do
+ ruby_exe(@test_string, options: '-Ku').should ==
+ [Encoding::UTF_8.name, Encoding::UTF_8.name, nil].inspect
+ end
+
+ it "to Encoding::UTF_8 with -KU" do
+ ruby_exe(@test_string, options: '-KU').should ==
+ [Encoding::UTF_8.name, Encoding::UTF_8.name, nil].inspect
+ end
+
+ it "to Encoding::Windows_31J with -Ks" do
+ ruby_exe(@test_string, options: '-Ks').should ==
+ [Encoding::Windows_31J.name, Encoding::Windows_31J.name, nil].inspect
+ end
- it "to Encoding::Windows_31J with -Ks" do
- ruby_exe("print __ENCODING__", options: '-Ks').should == Encoding::Windows_31J.to_s
+ it "to Encoding::Windows_31J with -KS" do
+ ruby_exe(@test_string, options: '-KS').should ==
+ [Encoding::Windows_31J.name, Encoding::Windows_31J.name, nil].inspect
+ end
end
- it "to Encoding::Windows_31J with -KS" do
- ruby_exe("print __ENCODING__", options: '-KS').should == Encoding::Windows_31J.to_s
+ platform_is_not :windows do
+ it "ignores unknown codes" do
+ ruby_exe(@test_string, options: '-KZ').should ==
+ [Encoding::UTF_8.name, Encoding::UTF_8.name, nil].inspect
+ end
end
end
diff --git a/spec/ruby/command_line/dash_upper_u_spec.rb b/spec/ruby/command_line/dash_upper_u_spec.rb
index 6cd52a3647..2546b5b9f4 100644
--- a/spec/ruby/command_line/dash_upper_u_spec.rb
+++ b/spec/ruby/command_line/dash_upper_u_spec.rb
@@ -1,3 +1,5 @@
+require_relative '../spec_helper'
+
describe "ruby -U" do
it "sets Encoding.default_internal to UTF-8" do
ruby_exe('print Encoding.default_internal.name',
diff --git a/spec/ruby/command_line/dash_x_spec.rb b/spec/ruby/command_line/dash_x_spec.rb
index a5306b4f75..ad6be23063 100644
--- a/spec/ruby/command_line/dash_x_spec.rb
+++ b/spec/ruby/command_line/dash_x_spec.rb
@@ -1,3 +1,5 @@
+require_relative '../spec_helper'
+
describe "The -x command line option" do
it "runs code after the first /\#!.*ruby.*/-ish line in target file" do
embedded_ruby = fixture __FILE__, "bin/embedded_ruby.txt"
diff --git a/spec/ruby/command_line/fixtures/bin/launcher.rb b/spec/ruby/command_line/fixtures/bin/launcher.rb
index 92a0ee2b49..92a0ee2b49 100644..100755
--- a/spec/ruby/command_line/fixtures/bin/launcher.rb
+++ b/spec/ruby/command_line/fixtures/bin/launcher.rb