Skip to content

Commit 047626d

Browse files
committed
try with 'set' instead 'echo'
1 parent de48f84 commit 047626d

File tree

1 file changed

+54
-11
lines changed

1 file changed

+54
-11
lines changed

tests/test_cli.py

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import sys
23
from pathlib import Path
34
from typing import Optional
45

@@ -185,13 +186,28 @@ def test_run(tmp_path):
185186
with pushd(tmp_path):
186187
(tmp_path / ".env").write_text("a=b")
187188

189+
# Use sys.executable to run the command via Python directly
188190
if IS_WINDOWS:
189-
printenv_cmd = ["dotenv", "run", "cmd", "/c", "echo", "%a%"]
191+
# On Windows, use set command instead of echo with variable expansion
192+
printenv_cmd = [
193+
sys.executable,
194+
"-m",
195+
"dotenv",
196+
"run",
197+
"cmd",
198+
"/c",
199+
"set",
200+
"a",
201+
]
190202
else:
191203
printenv_cmd = ["dotenv", "run", "printenv", "a"]
192204

193205
result = run_command(printenv_cmd)
194-
assert result == "b\n"
206+
if IS_WINDOWS:
207+
# Windows 'set' command includes variable name, extract just the value
208+
assert result.strip().endswith("=b")
209+
else:
210+
assert result == "b\n"
195211

196212

197213
def test_run_with_existing_variable(tmp_path):
@@ -201,13 +217,23 @@ def test_run_with_existing_variable(tmp_path):
201217
env.update({"LANG": "en_US.UTF-8", "a": "c"})
202218

203219
if IS_WINDOWS:
204-
printenv_cmd = ["dotenv", "run", "cmd", "/c", "echo", "%a%"]
220+
printenv_cmd = [
221+
"dotenv",
222+
"run",
223+
"cmd",
224+
"/c",
225+
"set",
226+
"a",
227+
]
205228
else:
206229
printenv_cmd = ["dotenv", "run", "printenv", "a"]
207230

208231
result = run_command(printenv_cmd, env=env)
209-
210-
assert result == "b\n"
232+
if IS_WINDOWS:
233+
# Windows 'set' command includes variable name, extract just the value
234+
assert result.strip().endswith("=b")
235+
else:
236+
assert result == "b\n"
211237

212238

213239
def test_run_with_existing_variable_not_overridden(tmp_path):
@@ -224,28 +250,45 @@ def test_run_with_existing_variable_not_overridden(tmp_path):
224250
"--no-override",
225251
"cmd",
226252
"/c",
227-
"echo",
228-
"%a%",
253+
"set",
254+
"a",
229255
]
230256
else:
231257
printenv_cmd = ["dotenv", "run", "--no-override", "printenv", "a"]
232258

233259
result = run_command(printenv_cmd, env=env)
234260

235-
assert result == "c\n"
261+
if IS_WINDOWS:
262+
# Windows 'set' command includes variable name, extract just the value
263+
assert result.strip().endswith("=c")
264+
else:
265+
assert result == "c\n"
236266

237267

238268
def test_run_with_none_value(tmp_path):
239269
with pushd(tmp_path):
240270
(tmp_path / ".env").write_text("a=b\nc")
271+
# Use sys.executable to run the command via Python directly
241272
if IS_WINDOWS:
242-
printenv_cmd = ["dotenv", "run", "cmd", "/c", "echo", "%a%"]
273+
printenv_cmd = [
274+
sys.executable,
275+
"-m",
276+
"dotenv",
277+
"run",
278+
"cmd",
279+
"/c",
280+
"set",
281+
"a",
282+
]
243283
else:
244284
printenv_cmd = ["dotenv", "run", "printenv", "a"]
245285

246286
result = run_command(printenv_cmd)
247-
248-
assert result == "b\n"
287+
if IS_WINDOWS:
288+
# Windows 'set' command includes variable name, extract just the value
289+
assert result.strip().endswith("=b")
290+
else:
291+
assert result == "b\n"
249292

250293

251294
def test_run_with_other_env(dotenv_path):

0 commit comments

Comments
 (0)