From a7ef9791f816cfc101254f4221dca64795c2aa77 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Tue, 15 Nov 2022 17:37:15 +0100 Subject: [PATCH] [tests] Use a different identifier than '%...%' for replacement text. When the autoformatter runs into the '%...%' pattern in *.cs files, it will re-format the text (to '% ... %'), but that breaks our text replacement logic. So instead use a valid C# identifier as a replacement token, in which case the autoformatter won't confuse our replacement logic. --- tests/common/mac/ApiDefinition.cs | 2 +- tests/common/mac/BindingProjectWithNoTag.csproj | 2 +- tests/common/mac/Component1.fs | 2 +- tests/common/mac/MobileBinding.csproj | 2 +- tests/common/mac/MyClass.cs | 2 +- tests/common/mac/ProjectTestHelpers.cs | 14 +++++++------- tests/common/mac/StructsAndEnums.cs | 2 +- tests/common/mac/SystemMonoExample.csproj | 4 ++-- tests/common/mac/Today/TodayViewController.cs | 2 +- tests/common/mac/UnifiedExample.csproj | 4 ++-- tests/common/mac/UnifiedLibrary.csproj | 2 +- tests/common/mac/XM45Binding.csproj | 2 +- tests/common/mac/XM45Example.csproj | 4 ++-- tests/common/mac/XM45Library.csproj | 2 +- tests/mmptest/src/ExtensionTests.cs | 2 +- tests/mmptest/src/PackageReferenceTests.cs | 2 +- tests/mmptest/src/XM45Example.csproj | 2 +- 17 files changed, 26 insertions(+), 26 deletions(-) diff --git a/tests/common/mac/ApiDefinition.cs b/tests/common/mac/ApiDefinition.cs index 6d4d7073798f..688fcd16ff4f 100644 --- a/tests/common/mac/ApiDefinition.cs +++ b/tests/common/mac/ApiDefinition.cs @@ -63,5 +63,5 @@ namespace ExampleBinding // // For more information, see http://developer.xamarin.com/guides/ios/advanced_topics/binding_objective-c/ // -%CODE% +REPLACE_CODE_REPLACE } diff --git a/tests/common/mac/BindingProjectWithNoTag.csproj b/tests/common/mac/BindingProjectWithNoTag.csproj index 710e2238a5e6..7f9b675e284e 100644 --- a/tests/common/mac/BindingProjectWithNoTag.csproj +++ b/tests/common/mac/BindingProjectWithNoTag.csproj @@ -20,7 +20,7 @@ prompt 4 false -%CODE% +REPLACE_CODE_REPLACE diff --git a/tests/common/mac/Component1.fs b/tests/common/mac/Component1.fs index d23771e44f22..e95030e8022c 100644 --- a/tests/common/mac/Component1.fs +++ b/tests/common/mac/Component1.fs @@ -2,4 +2,4 @@ namespace FSharpXM45Library type Class1() = member this.X = "F#" -%CODE% +REPLACE_CODE_REPLACE diff --git a/tests/common/mac/MobileBinding.csproj b/tests/common/mac/MobileBinding.csproj index 1f4160e48304..3411a890ba93 100644 --- a/tests/common/mac/MobileBinding.csproj +++ b/tests/common/mac/MobileBinding.csproj @@ -22,7 +22,7 @@ prompt 4 false -%CODE% +REPLACE_CODE_REPLACE diff --git a/tests/common/mac/MyClass.cs b/tests/common/mac/MyClass.cs index f64813eaccf0..a2642ca8b81d 100644 --- a/tests/common/mac/MyClass.cs +++ b/tests/common/mac/MyClass.cs @@ -10,4 +10,4 @@ public MyClass () } } -%CODE% +REPLACE_CODE_REPLACE diff --git a/tests/common/mac/ProjectTestHelpers.cs b/tests/common/mac/ProjectTestHelpers.cs index f7101308c03e..834c32340dc3 100644 --- a/tests/common/mac/ProjectTestHelpers.cs +++ b/tests/common/mac/ProjectTestHelpers.cs @@ -239,7 +239,7 @@ public static BuildResult BuildProject (string csprojTarget, bool shouldFail = f static string ProjectTextReplacement (UnifiedTestConfig config, string text) { - text = text.Replace ("%CODE%", config.CSProjConfig) + text = text.Replace ("REPLACE_CODE_REPLACE", config.CSProjConfig) .Replace ("%REFERENCES%", config.References) .Replace ("%REFERENCES_BEFORE_PLATFORM%", config.ReferencesBeforePlatform) .Replace ("%NAME%", config.AssemblyName ?? Path.GetFileNameWithoutExtension (config.ProjectName)) @@ -304,8 +304,8 @@ public static string GenerateEXEProject (UnifiedTestConfig config) public static string GenerateBindingLibraryProject (UnifiedTestConfig config) { string sourceDir = FindSourceDirectory (); - CopyFileWithSubstitutions (Path.Combine (sourceDir, "ApiDefinition.cs"), Path.Combine (config.TmpDir, "ApiDefinition.cs"), text => text.Replace ("%CODE%", config.APIDefinitionConfig)); - CopyFileWithSubstitutions (Path.Combine (sourceDir, "StructsAndEnums.cs"), Path.Combine (config.TmpDir, "StructsAndEnums.cs"), text => text.Replace ("%CODE%", config.StructsAndEnumsConfig)); + CopyFileWithSubstitutions (Path.Combine (sourceDir, "ApiDefinition.cs"), Path.Combine (config.TmpDir, "ApiDefinition.cs"), text => text.Replace ("REPLACE_CODE_REPLACE", config.APIDefinitionConfig)); + CopyFileWithSubstitutions (Path.Combine (sourceDir, "StructsAndEnums.cs"), Path.Combine (config.TmpDir, "StructsAndEnums.cs"), text => text.Replace ("REPLACE_CODE_REPLACE", config.StructsAndEnumsConfig)); string linkWithName = null; if (config.LinkWithName != null) { @@ -331,7 +331,7 @@ public static string GenerateUnifiedLibraryProject (UnifiedTestConfig config) string projectSuffix = config.FSharp ? ".fsproj" : ".csproj"; CopyFileWithSubstitutions (Path.Combine (sourceDir, sourceFileName), Path.Combine (config.TmpDir, sourceFileName), text => { - return text.Replace ("%CODE%", config.TestCode); + return text.Replace ("REPLACE_CODE_REPLACE", config.TestCode); }); return CopyFileWithSubstitutions (Path.Combine (sourceDir, config.ProjectName + projectSuffix), Path.Combine (config.TmpDir, config.ProjectName + projectSuffix), text => { @@ -474,7 +474,7 @@ open AppKit [] let main args = NSApplication.Init () - %CODE% + REPLACE_CODE_REPLACE 0"; const string MainTemplate = @" @@ -490,12 +490,12 @@ class MainClass static void Main (string[] args) { NSApplication.Init (); - %CODE% + REPLACE_CODE_REPLACE } } }"; string currentTemplate = fsharp ? FSharpMainTemplate : MainTemplate; - string testCase = currentTemplate.Replace ("%CODE%", content).Replace ("%DECL%", decl); + string testCase = currentTemplate.Replace ("REPLACE_CODE_REPLACE", content).Replace ("%DECL%", decl); using (StreamWriter s = new StreamWriter (location)) s.Write(testCase); } diff --git a/tests/common/mac/StructsAndEnums.cs b/tests/common/mac/StructsAndEnums.cs index 692aa9485def..015edca2c589 100644 --- a/tests/common/mac/StructsAndEnums.cs +++ b/tests/common/mac/StructsAndEnums.cs @@ -2,5 +2,5 @@ namespace ExampleBinding { - %CODE% + REPLACE_CODE_REPLACE } diff --git a/tests/common/mac/SystemMonoExample.csproj b/tests/common/mac/SystemMonoExample.csproj index 2dcde8a39aec..6c888b497e18 100644 --- a/tests/common/mac/SystemMonoExample.csproj +++ b/tests/common/mac/SystemMonoExample.csproj @@ -24,7 +24,7 @@ false true false -%CODE% +REPLACE_CODE_REPLACE false @@ -34,7 +34,7 @@ 4 false true -%CODE% +REPLACE_CODE_REPLACE diff --git a/tests/common/mac/Today/TodayViewController.cs b/tests/common/mac/Today/TodayViewController.cs index 03c71a120c97..092313c33013 100644 --- a/tests/common/mac/Today/TodayViewController.cs +++ b/tests/common/mac/Today/TodayViewController.cs @@ -17,7 +17,7 @@ public TodayViewController (IntPtr handle) : base (handle) public override void ViewDidLoad () { base.ViewDidLoad (); -%TESTCODE% + REPLACE_CODE_REPLACE // Do any additional setup after loading the view. } diff --git a/tests/common/mac/UnifiedExample.csproj b/tests/common/mac/UnifiedExample.csproj index 5cdbee494550..5ec0b270c2d4 100644 --- a/tests/common/mac/UnifiedExample.csproj +++ b/tests/common/mac/UnifiedExample.csproj @@ -24,7 +24,7 @@ true 4 false -%CODE% +REPLACE_CODE_REPLACE pdbonly @@ -39,7 +39,7 @@ true true SdkOnly -%CODE% +REPLACE_CODE_REPLACE diff --git a/tests/common/mac/UnifiedLibrary.csproj b/tests/common/mac/UnifiedLibrary.csproj index 255cab4f9067..3acac7597a1c 100644 --- a/tests/common/mac/UnifiedLibrary.csproj +++ b/tests/common/mac/UnifiedLibrary.csproj @@ -29,7 +29,7 @@ false false false -%CODE% +REPLACE_CODE_REPLACE diff --git a/tests/common/mac/XM45Binding.csproj b/tests/common/mac/XM45Binding.csproj index fd6c1364dae8..8812c51663c5 100644 --- a/tests/common/mac/XM45Binding.csproj +++ b/tests/common/mac/XM45Binding.csproj @@ -21,7 +21,7 @@ prompt 4 false -%CODE% +REPLACE_CODE_REPLACE diff --git a/tests/common/mac/XM45Example.csproj b/tests/common/mac/XM45Example.csproj index d57eda0c7c71..4dc4b5dc0d33 100644 --- a/tests/common/mac/XM45Example.csproj +++ b/tests/common/mac/XM45Example.csproj @@ -23,7 +23,7 @@ false 4 false -%CODE% +REPLACE_CODE_REPLACE false @@ -35,7 +35,7 @@ false false false -%CODE% +REPLACE_CODE_REPLACE diff --git a/tests/common/mac/XM45Library.csproj b/tests/common/mac/XM45Library.csproj index 89e216250c29..fc5f2ef15510 100644 --- a/tests/common/mac/XM45Library.csproj +++ b/tests/common/mac/XM45Library.csproj @@ -19,7 +19,7 @@ prompt 4 false -%CODE% +REPLACE_CODE_REPLACE diff --git a/tests/mmptest/src/ExtensionTests.cs b/tests/mmptest/src/ExtensionTests.cs index 3c3ea577bf3e..51073c684d5a 100644 --- a/tests/mmptest/src/ExtensionTests.cs +++ b/tests/mmptest/src/ExtensionTests.cs @@ -24,7 +24,7 @@ public void TodayExtension_SmokeTest () string project = Path.Combine (tmpDir, "Today/TodayExtensionTest.csproj"); string main = Path.Combine (tmpDir, "Today/TodayViewController.cs"); TI.CopyFileWithSubstitutions (project, project, s => s.Replace ("%ITEMGROUP%", "")); - TI.CopyFileWithSubstitutions (main, main, s => s.Replace ("%TESTCODE%", "")); + TI.CopyFileWithSubstitutions (main, main, s => s.Replace ("REPLACE_CODE_REPLACE", "")); TI.BuildProject (project); }); } diff --git a/tests/mmptest/src/PackageReferenceTests.cs b/tests/mmptest/src/PackageReferenceTests.cs index dae9b3cc954e..60f5c8bb72ea 100644 --- a/tests/mmptest/src/PackageReferenceTests.cs +++ b/tests/mmptest/src/PackageReferenceTests.cs @@ -64,7 +64,7 @@ public void ExtensionProjectPackageReferencs_Build () string main = Path.Combine (tmpDir, "Today/TodayViewController.cs"); TI.CopyFileWithSubstitutions (project, project, s => s.Replace ("%ITEMGROUP%", PackageReference)); - TI.CopyFileWithSubstitutions (main, main, s => s.Replace ("%TESTCODE%", TestCode)); + TI.CopyFileWithSubstitutions (main, main, s => s.Replace ("REPLACE_CODE_REPLACE", TestCode)); TI.NugetRestore (project); var buildResult = TI.BuildProject (Path.Combine (tmpDir, "Today/TodayExtensionTest.csproj")); diff --git a/tests/mmptest/src/XM45Example.csproj b/tests/mmptest/src/XM45Example.csproj index a471f9b9ab73..14190154dc62 100644 --- a/tests/mmptest/src/XM45Example.csproj +++ b/tests/mmptest/src/XM45Example.csproj @@ -23,7 +23,7 @@ false 4 false -%CODE% +REPLACE_CODE_REPLACE false