示例#1
0
        private string GenerateProfileUnitTestCall(BehaviourTestSuite testSuite, int index, ProfileResult expected,
                                                   Dictionary <string, string> tags, bool invertPriority)
        {
            _skeleton.AddDep("debug_table");
            var parameters = new Dictionary <string, string>();


            var keysToCheck = new List <string>();

            foreach (var(key, value) in tags)
            {
                if (key.StartsWith("#"))
                {
                    parameters[key.TrimStart('#')] = value;
                }

                if (key.StartsWith("_relation:"))
                {
                    keysToCheck.Add(key);
                }
            }


            foreach (var key in keysToCheck)
            {
                var newKey = key.Replace(".", "_");
                if (newKey == key)
                {
                    continue;
                }
                tags[newKey] = tags[key];
                tags.Remove(key);
            }

            foreach (var(paramName, _) in parameters)
            {
                tags.Remove("#" + paramName);
            }

            var expectedPriority = "" + expected.Priority;

            if (invertPriority)
            {
                expectedPriority = $"inv({expectedPriority})";
            }

            // Generates something like:
            // function unit_test_profile(profile_function, profile_name, index, expected, tags)
            return
                ($"unit_test_profile(behaviour_{testSuite.Profile.Name.AsLuaIdentifier()}_{testSuite.BehaviourName.AsLuaIdentifier()}, " +
                 $"\"{testSuite.BehaviourName}\", " +
                 $"{index}, " +
                 $"{{access = \"{D(expected.Access)}\", speed = {expected.Speed}, oneway = \"{D(expected.Oneway)}\", priority = {expectedPriority} }}, " +
                 tags.ToLuaTable() +
                 ")");
        }
示例#2
0
        private static List <(ProfileMetaData profile, List <BehaviourTestSuite> profileTests)> ParseProfiles(
            IEnumerable <string> jsonFiles, IReadOnlyCollection <string> testFiles, Context context, DateTime lastChange)
        {
            var result = new List <(ProfileMetaData profile, List <BehaviourTestSuite> profileTests)>();

            foreach (var jsonFile in jsonFiles)
            {
                try
                {
                    var profile =
                        JsonParser.ProfileFromJson(context, File.ReadAllText(jsonFile), new FileInfo(jsonFile),
                                                   lastChange);
                    if (profile == null)
                    {
                        continue;
                    }

                    profile.SanityCheckProfile(context);

                    var profileTests = new List <BehaviourTestSuite>();
                    foreach (var behaviourName in profile.Behaviours.Keys)
                    {
                        var path = testFiles.FindTest($"{profile.Name}.{behaviourName}.behaviour_test.csv");
                        if (path != null && File.Exists(path))
                        {
                            var test = BehaviourTestSuite.FromString(context, profile, behaviourName,
                                                                     File.ReadAllText(path));
                            profileTests.Add(test);
                        }
                        else
                        {
                            Console.WriteLine($"[{profile.Name}] WARNING: no test found for behaviour {behaviourName}");
                        }
                    }

                    result.Add((profile, profileTests));
                }
                catch (Exception e)
                {
                    // PrintError(jsonFile, e);
                    throw new Exception("In the file " + jsonFile, e);
                }
            }

            return(result);
        }
示例#3
0
 private string GenerateProfileTestSuite(BehaviourTestSuite testSuite, bool invertPriority)
 {
     return(string.Join("\n",
                        testSuite.Tests.Select((test, i) => GenerateProfileUnitTestCall(testSuite, i, test.Item1, test.tags, invertPriority))
                        .ToList()));
 }