public void TestParamDisambiguation() { string[] args = "-f 1 -fo 2 -foo 3".Split(' '); var dest = new CommandTestObj(); CmdLineArg[] Arguments = new CmdLineArg[] { new CmdLineArg() { Flag = "f", DataType = typeof(int), PropertyName = "f" }, new CmdLineArg() { Flag = "fo", DataType = typeof(int), PropertyName = "fo" }, new CmdLineArg() { Flag = "foo", DataType = typeof(int), PropertyName = "foo" }, }; CmdLineJobBase cmds = new CmdLineJobBase(); Assert.IsTrue(cmds.Load(args, Arguments, dest), "Load failed!"); Assert.AreEqual(1, dest.f, "failed on 'f'"); Assert.AreEqual(2, dest.fo, "failed on 'fo'"); Assert.AreEqual(3, dest.foo, "failed on 'foo'"); }
public void TestTypeConversion() { string[] args = "-string abcdef ghijklmno pqrstuvwxyz -double 3.14159265359 -int 8".Split(' '); var dest = new CommandTestObj(); CmdLineArg[] Arguments = new CmdLineArg[] { new CmdLineArg() { Flag = "string", DataType = typeof(string), PropertyName = "str" }, new CmdLineArg() { Flag = "double", DataType = typeof(double), PropertyName = "dbl" }, new CmdLineArg() { Flag = "int", DataType = typeof(int), PropertyName = "it" }, }; CmdLineJobBase cmds = new CmdLineJobBase(); Assert.IsTrue(cmds.Load(args, Arguments, dest), "Load failed!"); Assert.AreEqual("abcdef ghijklmno pqrstuvwxyz", dest.str, "failed on string with spaces"); Assert.AreEqual(3.14159265359, dest.dbl, "failed on double parsing"); Assert.AreEqual(8, dest.it, "failed on integer parsing"); }
/// <summary> /// Reads a config hierarchy (or retrieve it from the cache) /// </summary> /// <param name="Type">The type of hierarchy to read</param> /// <param name="ProjectDir">The project directory to read the hierarchy for</param> /// <param name="Platform">Which platform to read platform-specific config files for</param> /// <param name="GeneratedConfigDir">Base directory for generated configs</param> /// <returns>The requested config hierarchy</returns> public static ConfigHierarchy ReadHierarchy(ConfigHierarchyType Type, DirectoryReference ProjectDir, UnrealTargetPlatform Platform, DirectoryReference GeneratedConfigDir = null) { // Get the key to use for the cache. It cannot be null, so we use the engine directory if a project directory is not given. ConfigHierarchyKey Key = new ConfigHierarchyKey(Type, ProjectDir, Platform); // Try to get the cached hierarchy with this key ConfigHierarchy Hierarchy; if (!HierarchyKeyToHierarchy.TryGetValue(Key, out Hierarchy)) { List <ConfigFile> Files = new List <ConfigFile>(); foreach (FileReference IniFileName in ConfigHierarchy.EnumerateConfigFileLocations(Type, ProjectDir, Platform)) { ConfigFile File; if (TryReadFile(IniFileName, out File)) { Files.Add(File); } } // If we haven't been given a generated project dir, but we do have a project then the generated configs // should go into ProjectDir/Saved if (GeneratedConfigDir == null && ProjectDir != null) { GeneratedConfigDir = DirectoryReference.Combine(ProjectDir, "Saved"); } if (GeneratedConfigDir != null) { // We know where the generated version of this config file lives, so we can read it back in // and include any user settings from there in our hierarchy string BaseIniName = Enum.GetName(typeof(ConfigHierarchyType), Type); string PlatformName = ConfigHierarchy.GetIniPlatformName(Platform); FileReference DestinationIniFilename = FileReference.Combine(GeneratedConfigDir, "Config", PlatformName, BaseIniName + ".ini"); ConfigFile File; if (TryReadFile(DestinationIniFilename, out File)) { Files.Add(File); } } // Handle command line overrides string[] CmdLine = Environment.GetCommandLineArgs(); string IniConfigArgPrefix = "-ini:" + Enum.GetName(typeof(ConfigHierarchyType), Type) + ":"; foreach (string CmdLineArg in CmdLine) { if (CmdLineArg.StartsWith(IniConfigArgPrefix)) { ConfigFile OverrideFile = new ConfigFile(CmdLineArg.Substring(IniConfigArgPrefix.Length)); Files.Add(OverrideFile); } } Hierarchy = new ConfigHierarchy(Files); HierarchyKeyToHierarchy.Add(Key, Hierarchy); } return(Hierarchy); }
public void ParseTest() { string[] args = { "-Slot", "1", "-eden", "zhong", "eden", "zhong", "--hello", "my friend", "micro=soft" }; CmdArgs a = CmdLineArg.Parse(args); Assert.AreEqual(a.ArgPairs.Count, 4); Assert.AreEqual(a.ArgPairs["Slot"], "1"); Assert.AreEqual(a.ArgPairs["eden"], "zhong"); Assert.AreEqual(a.ArgPairs["hello"], "my friend"); Assert.AreEqual(a.ArgPairs["micro"], "soft"); Assert.AreEqual(a.Args.Count, 2); Assert.AreEqual(a.Args[0], "eden"); Assert.AreEqual(a.Args[1], "zhong"); }
/// <summary> /// Reads a config hierarchy (or retrieve it from the cache) /// </summary> /// <param name="Type">The type of hierarchy to read</param> /// <param name="ProjectDir">The project directory to read the hierarchy for</param> /// <param name="Platform">Which platform to read platform-specific config files for</param> /// <returns>The requested config hierarchy</returns> public static ConfigHierarchy ReadHierarchy(ConfigHierarchyType Type, DirectoryReference ProjectDir, UnrealTargetPlatform Platform) { // Get the key to use for the cache. It cannot be null, so we use the engine directory if a project directory is not given. ConfigHierarchyKey Key = new ConfigHierarchyKey(Type, ProjectDir, Platform); // Try to get the cached hierarchy with this key ConfigHierarchy Hierarchy; lock (HierarchyKeyToHierarchy) { if (!HierarchyKeyToHierarchy.TryGetValue(Key, out Hierarchy)) { // Find all the input files List <ConfigFile> Files = new List <ConfigFile>(); foreach (FileReference IniFileName in ConfigHierarchy.EnumerateConfigFileLocations(Type, ProjectDir, Platform)) { ConfigFile File; if (TryReadFile(IniFileName, out File)) { Files.Add(File); } } // Handle command line overrides string[] CmdLine = Environment.GetCommandLineArgs(); string IniConfigArgPrefix = "-ini:" + Enum.GetName(typeof(ConfigHierarchyType), Type) + ":"; foreach (string CmdLineArg in CmdLine) { if (CmdLineArg.StartsWith(IniConfigArgPrefix)) { ConfigFile OverrideFile = new ConfigFile(CmdLineArg.Substring(IniConfigArgPrefix.Length)); Files.Add(OverrideFile); } } // Create the hierarchy Hierarchy = new ConfigHierarchy(Files); HierarchyKeyToHierarchy.Add(Key, Hierarchy); } } return(Hierarchy); }
/// <summary> /// Whether a host can use its system sdk for this platform /// </summary> public virtual bool ForceUseSystemCompiler() { // by default tools chains don't parse arguments, but we want to be able to check the -bForceUseSystemCompiler flag. if (bForceUseSystemCompiler == -1) { bForceUseSystemCompiler = 0; string[] CmdLine = Environment.GetCommandLineArgs(); foreach (string CmdLineArg in CmdLine) { if (CmdLineArg.Equals("-ForceUseSystemCompiler", StringComparison.OrdinalIgnoreCase)) { bForceUseSystemCompiler = 1; break; } } } return(bForceUseSystemCompiler == 1); }
public void TestInvalidArguments() { string[] args = "-realarg abcde -realagr defghi ".Split(' '); var dest = new CommandTestObj(); CmdLineArg[] Arguments = new CmdLineArg[] { new CmdLineArg() { Flag = "realarg", DataType = typeof(string), PropertyName = "somefile" } }; CmdLineJobBase cmds = new CmdLineJobBase(); bool loadDidFail = cmds.Load(args, Arguments, dest); //switched this, nunit was being weird Assert.IsTrue(loadDidFail == false, "Load Succeeded???"); //assert should pass, load should fail }
public void TestQuotesInArguments() { string[] args = "-somefile \"C:\\terrible path\\with spaces\\in-it\\terrible_filename.txt\" -another param ".Split(' '); var dest = new CommandTestObj(); CmdLineArg[] Arguments = new CmdLineArg[] { new CmdLineArg() { Flag = "somefile", DataType = typeof(string), PropertyName = "somefile" }, new CmdLineArg() { Flag = "another", DataType = typeof(string), PropertyName = "another" } }; CmdLineJobBase cmds = new CmdLineJobBase(); Assert.IsTrue(cmds.Load(args, Arguments, dest), "Load failed!"); Assert.AreEqual("param", dest.another, "parameter after filename with hypens was clobbered"); Assert.AreEqual("C:\\terrible path\\with spaces\\in-it\\terrible_filename.txt", dest.somefile, "failed on filename with quotes"); }