Skip to content

Commit 307bbc0

Browse files
author
Alistair Turnbull
committed
Set NANCY_INPUT and NANCY_OUTPUT for $run (fix #25), and test
1 parent 82bf964 commit 307bbc0

File tree

9 files changed

+82
-0
lines changed

9 files changed

+82
-0
lines changed

nancy/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,8 @@ def run(self, args: Optional[list[bytes]], input: Optional[bytes]) -> bytes:
497497

498498
exe_path = self._expand.file_arg(args[0], exe=True)
499499
expanded_input = None if input is None else self._expand.expand(input)
500+
os.environ['NANCY_INPUT'] = str(self._expand.root)
501+
os.environ['NANCY_OUTPUT'] = str(self._expand.trees.output)
500502
return filter_bytes(expanded_input, exe_path, args[1:])
501503

502504

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<html>
2+
<head>
3+
</head>
4+
<body>
5+
<p>This is the index.</p>
6+
7+
<p><a href="people/index.html">People</a></p>
8+
9+
<p>NANCY_INPUT is webpage-src
10+
11+
</p>
12+
<p>NANCY_OUTPUT is output
13+
14+
</p>
15+
</body>
16+
</html>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<html>
2+
<head>
3+
</head>
4+
<body>
5+
Adam's page has been overridden.
6+
7+
<p>NANCY_INPUT is env-vars-src
8+
9+
</p>
10+
<p>NANCY_OUTPUT is output
11+
12+
</p>
13+
</body>
14+
</html>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<html>
2+
<head>
3+
</head>
4+
<body>
5+
This is eve&apos;s page.
6+
7+
<p>NANCY_INPUT is webpage-src
8+
9+
</p>
10+
<p>NANCY_OUTPUT is output
11+
12+
</p>
13+
</body>
14+
</html>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<html>
2+
<head>
3+
</head>
4+
<body>
5+
This is people:
6+
7+
<ul>
8+
<li><a href="adam/index.html">adam</a></li>
9+
<li><a href="eve/index.html">eve</a></li>
10+
</ul>
11+
12+
<p>NANCY_INPUT is webpage-src
13+
14+
</p>
15+
<p>NANCY_OUTPUT is output
16+
17+
</p>
18+
</body>
19+
</html>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Adam's page has been overridden.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
$include(template.in.html)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<html>
2+
<head>
3+
</head>
4+
<body>
5+
$include(body.in.html)
6+
7+
<p>NANCY_INPUT is $run(basename,$run(printenv,NANCY_INPUT))</p>
8+
<p>NANCY_OUTPUT is $run(basename,$run(printenv,NANCY_OUTPUT))</p>
9+
</body>
10+
</html>

tests/test_nancy.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ def test_two_trees() -> None:
6262
check_links("mergetrees-expected", "index.html")
6363

6464

65+
def test_env_vars() -> None:
66+
with chdir(tests_dir):
67+
passing_test(["env-vars-src", "webpage-src"], "env-vars-expected")
68+
69+
6570
def test_nested_macro_invocations() -> None:
6671
with chdir(tests_dir):
6772
passing_test(["nested-macro-src"], "nested-macro-expected")

0 commit comments

Comments
 (0)