about summary refs log tree commit homepage
path: root/test
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2013-09-07 21:25:17 +0000
committerEric Wong <normalperson@yhbt.net>2013-09-07 22:35:35 +0000
commitd2f75170a6c1548b85335c7e84a000ed67a0158b (patch)
treefb8fba7c6d1f15826ad5f3118367c3ec57241524 /test
parent136f46adb568b964f61ecdafcd28936c44680b78 (diff)
downloaddtas-d2f75170a6c1548b85335c7e84a000ed67a0158b.tar.gz
This will allow users to more-easily edit configs and feel
like a real shell.  We no longer mistakenly expand nil env
variables to "" anymore, either.
Diffstat (limited to 'test')
-rw-r--r--test/test_env.rb55
-rw-r--r--test/test_rg_integration.rb3
2 files changed, 56 insertions, 2 deletions
diff --git a/test/test_env.rb b/test/test_env.rb
new file mode 100644
index 0000000..92fc53c
--- /dev/null
+++ b/test/test_env.rb
@@ -0,0 +1,55 @@
+# Copyright (C) 2013, Eric Wong <normalperson@yhbt.net> and all contributors
+# License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt)
+require_relative 'helper'
+require 'dtas/process'
+class TestEnv < Testcase
+  include DTAS::Process
+  def setup
+    @orig = ENV.to_hash
+  end
+
+  def teardown
+    ENV.clear
+    ENV.update(@orig)
+  end
+
+  def test_expand
+    ENV["HELLO"] = 'HIHI'
+    expect = { "BLAH" => "HIHI/WORLD" }
+    opts = {}
+
+    env = { "BLAH" => "$HELLO/WORLD" }
+    assert_equal(expect, env_expand(env, opts))
+
+    env = { "BLAH" => "${HELLO}/WORLD" }
+    assert_equal(expect, env_expand(env, opts))
+
+    env = { "BLAH" => "$(echo $HELLO)/WORLD" }
+    assert_equal(expect, env_expand(env, opts))
+
+    env = { "BLAH" => "`echo $HELLO/WORLD`" }
+    assert_equal(expect, env_expand(env, opts))
+
+    env = { "BLAH" => "HIHI/WORLD" }
+    assert_equal(expect, env_expand(env, opts))
+
+    # disable expansion
+    env = expect = { "BLAH" => "`echo $HELLO/WORLD`" }
+    assert_equal(expect, env_expand(env, expand: false))
+
+    # numeric expansion always happens
+    env = { "BLAH" => 1 }
+    assert_equal({"BLAH"=>"1"}, env_expand(env, expand: false))
+    env = { "BLAH" => 1 }
+    assert_equal({"BLAH"=>"1"}, env_expand(env, {}))
+
+    expect = { "BLAH" => nil }
+    env = expect.dup
+    assert_equal expect, env_expand(env, expand:false)
+    assert_equal expect, env_expand(env, expand:true)
+
+    # recursive expansion
+    res = env_expand({"PATH"=>"$PATH"}, expand: true)
+    assert_equal ENV["PATH"], res["PATH"]
+  end
+end
diff --git a/test/test_rg_integration.rb b/test/test_rg_integration.rb
index d6a90b0..2779f86 100644
--- a/test/test_rg_integration.rb
+++ b/test/test_rg_integration.rb
@@ -40,7 +40,7 @@ class TestRgIntegration < Testcase
       end while cur["current_offset"] == 0 && sleep(0.01)
     end
 
-    assert_empty cur["current"]["env"]["RGFX"]
+    assert_nil cur["current"]["env"]["RGFX"]
 
     assert_equal DTAS::Format.new.rate * len, cur["current_expect"]
 
@@ -119,7 +119,6 @@ class TestRgIntegration < Testcase
       "REPLAYGAIN_ALBUM_GAIN" => "-3.0",
       "REPLAYGAIN_TRACK_PEAK" => "0.666",
       "REPLAYGAIN_ALBUM_PEAK" => "0.999",
-      "REPLAYGAIN_REFERENCE_LOUDNESS" => nil
     }
     assert_equal expect, rg
   end