forked from grofit/unity-rx-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
104 lines (97 loc) · 6.11 KB
/
gulpfile.js
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
const { src, dest, parallel } = require("gulp");
const replace = require("gulp-replace");
const filter = require("gulp-filter");
const print = require('gulp-print').default;
const path = require('path');
class Tasks {
patchRxMainCsProj() {
return src("../reactive/Rx.NET/Source/src/System.Reactive/System.Reactive.csproj")
.pipe(replace("<TargetFrameworks>netcoreapp3.1;netstandard2.0;net472;uap10.0.16299;net5.0;net5.0-windows10.0.19041</TargetFrameworks>", "<TargetFramework>netstandard2.0</TargetFramework><LangVersion>9</LangVersion><DefineConstants>NO_NULLABLE_ATTRIBUTES</DefineConstants>"))
.pipe(replace("<SignAssembly>true</SignAssembly>", "<SignAssembly>false</SignAssembly>"))
.pipe(dest((file) => file.base));
}
patchRxRemoveUnsupportedFeatures() {
return src("../reactive/Rx.NET/Source/src/System.Reactive/TaskObservable.cs")
.pipe(replace("[AsyncMethodBuilder(typeof(TaskObservableMethodBuilder<>))]", ""))
.pipe(replace("<SignAssembly>true</SignAssembly>", "<SignAssembly>false</SignAssembly>"))
.pipe(dest((file) => file.base));
}
testCode() {
const threadPoolSchedulerReplacementFilter = filter([
"**",
"!Tests/Concurrency/SchedulerTest.cs",
"!Tests/Concurrency/ThreadPoolSchedulerTest.cs",
], {restore: true});
return this.xunit2nunitTransformer(src("./**/*.cs", {
cwd: path.join(__dirname, "../reactive/Rx.NET/Source/tests/Tests.System.Reactive"),
ignore: [
"Tests/Internal/HalfSerializerTest.cs",
"Tests/LicenseHeaderTest.cs",
"Tests/ArgumentValidationTest.cs",
"Tests/Aliases.cs",
"Tests/AliasesTest.cs",
"Tests/TaskLikeSupportTest.cs",
"Tests/Linq/ObservableRemotingTest.cs",
"Tests/Linq/ObservableSafetyTest.cs",
"Tests/Linq/QbservableTest.cs",
"Tests/Linq/QbservableExTest.cs",
"obj/**/*.cs"
],
nocase: true
})
.pipe(print(filepath => `built: ${filepath}`)))
.pipe(threadPoolSchedulerReplacementFilter)
.pipe(replace("ThreadPoolScheduler.Instance", "Rx.Unity.Concurrency.ThreadPoolOnlyScheduler.Instance"))
.pipe(threadPoolSchedulerReplacementFilter.restore)
.pipe(replace("public class ", "public partial class "))
.pipe(replace("public void ForEachAsync_DisposeThrows()", "private void ForEachAsync_DisposeThrows()")) // sort of a workaround (as [Trait("SkipCI", "true")] isn't ignored)
.pipe(replace("public void Virtual_ThreadSafety()", "private void Virtual_ThreadSafety()")) // sort of a workaround (as [Trait("SkipCI", "true")] isn't ignored)
.pipe(replace("public void Generate_LongRunning1()", "private void Generate_LongRunning1()")) // TestLongRunningScheduler causes issues with IL2CPP
.pipe(replace("public void Generate_LongRunning2()", "private void Generate_LongRunning2()")) // TestLongRunningScheduler causes issues with IL2CPP
.pipe(replace("public void Repeat_Inf_LongRunning()", "private void Repeat_Inf_LongRunning()")) // TestLongRunningScheduler causes issues with IL2CPP
.pipe(replace("public void ObserveOn_LongRunning_SameThread()", "private void ObserveOn_LongRunning_SameThread()")) // TaskPoolScheduler isn't supported when used with IL2CPP
.pipe(replace("public void ObserveOn_LongRunning_DisableOptimizations()", "private void ObserveOn_LongRunning_DisableOptimizations()")) // TaskPoolScheduler isn't supported when used with IL2CPP
.pipe(replace("public void EnumerableToObservable_LongRunning_Dispose()", "private void EnumerableToObservable_LongRunning_Dispose()")) // TestLongRunningScheduler causes issues with IL2CPP
.pipe(replace("public void EnumerableToObservable_LongRunning_Error()", "private void EnumerableToObservable_LongRunning_Error()")) // TestLongRunningScheduler causes issues with IL2CPP
.pipe(dest(path.join(__dirname, "../Tests/Tests.System.Reactive")));
}
testingLibCode() {
return this.xunit2nunitTransformer(src("**/*.cs", {
cwd: path.join(__dirname, "../reactive/Rx.NET/Source/src/Microsoft.Reactive.Testing"),
ignore: [
"obj/**/*.cs",
"Properties/AssemblyInfo.cs"
],
nocase: true
}))
.pipe(print(filepath => `built: ${filepath}`))
.pipe(replace("public class ReactiveTest", "public partial class ReactiveTest")) // just so we can log some infos
.pipe(dest(path.join(__dirname, "../Tests/Microsoft.Reactive.Testing")));
}
rxDataTestCode() {
return src("**/*.cs", {
cwd: path.join(__dirname, "../Rx.Data/src/Rx.Data.Tests"),
ignores: "obj/**/*.cs",
nocase: true
})
.pipe(print(filepath => `built: ${filepath}`))
.pipe(dest(path.join(__dirname, "../Tests/Rx.Data.Tests")));
}
xunit2nunitTransformer(source) {
return source
.pipe(replace("using Xunit;", "using NUnit.Framework;\r\nusing Rx.Unity.Tests.Helper;"))
.pipe(replace("Assert.Equal(", "XunitAssert.Equal("))
.pipe(replace("Assert.NotEqual(", "XunitAssert.NotEqual("))
.pipe(replace("Assert.IsType<", "XunitAssert.IsType<"))
.pipe(replace("Assert.IsType(", "XunitAssert.IsType("))
.pipe(replace("Assert.Same(", "Assert.AreSame("))
.pipe(replace("Assert.NotSame(", "Assert.AreNotSame("))
.pipe(replace("Assert.Empty(", "CollectionAssert.IsEmpty("))
.pipe(replace(/\[Fact([^\]]+)?\]/g, "[Test]"))
.pipe(replace(/\[Trait\([^\(]*\)\]/g, "// $&"))
.pipe(replace(/\[Test[^.\w]([^\(]+(?<=\sasync\s)[^\(]+\s{1,}(\w+)\s{0,}\()/gm, "[Test]\r\n public void $2_Sync() => $2().Wait();\r\n$1"));
}
}
const tasks = new Tasks();
exports.generateRxProj = parallel(() => tasks.patchRxMainCsProj(), () => tasks.patchRxRemoveUnsupportedFeatures());
exports.generateTests = parallel(() => tasks.testCode(), () => tasks.testingLibCode(), () => tasks.rxDataTestCode());