Reputation: 11427
When running a ScriptCS .CSX script, is there a way to get the location of the current script file?
Upvotes: 0
Views: 238
Reputation: 11427
Okay, so you can access that using Env.ScriptPath
from inside your CSX script.
The test below shows that in action, and can be found here.
[Scenario]
public static void ScriptPathIsSet(ScenarioDirectory directory, string output)
{
var scenario = MethodBase.GetCurrentMethod().GetFullName();
"Given a script which accesses Env.ScriptPath"
.f(() => directory = ScenarioDirectory.Create(scenario)
.WriteLine("foo.csx", "Console.WriteLine(Env.ScriptPath)"));
"When I execute the script"
.f(() => output = ScriptCsExe.Run("foo.csx", directory));
"Then the ScriptPath is displayed"
.f(() => output.ShouldContain("foo.csx"));
}
Upvotes: 1