Skip to content

Commit df482a9

Browse files
authored
Merge pull request #7314 from michaelnebel/csharp-stubs-dataflow-global
C#: Update tests dataflow/global tests to use stubs.
2 parents 8bba3eb + 69f42b9 commit df482a9

File tree

9 files changed

+62
-432
lines changed

9 files changed

+62
-432
lines changed

csharp/ql/lib/csharp.qll

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,5 @@
22
* The default C# QL library.
33
*/
44

5-
import Customizations
6-
import semmle.code.csharp.Attribute
7-
import semmle.code.csharp.Callable
8-
import semmle.code.csharp.Comments
9-
import semmle.code.csharp.Element
10-
import semmle.code.csharp.Event
11-
import semmle.code.csharp.File
12-
import semmle.code.csharp.Generics
13-
import semmle.code.csharp.Location
14-
import semmle.code.csharp.Member
15-
import semmle.code.csharp.Namespace
16-
import semmle.code.csharp.AnnotatedType
17-
import semmle.code.csharp.Property
18-
import semmle.code.csharp.Stmt
19-
import semmle.code.csharp.Type
20-
import semmle.code.csharp.Using
21-
import semmle.code.csharp.Variable
22-
import semmle.code.csharp.XML
23-
import semmle.code.csharp.Preprocessor
24-
import semmle.code.csharp.exprs.Access
25-
import semmle.code.csharp.exprs.ArithmeticOperation
26-
import semmle.code.csharp.exprs.Assignment
27-
import semmle.code.csharp.exprs.BitwiseOperation
28-
import semmle.code.csharp.exprs.Call
29-
import semmle.code.csharp.exprs.ComparisonOperation
30-
import semmle.code.csharp.exprs.Creation
31-
import semmle.code.csharp.exprs.Dynamic
32-
import semmle.code.csharp.exprs.Expr
33-
import semmle.code.csharp.exprs.Literal
34-
import semmle.code.csharp.exprs.LogicalOperation
35-
import semmle.code.csharp.controlflow.ControlFlowGraph
36-
import semmle.code.csharp.dataflow.DataFlow
37-
import semmle.code.csharp.dataflow.TaintTracking
38-
import semmle.code.csharp.dataflow.SSA
39-
40-
/** Whether the source was extracted without a build command. */
41-
predicate extractionIsStandalone() { exists(SourceFile f | f.extractedStandalone()) }
5+
// Do not add other imports here; add to `semmle.code.csharp.internal.csharp` instead
6+
import semmle.code.csharp.internal.csharp
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* The default C# QL library.
3+
*/
4+
5+
import Customizations
6+
import semmle.code.csharp.Attribute
7+
import semmle.code.csharp.Callable
8+
import semmle.code.csharp.Comments
9+
import semmle.code.csharp.Element
10+
import semmle.code.csharp.Event
11+
import semmle.code.csharp.File
12+
import semmle.code.csharp.Generics
13+
import semmle.code.csharp.Location
14+
import semmle.code.csharp.Member
15+
import semmle.code.csharp.Namespace
16+
import semmle.code.csharp.AnnotatedType
17+
import semmle.code.csharp.Property
18+
import semmle.code.csharp.Stmt
19+
import semmle.code.csharp.Type
20+
import semmle.code.csharp.Using
21+
import semmle.code.csharp.Variable
22+
import semmle.code.csharp.XML
23+
import semmle.code.csharp.Preprocessor
24+
import semmle.code.csharp.exprs.Access
25+
import semmle.code.csharp.exprs.ArithmeticOperation
26+
import semmle.code.csharp.exprs.Assignment
27+
import semmle.code.csharp.exprs.BitwiseOperation
28+
import semmle.code.csharp.exprs.Call
29+
import semmle.code.csharp.exprs.ComparisonOperation
30+
import semmle.code.csharp.exprs.Creation
31+
import semmle.code.csharp.exprs.Dynamic
32+
import semmle.code.csharp.exprs.Expr
33+
import semmle.code.csharp.exprs.Literal
34+
import semmle.code.csharp.exprs.LogicalOperation
35+
import semmle.code.csharp.controlflow.ControlFlowGraph
36+
import semmle.code.csharp.dataflow.DataFlow
37+
import semmle.code.csharp.dataflow.TaintTracking
38+
import semmle.code.csharp.dataflow.SSA
39+
40+
/** Whether the source was extracted without a build command. */
41+
predicate extractionIsStandalone() { exists(SourceFile f | f.extractedStandalone()) }

csharp/ql/test/csharp.qll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* The default C# QL library.
3+
*/
4+
5+
import semmle.code.csharp.internal.csharp
6+
7+
private class FileAdjusted extends File {
8+
override predicate fromSource() {
9+
super.fromSource() and
10+
not this.getAbsolutePath().matches("%resources/stubs/%")
11+
}
12+
}

csharp/ql/test/library-tests/dataflow/global/GetAnOutNode.expected

Lines changed: 0 additions & 148 deletions
Large diffs are not rendered by default.

csharp/ql/test/library-tests/dataflow/global/GetAnOutNode.ql

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,10 @@ private class DataFlowCallAdjusted extends TDataFlowCall {
1313
}
1414
}
1515

16-
private class NodeAdjusted extends TNode {
17-
string toString() { result = this.(DataFlow::Node).toString() }
18-
19-
Location getLocation() {
20-
exists(Location l |
21-
l = this.(DataFlow::Node).getLocation() and
22-
if l instanceof SourceLocation then result = l else result instanceof EmptyLocation
23-
)
24-
}
16+
private class SourceNode extends DataFlow::Node {
17+
SourceNode() { this.getLocation().getFile().fromSource() }
2518
}
2619

27-
from DataFlowCallAdjusted call, NodeAdjusted n, ReturnKind kind
20+
from DataFlowCallAdjusted call, SourceNode n, ReturnKind kind
2821
where n = getAnOutNode(call, kind)
2922
select call, kind, n
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
semmle-extractor-options: /r:System.Diagnostics.Process.dll /r:System.Linq.dll /r:System.Linq.Expressions.dll /r:System.Linq.Queryable.dll /r:System.ComponentModel.Primitives.dll
1+
semmle-extractor-options: /nostdlib /noconfig
2+
semmle-extractor-options: --load-sources-from-project:${testdir}/../../../resources/stubs/Newtonsoft.Json/13.0.1/Newtonsoft.Json.csproj
3+
semmle-extractor-options: ${testdir}/../../../resources/stubs/System.Web.cs

csharp/ql/test/library-tests/frameworks/EntityFramework/Dataflow.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ edges
8484
| EntityFramework.cs:219:18:219:54 | call to method First<Address> [property Street] : String | EntityFramework.cs:219:18:219:61 | access to property Street |
8585
| EntityFrameworkCore.cs:75:31:75:39 | "tainted" : String | EntityFrameworkCore.cs:76:18:76:28 | access to local variable taintSource |
8686
| EntityFrameworkCore.cs:75:31:75:39 | "tainted" : String | EntityFrameworkCore.cs:77:35:77:45 | access to local variable taintSource : String |
87+
| EntityFrameworkCore.cs:75:31:75:39 | "tainted" : String | EntityFrameworkCore.cs:78:18:78:42 | (...) ... |
8788
| EntityFrameworkCore.cs:75:31:75:39 | "tainted" : String | EntityFrameworkCore.cs:78:32:78:42 | access to local variable taintSource : String |
8889
| EntityFrameworkCore.cs:77:18:77:46 | object creation of type RawSqlString : RawSqlString | EntityFrameworkCore.cs:77:18:77:46 | (...) ... |
8990
| EntityFrameworkCore.cs:77:35:77:45 | access to local variable taintSource : String | EntityFrameworkCore.cs:77:18:77:46 | object creation of type RawSqlString : RawSqlString |

csharp/ql/test/library-tests/frameworks/test/Assertions.expected

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
assertTrue
2-
| ../../../resources/stubs/Microsoft.VisualStudio.TestTools.UnitTesting.cs:9:28:9:33 | IsTrue | ../../../resources/stubs/Microsoft.VisualStudio.TestTools.UnitTesting.cs:9:40:9:40 | b |
32
| DoesNotReturnIf.cs:8:22:8:31 | AssertTrue | DoesNotReturnIf.cs:8:95:8:103 | condition |
43
| DoesNotReturnIf.cs:16:22:16:32 | AssertTrue2 | DoesNotReturnIf.cs:17:75:17:84 | condition1 |
54
| DoesNotReturnIf.cs:16:22:16:32 | AssertTrue2 | DoesNotReturnIf.cs:18:75:18:84 | condition2 |
@@ -11,20 +10,17 @@ assertTrue
1110
| nunit.cs:53:21:53:24 | That | nunit.cs:53:31:53:39 | condition |
1211
| nunit.cs:54:21:54:24 | That | nunit.cs:54:31:54:39 | condition |
1312
assertFalse
14-
| ../../../resources/stubs/Microsoft.VisualStudio.TestTools.UnitTesting.cs:10:28:10:34 | IsFalse | ../../../resources/stubs/Microsoft.VisualStudio.TestTools.UnitTesting.cs:10:41:10:41 | b |
1513
| DoesNotReturnIf.cs:12:22:12:32 | AssertFalse | DoesNotReturnIf.cs:12:95:12:103 | condition |
1614
| nunit.cs:34:21:34:25 | False | nunit.cs:34:32:34:40 | condition |
1715
| nunit.cs:35:21:35:25 | False | nunit.cs:35:32:35:40 | condition |
1816
| nunit.cs:37:21:37:27 | IsFalse | nunit.cs:37:34:37:42 | condition |
1917
| nunit.cs:38:21:38:27 | IsFalse | nunit.cs:38:34:38:42 | condition |
2018
assertNull
21-
| ../../../resources/stubs/Microsoft.VisualStudio.TestTools.UnitTesting.cs:7:28:7:33 | IsNull | ../../../resources/stubs/Microsoft.VisualStudio.TestTools.UnitTesting.cs:7:42:7:42 | o |
2219
| nunit.cs:40:21:40:24 | Null | nunit.cs:40:33:40:40 | anObject |
2320
| nunit.cs:41:21:41:24 | Null | nunit.cs:41:33:41:40 | anObject |
2421
| nunit.cs:43:21:43:26 | IsNull | nunit.cs:43:35:43:42 | anObject |
2522
| nunit.cs:44:21:44:26 | IsNull | nunit.cs:44:35:44:42 | anObject |
2623
assertNonNull
27-
| ../../../resources/stubs/Microsoft.VisualStudio.TestTools.UnitTesting.cs:8:28:8:36 | IsNotNull | ../../../resources/stubs/Microsoft.VisualStudio.TestTools.UnitTesting.cs:8:45:8:45 | o |
2824
| nunit.cs:46:21:46:27 | NotNull | nunit.cs:46:36:46:43 | anObject |
2925
| nunit.cs:47:21:47:27 | NotNull | nunit.cs:47:36:47:43 | anObject |
3026
| nunit.cs:49:21:49:29 | IsNotNull | nunit.cs:49:38:49:45 | anObject |

0 commit comments

Comments
 (0)