dtas.git  about / heads / tags
duct tape audio suite for *nix
blob bd7961d5f8e702da37e4c78bf31242e0069d5f29 1527 bytes (raw)
$ git show tfx-pu:test/test_env.rb	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
 
# Copyright (C) 2013-2015 all contributors <dtas-all@nongnu.org>
# 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

git clone git://80x24.org/dtas.git
git clone https://80x24.org/dtas.git