Skip to content

Commit b94b4b7

Browse files
committed
C#: Fix tests
1 parent 71e0dc0 commit b94b4b7

File tree

11 files changed

+51
-41
lines changed

11 files changed

+51
-41
lines changed

csharp/extractor/Semmle.Extraction.CSharp.Standalone/BuildAnalysis.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -100,20 +100,20 @@ public BuildAnalysis(Options options, IProgressMonitor progress)
100100

101101
{
102102
// These files can sometimes prevent `dotnet restore` from working correctly.
103-
using var renamer1 = new FileRenamer(sourceDir.GetFiles("global.json", SearchOption.AllDirectories));
104-
using var renamer2 = new FileRenamer(sourceDir.GetFiles("Directory.Build.props", SearchOption.AllDirectories));
105-
106-
var solutions = options.SolutionFile != null ?
107-
new[] { options.SolutionFile } :
108-
sourceDir.GetFiles("*.sln", SearchOption.AllDirectories).Select(d => d.FullName);
109-
103+
using (new FileRenamer(sourceDir.GetFiles("global.json", SearchOption.AllDirectories)))
104+
using (new FileRenamer(sourceDir.GetFiles("Directory.Build.props", SearchOption.AllDirectories)))
105+
{
106+
var solutions = options.SolutionFile != null ?
107+
new[] { options.SolutionFile } :
108+
sourceDir.GetFiles("*.sln", SearchOption.AllDirectories).Select(d => d.FullName);
110109

111-
RestoreSolutions(solutions);
112-
dllDirNames.Add(PackageDirectory.DirInfo.FullName);
113-
assemblyCache = new BuildAnalyser.AssemblyCache(dllDirNames, progress);
114-
AnalyseSolutions(solutions);
110+
RestoreSolutions(solutions);
111+
dllDirNames.Add(PackageDirectory.DirInfo.FullName);
112+
assemblyCache = new BuildAnalyser.AssemblyCache(dllDirNames, progress);
113+
AnalyseSolutions(solutions);
115114

116-
usedReferences = new HashSet<string>(assemblyCache.AllAssemblies.Select(a => a.Filename));
115+
usedReferences = new HashSet<string>(assemblyCache.AllAssemblies.Select(a => a.Filename));
116+
}
117117
}
118118

119119
ResolveConflicts();
@@ -254,7 +254,7 @@ void UnresolvedReference(string id, string projectFile)
254254
unresolvedReferences[id] = projectFile;
255255
}
256256

257-
TemporaryDirectory PackageDirectory;
257+
readonly TemporaryDirectory PackageDirectory;
258258

259259
/// <summary>
260260
/// Reads all the source files and references from the given list of projects.

csharp/extractor/Semmle.Extraction.CSharp.Standalone/CsProjFile.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,6 @@ public void ReadProjectFileAsXml(FileInfo filename)
9090

9191
if(netCoreProjectFile)
9292
{
93-
var frameworksNode = root.SelectNodes("/Project/PropertyGroup/TargetFrameworks").NodeList().Concat(
94-
root.SelectNodes("/Project/PropertyGroup/TargetFramework").NodeList()).Select(node => node.InnerText);
95-
9693
var relativeCsIncludes2 =
9794
root.SelectNodes("/Project/ItemGroup/Compile/@Include", mgr).
9895
NodeList().

csharp/extractor/Semmle.Extraction.CSharp.Standalone/DotNet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static int RestoreToDirectory(string projectOrSolutionFile, string packag
2424
/// </summary>
2525
sealed class FileRenamer : IDisposable
2626
{
27-
string[] files;
27+
readonly string[] files;
2828
const string suffix = ".codeqlhidden";
2929

3030
public FileRenamer(IEnumerable<FileInfo> oldFiles)

csharp/extractor/Semmle.Extraction.CSharp.Standalone/NugetPackages.cs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,15 @@ void RestoreNugetPackage(string package, IProgressMonitor pm)
114114

115115
try
116116
{
117-
using (var p = Process.Start(pi))
117+
using var p = Process.Start(pi);
118+
119+
string output = p.StandardOutput.ReadToEnd();
120+
string error = p.StandardError.ReadToEnd();
121+
122+
p.WaitForExit();
123+
if (p.ExitCode != 0)
118124
{
119-
string output = p.StandardOutput.ReadToEnd();
120-
string error = p.StandardError.ReadToEnd();
121-
122-
p.WaitForExit();
123-
if (p.ExitCode != 0)
124-
{
125-
pm.FailedNugetCommand(pi.FileName, pi.Arguments, output + error);
126-
}
125+
pm.FailedNugetCommand(pi.FileName, pi.Arguments, output + error);
127126
}
128127
}
129128
catch (Exception ex)
@@ -136,6 +135,10 @@ void RestoreNugetPackage(string package, IProgressMonitor pm)
136135
readonly string nugetExe;
137136
}
138137

138+
/// <summary>
139+
/// A temporary directory that is created within the system temp directory.
140+
/// When this object is disposed, the directory is deleted.
141+
/// </summary>
139142
sealed class TemporaryDirectory : IDisposable
140143
{
141144
public DirectoryInfo DirInfo { get; }
@@ -156,7 +159,7 @@ public static string ComputeTempDirectory(string srcDir)
156159
{
157160
var bytes = Encoding.Unicode.GetBytes(srcDir);
158161

159-
var sha1 = new SHA1CryptoServiceProvider();
162+
using var sha1 = new SHA1CryptoServiceProvider();
160163
var sha = sha1.ComputeHash(bytes);
161164
var sb = new StringBuilder();
162165
foreach (var b in sha.Take(8))

csharp/extractor/Semmle.Extraction.CSharp.Standalone/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public class Program
8585
static int Main(string[] args)
8686
{
8787
var options = Options.Create(args);
88-
options.CIL = true;
88+
// options.CIL = true; // To do: Enable this
8989
var output = new ConsoleLogger(options.Verbosity);
9090
var a = new Analysis(output);
9191

csharp/extractor/Semmle.Extraction.CSharp/SymbolExtensions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,6 @@ private static void BuildAssembly(IAssemblySymbol asm, TextWriter trapFile, bool
214214
static void BuildNamedTypeId(this INamedTypeSymbol named, Context cx, TextWriter trapFile, Action<Context, TextWriter, ITypeSymbol> subTermAction)
215215
{
216216
bool prefixAssembly = true;
217-
if (cx.Extractor.Standalone) prefixAssembly = false;
218217
if (named.ContainingAssembly is null) prefixAssembly = false;
219218

220219
if (named.IsTupleType)

csharp/ql/src/semmle/code/csharp/exprs/Access.qll

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,12 @@ library class PropertyAccessExpr extends Expr, @property_access_expr {
388388
/** Gets the target of this property access. */
389389
Property getProperty() { expr_access(this, result) }
390390

391-
override string toString() { result = "access to property " + this.getProperty().getName() }
391+
override string toString() {
392+
result = "access to property " + this.getProperty().getName()
393+
or
394+
not exists(this.getProperty()) and
395+
result = "access to property (unknown)"
396+
}
392397
}
393398

394399
/**

csharp/ql/test/library-tests/standalone/controlflow/cfg.expected

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@
77
| ControlFlow.cs:10:9:10:43 | Call (unknown target) | ControlFlow.cs:12:9:12:87 | ...; |
88
| ControlFlow.cs:10:9:10:43 | call to method | ControlFlow.cs:12:9:12:87 | ...; |
99
| ControlFlow.cs:10:9:10:44 | ...; | ControlFlow.cs:10:9:10:13 | Expression |
10-
| ControlFlow.cs:10:22:10:22 | access to local variable v | ControlFlow.cs:10:22:10:24 | Expression |
11-
| ControlFlow.cs:10:22:10:24 | Expression | ControlFlow.cs:10:22:10:26 | Expression |
12-
| ControlFlow.cs:10:22:10:26 | Expression | ControlFlow.cs:10:29:10:42 | "This is true" |
10+
| ControlFlow.cs:10:22:10:22 | access to local variable v | ControlFlow.cs:10:22:10:24 | Call (unknown target) |
11+
| ControlFlow.cs:10:22:10:22 | access to local variable v | ControlFlow.cs:10:22:10:24 | access to property (unknown) |
12+
| ControlFlow.cs:10:22:10:24 | Call (unknown target) | ControlFlow.cs:10:22:10:26 | Call (unknown target) |
13+
| ControlFlow.cs:10:22:10:24 | Call (unknown target) | ControlFlow.cs:10:22:10:26 | access to property (unknown) |
14+
| ControlFlow.cs:10:22:10:24 | access to property (unknown) | ControlFlow.cs:10:22:10:26 | Call (unknown target) |
15+
| ControlFlow.cs:10:22:10:24 | access to property (unknown) | ControlFlow.cs:10:22:10:26 | access to property (unknown) |
16+
| ControlFlow.cs:10:22:10:26 | Call (unknown target) | ControlFlow.cs:10:29:10:42 | "This is true" |
17+
| ControlFlow.cs:10:22:10:26 | access to property (unknown) | ControlFlow.cs:10:29:10:42 | "This is true" |
1318
| ControlFlow.cs:10:29:10:42 | "This is true" | ControlFlow.cs:10:9:10:43 | Call (unknown target) |
1419
| ControlFlow.cs:10:29:10:42 | "This is true" | ControlFlow.cs:10:9:10:43 | call to method |
1520
| ControlFlow.cs:12:9:12:86 | Call (unknown target) | ControlFlow.cs:12:37:12:47 | Expression |
@@ -20,5 +25,7 @@
2025
| ControlFlow.cs:12:51:12:62 | access to field Empty | ControlFlow.cs:12:37:12:62 | ... = ... |
2126
| ControlFlow.cs:12:65:12:75 | Expression | ControlFlow.cs:12:79:12:79 | access to local variable v |
2227
| ControlFlow.cs:12:65:12:84 | ... = ... | ControlFlow.cs:12:35:12:86 | { ..., ... } |
23-
| ControlFlow.cs:12:79:12:79 | access to local variable v | ControlFlow.cs:12:79:12:84 | Expression |
24-
| ControlFlow.cs:12:79:12:84 | Expression | ControlFlow.cs:12:65:12:84 | ... = ... |
28+
| ControlFlow.cs:12:79:12:79 | access to local variable v | ControlFlow.cs:12:79:12:84 | Call (unknown target) |
29+
| ControlFlow.cs:12:79:12:79 | access to local variable v | ControlFlow.cs:12:79:12:84 | access to property (unknown) |
30+
| ControlFlow.cs:12:79:12:84 | Call (unknown target) | ControlFlow.cs:12:65:12:84 | ... = ... |
31+
| ControlFlow.cs:12:79:12:84 | access to property (unknown) | ControlFlow.cs:12:65:12:84 | ... = ... |

csharp/ql/test/library-tests/standalone/errorrecovery/ErrorCalls.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
| errors.cs:43:21:43:28 | errors.cs:43:21:43:28 | object creation of type C1 | C1 |
33
| errors.cs:44:13:44:19 | errors.cs:44:13:44:19 | call to method m1 | m1 |
44
| errors.cs:45:13:45:19 | errors.cs:45:13:45:19 | call to method m2 | m2 |
5-
| errors.cs:46:13:46:38 | errors.cs:46:13:46:38 | call to method | none |
5+
| errors.cs:46:13:46:38 | errors.cs:46:13:46:38 | call to method WriteLine | WriteLine |
66
| errors.cs:53:17:53:25 | errors.cs:53:17:53:25 | object creation of type C2 | none |
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
| regressions.cs:16:13:16:37 | case ...: | regressions.cs:16:18:16:36 | Expression |
2-
| regressions.cs:18:13:18:37 | case ...: | regressions.cs:18:18:18:36 | Expression |
1+
| regressions.cs:16:13:16:37 | case ...: | regressions.cs:16:18:16:36 | access to property (unknown) |
2+
| regressions.cs:18:13:18:37 | case ...: | regressions.cs:18:18:18:36 | access to property (unknown) |
3+
| regressions.cs:20:13:20:23 | case ...: | regressions.cs:20:18:20:22 | Int32 x |

0 commit comments

Comments
 (0)