source_win_bat 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 13570792e56f831dce6bdc6c882950bfa681bedeb3e06bc6ef6ad4ef06b7a853
4
- data.tar.gz: 0a68d985177b5f751b7fd7ebdf06440cda0269ec03347b261615ac919a80da3b
3
+ metadata.gz: 2c46cbace49e6e3914b1f3d5152349714d731635f12c26be4d55b58a590a9651
4
+ data.tar.gz: 36dcbb2f601fde0b2805b6387ee22205c47d48247e320c92ba6ea059c75ba8f3
5
5
  SHA512:
6
- metadata.gz: db9581bba734ea26bad073cce02811c74ff748037e99165a57f07c81dad7590537b9af04bb445db084e249e7d73fb6e3d500e36ce863eac5778c29373cedfbd9
7
- data.tar.gz: 2e8c8d97f2285224a2608dafda5045c36ce67790c30d26a0b70e030f97ba439c20f49657ec6400ee06b16be0493c72ff214596ac15083ebe23057792498f6746
6
+ metadata.gz: 92f80de09376677f864f6817291965309d17c7f9be4a2f733193b381a0141eaade5928c99ce853153539ad97a79a5e7576c0739b5bd40ae00cb228b65db62278
7
+ data.tar.gz: 7ce72e5a78583ad0124a72efdb50478d33b8f7ffa36b3a7f9824594dc72643451ef24c7fa95781a372d247a0d31e6ff735882d512af9e20c722b04a2115cfedd
data/Rakefile CHANGED
@@ -47,7 +47,12 @@ task :test do
47
47
  end
48
48
  cd2test = "cd \"$(#{convpath_win2compat} '#{tests_winpath}')\"; "
49
49
  rubylib = "RUBYLIB=\"$(#{convpath_win2compat} '#{lib_winpath}')\" "
50
- prove = "prove -e /bin/bash -j4 test_*.bash; "
50
+ if ENV['TEST']
51
+ testcases = ENV['TEST']
52
+ else
53
+ testcases = "test_*.bash"
54
+ end
55
+ prove = "prove -e /bin/bash -j4 #{testcases}; "
51
56
 
52
57
  cmd_in_env = cd2test + rubylib + prove
53
58
  if env == UnixCompatEnv.compat_env
@@ -6,7 +6,7 @@ require_relative 'unixcompatenv'
6
6
 
7
7
  class SourceWindowsBatch
8
8
 
9
- VERSION = "0.1.0"
9
+ VERSION = "0.2.0"
10
10
 
11
11
  def main(argv)
12
12
  if argv.length < 4 || argv[3].chomp.empty?
@@ -102,14 +102,31 @@ Internal Ruby command Usage:
102
102
  wslenvs
103
103
  end
104
104
 
105
+ def whitelist_block?(envvar_name)
106
+ return false if !ENV["SWB_WHITELIST"]
107
+ ENV["SWB_WHITELIST"].split(":").each do |name_regexp|
108
+ return false if Regexp.new(name_regexp) =~ envvar_name
109
+ end
110
+ true
111
+ end
112
+
113
+ def blacklist_block?(envvar_name)
114
+ return false if !ENV["SWB_BLACKLIST"]
115
+ ENV["SWB_BLACKLIST"].split(":").each do |name_regexp|
116
+ return true if Regexp.new(name_regexp) =~ envvar_name
117
+ end
118
+ false
119
+ end
120
+
105
121
  def prepare_env_vars
106
122
  return {} if UnixCompatEnv.compat_env != :wsl
107
123
 
108
124
  wslenvs = Hash[]
109
125
  ENV.each do |envvar_name, _|
126
+ next if whitelist_block?(envvar_name) || blacklist_block?(envvar_name)
110
127
  wslenvs[envvar_name] = ""
111
128
  end
112
- wslenvs.merge!(parse_wslenv(ENV['WSLENV']))
129
+ wslenvs.merge!(parse_wslenv(ENV['WSLENV'])) if ENV['WSLENV']
113
130
  # We don't use '/l' option, but convert paths by ourselves instead.
114
131
  # See the comment that starts with 'How PATH in WSLENV is handled'
115
132
  wslenvs['PATH'] = ""
@@ -161,22 +178,6 @@ Internal Ruby command Usage:
161
178
  str.gsub(/'/, '"\'"')
162
179
  end
163
180
 
164
- def conv_to_host_cmds(in_file, out_file, conv_method, env)
165
- unless File.exist?(in_file)
166
- return
167
- end
168
- File.open(out_file, "w") do |out|
169
- File.open(in_file) do |f|
170
- f.each_line do |line|
171
- line.force_encoding("ASCII-8BIT")
172
- converted = conv_method.call(line, env)
173
- out.puts converted if converted
174
- end
175
- end
176
- end
177
- end
178
-
179
-
180
181
  def to_compat_pathlist(path, shell)
181
182
  raise "Unsupporeted" unless shell == :bash
182
183
  path.split(";")
@@ -216,6 +217,7 @@ Internal Ruby command Usage:
216
217
 
217
218
  is_var_valid = /^[a-zA-Z_][_0-9a-zA-Z]*$/ =~ var
218
219
  next if !is_var_valid
220
+ next if whitelist_block?(var) || blacklist_block?(var)
219
221
 
220
222
  if var == "PATH"
221
223
  val = to_compat_pathlist(val, shell)
@@ -234,7 +236,7 @@ Internal Ruby command Usage:
234
236
  # Leave the PATH's WSLENV flag as is
235
237
  wslenvs = Hash[*envs.flat_map {|env| [env, ""]}]
236
238
  wslenvs.delete('PATH')
237
- wslenvs.merge!(parse_wslenv(ENV['WSLENV']))
239
+ wslenvs.merge!(parse_wslenv(ENV['WSLENV'])) if ENV['WSLENV']
238
240
 
239
241
  if wslenvs.length > 0
240
242
  f_out.puts("export WSLENV='#{serialize_wslenvs(wslenvs)}'")
Binary file
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'source_win_bat'
3
- s.version = '0.1.0'
3
+ s.version = '0.2.0'
4
4
  s.date = '2019-01-05'
5
5
  s.summary = "'source' Windows bat files in your UNIX compatible shell in Windows"
6
6
  s.description = <<EOS
@@ -12,6 +12,6 @@ EOS
12
12
  s.email = 'abc.tkys+pub@gmail.com'
13
13
  s.files = `git ls-files`.split("\n")
14
14
  s.executables = ["init_sw"]
15
- s.homepage = 'http://rubygems.org/gems/source_win_bat'
15
+ s.homepage = 'https://github.com/nullpo-head/source-win-bat'
16
16
  s.license = 'MIT'
17
17
  end
File without changes
data/test/setcwd.cmd CHANGED
File without changes
data/test/setdoskey.cmd CHANGED
File without changes
data/test/setenv.cmd CHANGED
File without changes
data/test/setup_test.bash CHANGED
File without changes
@@ -1,6 +1,12 @@
1
1
  #!/bin/bash
2
2
 
3
3
  source ./setup_test.bash
4
+ if [[ "$(uname)" != Linux ]]; then
5
+ # Cygwin and MSYS2 currently fail in this test
6
+ tap_tests 0
7
+ exit 0
8
+ fi
9
+
4
10
  tap_tests 6
5
11
 
6
12
  export jp=日本語
data/test/test_exit.bash CHANGED
@@ -9,5 +9,5 @@ sw exit 0
9
9
  sw exit 42
10
10
  [[ $? = 42 ]]; tap_okif $? "Test exitcode is propagated 2"
11
11
 
12
- sw exit.cmd
12
+ sw exit_42.cmd
13
13
  [[ $? = 42 ]]; tap_okif $? "Test exitcode is propagated 3"
@@ -0,0 +1,24 @@
1
+ #!/bin/bash
2
+
3
+ source ./setup_test.bash
4
+ tap_tests 9
5
+
6
+ export SWB_BLACKLIST="SWB_FOO:SWB_BLACK_.*:SWB_BAR"
7
+ [[ -z "$(sw set SWB_FOO=FOO; echo $SWB_FOO)" ]]; tap_okif $?
8
+ [[ -z "$(sw set SWB_BLACK_FOO=FOO; echo $SWB_BLACK_FOO)" ]]; tap_okif $?
9
+ [[ -z "$(sw set SWB_BAR=BAR; echo $SWB_BAR)" ]]; tap_okif $?
10
+ [[ $(sw set SWB_BAZ=BAZ; echo $SWB_BAZ) = BAZ ]]; tap_okif $?
11
+
12
+
13
+ export SWB_WHITELIST="SWB_W1:SWB_WHITE_.*:SWB_W2"
14
+ export SWB_W1="foo"
15
+ export SWB_WHITE_FOO="foo foo"
16
+ export SWB_W2="bar"
17
+ [[ $(sw set SWB_W1=foo; echo $SWB_W1) = foo ]]; tap_okif $?
18
+ [[ $(sw set SWB_WHITE_FOO=foo; echo $SWB_WHITE_FOO) = foo ]]; tap_okif $?
19
+ [[ $(sw set SWB_W2=bar; echo $SWB_W2) = bar ]]; tap_okif $?
20
+ [[ -z "$(sw set SWB_W3=baz; echo $SWB_W3)" ]]; tap_okif $?
21
+
22
+ export SWB_W1=
23
+ export SWB_BLACKLIST="${SWB_BLACLIST}:SWB_W1"
24
+ [[ -z "$(sw set SWB_W1=W1; echo $SWB_W1)" ]]; tap_okif $?
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+
3
+ source ./setup_test.bash
4
+ tap_tests 1
5
+
6
+ unset WSLENV
7
+ if sw echo test > /dev/null; then tap_ok; else tap_notok; fi
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: source_win_bat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takaya Saeki
@@ -25,8 +25,9 @@ files:
25
25
  - bin/init_sw
26
26
  - lib/source_win_bat.rb
27
27
  - lib/unixcompatenv.rb
28
+ - source_win_bat-0.1.0.gem
28
29
  - source_win_bat.gemspec
29
- - test/exit.cmd
30
+ - test/exit_42.cmd
30
31
  - test/setcwd.cmd
31
32
  - test/setdoskey.cmd
32
33
  - test/setenv.cmd
@@ -38,7 +39,9 @@ files:
38
39
  - test/test_setcwd.bash
39
40
  - test/test_setdoskey.bash
40
41
  - test/test_setenv.bash
41
- homepage: http://rubygems.org/gems/source_win_bat
42
+ - test/test_whiteblacklist.bash
43
+ - test/test_wslenvunsetbug.bash
44
+ homepage: https://github.com/nullpo-head/source-win-bat
42
45
  licenses:
43
46
  - MIT
44
47
  metadata: {}