Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 5.6k
Expand file tree
/
Copy pathExecutorTests.cs
More file actions
Latest commit
130 lines (108 loc) · 5.23 KB
/
Copy pathExecutorTests.cs
File metadata and controls
130 lines (108 loc) · 5.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
usingSystem.Diagnostics;
usingSystem.IO;
usingSystem.Linq;
usingMicrosoft.DotNet.RemoteExecutor;
usingXunit;
namespaceSystem.CodeDom.Compiler.Tests
{
publicclassExecutorTests:FileCleanupTestBase
{
privatestaticreadonlystrings_cmd=PlatformDetection.IsWindows?"ipconfig":"printenv";// arbitrary commands to validate output
[SkipOnTargetFramework(~TargetFrameworkMonikers.Netcoreapp,"Not supported on .NET Core")]
[Fact]
publicvoidImpersonation_Unsupported_Throws()
{
stringoutputName=null,errorName=null;
Assert.Throws<PlatformNotSupportedException>(()=>Executor.ExecWaitWithCapture((IntPtr)1,null,null,refoutputName,referrorName));
Assert.Throws<PlatformNotSupportedException>(()=>Executor.ExecWaitWithCapture((IntPtr)1,null,null,null,refoutputName,referrorName));
}
[Fact]
publicvoidNullTempFileCollection_Required_Throws()
{
stringoutputName=null,errorName=null;
Assert.Throws<NullReferenceException>(()=>Executor.ExecWaitWithCapture("",null,refoutputName,referrorName));
}
// NOTE: RemoteInvoke is used because Executor creates inheritable files, which causes a problem
// for the tests if other tests run concurrently and launch child processes, as those child
// processes may then extend the lifetime of the opened files, leading to sharing errors in tests.
[ConditionalFact(typeof(RemoteExecutor),nameof(RemoteExecutor.IsSupported))]
publicvoidExecWait_OutputCaptured()
{
RemoteExecutor.Invoke(()=>
{
using(vartfc=newTempFileCollection(TestDirectory))
{
Executor.ExecWait(s_cmd,tfc);
Assert.Equal(3,tfc.Count);
Assert.NotEmpty(File.ReadAllText(tfc.BasePath+".out"));
Assert.Empty(File.ReadAllText(tfc.BasePath+".err"));
}
}).Dispose();
}
[ConditionalFact(typeof(RemoteExecutor),nameof(RemoteExecutor.IsSupported))]
publicvoidExecWaitWithCapture_NullNames_OutputCaptured()
{
RemoteExecutor.Invoke(()=>
{
using(vartfc=newTempFileCollection())
{
stringoutputName=null,errorName=null;
Assert.Equal(0,Executor.ExecWaitWithCapture(s_cmd,tfc,refoutputName,referrorName));
Assert.Equal(3,tfc.Count);
Assert.NotEmpty(outputName);
Assert.NotEmpty(errorName);
Assert.Contains(outputName,tfc.Cast<string>());
Assert.Contains(errorName,tfc.Cast<string>());
Assert.NotEmpty(File.ReadAllText(outputName));
Assert.Empty(File.ReadAllText(errorName));
}
}).Dispose();
}
[ConditionalFact(typeof(RemoteExecutor),nameof(RemoteExecutor.IsSupported))]
publicvoidExecWaitWithCapture_SpecifiedNames_OutputCaptured()
{
RemoteExecutor.Invoke(()=>
{
using(vartfc=newTempFileCollection())
{
stringoutputName=GetTestFilePath();
stringerrorName=GetTestFilePath();
Assert.Equal(0,Executor.ExecWaitWithCapture(s_cmd,tfc,refoutputName,referrorName));
Assert.Equal(0,tfc.Count);
Assert.NotEmpty(File.ReadAllText(outputName));
Assert.Empty(File.ReadAllText(errorName));
}
}).Dispose();
}
[ConditionalFact(typeof(RemoteExecutor),nameof(RemoteExecutor.IsSupported))]
publicvoidExecWaitWithCapture_CurrentDirectorySpecified_OutputIncludesSpecifiedDirectory()
{
RemoteExecutor.Invoke(()=>
{
using(vartfc=newTempFileCollection(TestDirectory))
{
stringoutputName=GetTestFilePath();
stringerrorName=GetTestFilePath();
Assert.Equal(0,Executor.ExecWaitWithCapture(s_cmd,TestDirectory,tfc,refoutputName,referrorName));
Assert.Contains(TestDirectory,File.ReadAllText(outputName));
}
}).Dispose();
}
[ConditionalFact(typeof(RemoteExecutor),nameof(RemoteExecutor.IsSupported))]
publicvoidExecWaitWithCapture_OutputIncludesCurrentDirectory()
{
RemoteExecutor.Invoke(()=>
{
using(vartfc=newTempFileCollection(TestDirectory))
{
stringoutputName=GetTestFilePath();
stringerrorName=GetTestFilePath();
Assert.Equal(0,Executor.ExecWaitWithCapture(s_cmd,tfc,refoutputName,referrorName));
Assert.Contains(Environment.CurrentDirectory,File.ReadAllText(outputName));
}
}).Dispose();
}
}
}