Sean Kearon
Sean Kearon

Reputation: 11427

Location of the script file in ScriptCS

When running a ScriptCS .CSX script, is there a way to get the location of the current script file?

Upvotes: 0

Views: 238

Answers (1)

Sean Kearon
Sean Kearon

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

Related Questions