< Summary

Class:GDX.Developer.ConsoleCommands.ExecConsoleCommand
Assembly:GDX
File(s):./Packages/com.dotbunny.gdx/GDX/Developer/ConsoleCommands/ExecConsoleCommand.cs
Covered lines:3
Uncovered lines:55
Coverable lines:58
Total lines:109
Line coverage:5.1% (3 of 58)
Covered branches:0
Total branches:0
Covered methods:1
Total methods:5
Method coverage:20% (1 of 5)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Evaluate(...)0%30500%
GetKeyword()0%110100%
GetHelpUsage()0%2100%
GetHelpMessage()0%2100%
GetInstance(...)0%42600%

File(s)

./Packages/com.dotbunny.gdx/GDX/Developer/ConsoleCommands/ExecConsoleCommand.cs

#LineLine coverage
 1// Copyright (c) 2020-2022 dotBunny Inc.
 2// dotBunny licenses this file to you under the BSL-1.0 license.
 3// See the LICENSE file in the project root for more information.
 4
 5using System;
 6using System.Collections.Generic;
 7using System.IO;
 8using UnityEngine;
 9
 10namespace GDX.Developer.ConsoleCommands
 11{
 12#if UNITY_2022_2_OR_NEWER
 13    public class ExecConsoleCommand : ConsoleCommandBase
 14    {
 15        string[] m_FilePaths;
 16        int m_FilePathsCount;
 17
 18        /// <inheritdoc />
 19        public override bool Evaluate(float deltaTime)
 020        {
 021            for (int i = 0; i < m_FilePathsCount; i++)
 022            {
 023                string[] lines = File.ReadAllLines(m_FilePaths[i]);
 024                Debug.Log($"Queueing commands found in {m_FilePaths[i]} ...");
 025                int lineCount = lines.Length;
 026                for (int j = 0; j < lineCount; j++)
 027                {
 028                    string line = lines[j].Trim();
 029                    if (line[0] == '#') // Skip comments
 030                    {
 031                        continue;
 32                    }
 33
 034                    if (!Console.QueueCommand(line))
 035                    {
 036                        Debug.LogWarning(
 37                            $"An error occured adding command '{line}' at line #{j} in {m_FilePaths[i]}.");
 038                    }
 039                }
 040            }
 41
 042            return true;
 043        }
 44
 45        /// <inheritdoc />
 46        public override string GetKeyword()
 747        {
 748            return "exec";
 749        }
 50
 51        /// <inheritdoc />
 52        public override string GetHelpUsage()
 053        {
 054            return "exec <absolute path>";
 055        }
 56
 57        /// <inheritdoc />
 58        public override string GetHelpMessage()
 059        {
 060            return "Execute an arbitrary script file based on the known commands of the console.";
 061        }
 62
 63        /// <inheritdoc />
 64        public override ConsoleCommandBase GetInstance(string context)
 065        {
 066            string[] files = context.Split(',', StringSplitOptions.RemoveEmptyEntries);
 067            int fileCount = files.Length;
 068            List<string> foundFiles = new List<string>(fileCount);
 69
 070            for (int i = 0; i < fileCount; i++)
 071            {
 072                string workingFile = files[i];
 073                if (File.Exists(workingFile))
 074                {
 075                    foundFiles.Add(workingFile);
 076                    continue;
 77                }
 78
 079                string dataPath = System.IO.Path.Combine(Application.dataPath, workingFile);
 080                if (File.Exists(dataPath))
 081                {
 082                    foundFiles.Add(dataPath);
 083                    continue;
 84                }
 85
 086                string persistentPath = Path.Combine(Application.persistentDataPath, workingFile);
 087                if (File.Exists(persistentPath))
 088                {
 089                    foundFiles.Add(persistentPath);
 090                    continue;
 91                }
 92
 093                Debug.LogWarning($"Unable to find script to execute @ {workingFile}.");
 094            }
 95
 096            if (foundFiles.Count <= 0)
 097            {
 098                return null;
 99            }
 100
 0101            ExecConsoleCommand command = new ExecConsoleCommand
 102            {
 103                m_FilePaths = foundFiles.ToArray(), m_FilePathsCount = foundFiles.Count
 104            };
 0105            return command;
 0106        }
 107    }
 108#endif // UNITY_2022_2_OR_NEWER
 109}

Coverage by test methods







Methods/Properties

Evaluate(System.Single)
GetKeyword()
GetHelpUsage()
GetHelpMessage()
GetInstance(System.String)