From 5b87f8f84e469be1511d9f1e6fe0afef122bfb36 Mon Sep 17 00:00:00 2001
From: Volker Hilsheimer <volker.hilsheimer@qt.io>
Date: Sat, 25 May 2019 12:20:12 +0200
Subject: [PATCH] Make box parameter optional for expanding variable

---
 minicoin/Vagrantfile       |  2 +-
 minicoin/tests/autotest.rb | 15 +++++++--------
 2 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/minicoin/Vagrantfile b/minicoin/Vagrantfile
index 3e16a96..c7459fe 100644
--- a/minicoin/Vagrantfile
+++ b/minicoin/Vagrantfile
@@ -263,7 +263,7 @@ def expand_env(value, box)
         end
       end
       value = value.sub("$#{env_name}", env_val)
-      if box.vm.guest == :windows
+      if !box.nil? && box.vm.guest == :windows
         value = value.gsub("/", "\\\\")
       end
     end
diff --git a/minicoin/tests/autotest.rb b/minicoin/tests/autotest.rb
index 0d48354..3acbf80 100644
--- a/minicoin/tests/autotest.rb
+++ b/minicoin/tests/autotest.rb
@@ -90,30 +90,29 @@ class Tester
     end
   end
   def test_expand_env()
+    user = ENV["USER"]
     test_data = {
       "plain" => [:windows, "foo", "foo"],
       "$home_win" => [:windows, "$HOME", "C:\\Users\\host"],
       "$home_nix" => [:linux, "$HOME", "/home/host"],
-      "$home_mac" => [:darwin, "$HOME", "/Users/host"]
+      "$home_mac" => [:darwin, "$HOME", "/Users/host"],
+      "$user" => [nil, "$USER", user],
+      "$user$user" => [nil, "$USER$USER", "#{user}#{user}"]
     }
+
     test_data.each do |name, data|
       @data_count += 1
       guest = data[0]
       input = data[1]
       output = data[2]
 
-      box = Box.new(guest)
+      box = Box.new(guest) unless guest.nil?
       result = expand_env(input, box)
       if result != output
         puts "Fail! for '#{name}', produced '#{result}', expected '#{output}'"
         @error_count += 1
       end
-      end
-
-    box = Box.new(:linux)
-    test_data = {
-      "$HOME" => "C:\\Users\\host"
-    }
+    end
   end
 
   def errors()
-- 
GitLab