Skip to content

Commit 2a71768

Browse files
Load CsDebugScript.CommonUserTypes.dll in tests, so that tests can be safely executed from Visual Studio.
1 parent 927cd7a commit 2a71768

File tree

4 files changed

+54
-2
lines changed

4 files changed

+54
-2
lines changed

Source/CsDebugScript.Scripting/ScriptCompiler.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ internal static class ScriptCompiler
2525
/// </summary>
2626
internal const string AutoGeneratedScriptFunctionName = "ScriptFunction";
2727

28+
/// <summary>
29+
/// Name of the CommonUserTypes dll file.
30+
/// </summary>
31+
private const string CommonUserTypesDll = "CsDebugScript.CommonUserTypes.dll";
32+
2833
/// <summary>
2934
/// Gets the list of search folders.
3035
/// </summary>
@@ -60,12 +65,23 @@ private static string[] GetDefaultAssemblyReferences()
6065

6166
// Try to find CsDebugScript.CommonUserTypes.dll
6267
string defaultPath = typeof(CsDebugScript.Variable).Assembly.Location;
63-
string commonUserTypes = Path.Combine(Path.GetDirectoryName(defaultPath), "CsDebugScript.CommonUserTypes.dll");
68+
string commonUserTypes = Path.Combine(Path.GetDirectoryName(defaultPath), CommonUserTypesDll);
6469

6570
if (File.Exists(commonUserTypes))
6671
{
6772
assemblyReferences.Add(commonUserTypes);
6873
}
74+
else
75+
{
76+
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
77+
{
78+
if (assembly.Location.EndsWith(CommonUserTypesDll))
79+
{
80+
assemblyReferences.Add(assembly.Location);
81+
break;
82+
}
83+
}
84+
}
6985

7086
// Add support for System.Dynamic
7187
assemblyReferences.Add("Microsoft.CSharp");

Source/CsDebugScript.Scripting/ScriptExecution.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,28 @@ private static string ResolvePath(string reference, string baseFilePath)
125125
return path;
126126
}
127127

128+
// Try to find path relative to current assembly location
129+
try
130+
{
131+
string folder = typeof(ScriptExecution).Assembly.Location;
132+
133+
if (!Path.IsPathRooted(baseFilePath))
134+
{
135+
folder = Path.GetFullPath(baseFilePath);
136+
}
137+
138+
folder = Path.GetDirectoryName(folder);
139+
path = Path.Combine(folder, reference);
140+
path = Path.GetFullPath(path);
141+
if (File.Exists(path))
142+
{
143+
return path;
144+
}
145+
}
146+
catch
147+
{
148+
}
149+
128150
// Look into search folders
129151
foreach (string folder in ScriptCompiler.SearchFolders)
130152
{

Tests/CsDebugScript.Engine.Test/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ static void Main(string[] args)
5555
{
5656
Action action = () =>
5757
{
58-
ScriptExecution.Execute(@"..\..\..\samples\script.csx", args);
58+
ScriptExecution.Execute(@"..\..\samples\script.csx", args);
5959
};
6060
DbgEngDll dbgEngDll = Context.Debugger as DbgEngDll;
6161

Tests/CsDebugScript.Tests/DumpInitialization.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ public class DumpInitialization
1111
{
1212
public const string DefaultDumpPath = @"..\..\..\dumps\";
1313

14+
private static CommonUserTypes.NativeTypes.std.vector vector = InitializeCommonUserTypes();
15+
1416
public DumpInitialization(string dumpPath, string defaultModuleName, string symbolPath)
1517
{
1618
if (!Path.IsPathRooted(dumpPath))
@@ -34,6 +36,18 @@ public DumpInitialization(string dumpPath, string defaultModuleName, string symb
3436
public InteractiveExecution InteractiveExecution { get; private set; } = new InteractiveExecution();
3537

3638
internal bool CodeGenExecuted { get; set; }
39+
40+
private static CommonUserTypes.NativeTypes.std.vector InitializeCommonUserTypes()
41+
{
42+
try
43+
{
44+
return new CommonUserTypes.NativeTypes.std.vector(null);
45+
}
46+
catch
47+
{
48+
return null;
49+
}
50+
}
3751
}
3852

3953
public class ElfCoreDumpInitialization : DumpInitialization

0 commit comments

Comments
 (0)