Skip to content

Commit b9e07c4

Browse files
Merge pull request #8 from MrUnbelievable92/1.0.10
v1.0.10
2 parents 2d42bdb + cf004d9 commit b9e07c4

File tree

7 files changed

+33
-29
lines changed

7 files changed

+33
-29
lines changed

AssemblyInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
[assembly: AssemblyConfiguration("")]
1010
[assembly: AssemblyCompany("")]
1111
[assembly: AssemblyProduct("C Sharp Dev Tools")]
12-
[assembly: AssemblyCopyright("Copyright � 2020 - 2023 Maximilian Kalimon")]
12+
[assembly: AssemblyCopyright("Copyright � 2020 - 2024 Maximilian Kalimon")]
1313
[assembly: AssemblyTrademark("")]
1414
[assembly: AssemblyCulture("")]
1515

@@ -29,5 +29,5 @@
2929
// Revision
3030
//
3131
//
32-
[assembly: AssemblyVersion("1.0.9")]
33-
[assembly: AssemblyFileVersion("1.0.9")]
32+
[assembly: AssemblyVersion("1.0.10")]
33+
[assembly: AssemblyFileVersion("1.0.10")]

Assert.Group.cs

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ internal GroupAttribute(string publicName)
4444

4545
internal string FileContent { get; private set; }
4646
internal string PublicName { get; private set; }
47+
4748
internal static Assert.GroupAttribute[] Defines => new Assert.GroupAttribute[]
4849
{
4950
new Assert.GroupAttribute{ FileContent = __FILE__BOOLEAN_CONDITION_CHECKS, PublicName = __NAME__BOOLEAN_CONDITION_CHECKS },
@@ -54,23 +55,28 @@ internal GroupAttribute(string publicName)
5455
new Assert.GroupAttribute{ FileContent = __FILE__ARITHMETIC_LOGIC_CHECKS, PublicName = __NAME__ARITHMETIC_LOGIC_CHECKS },
5556
new Assert.GroupAttribute{ FileContent = __FILE__MEMORY_CHECKS, PublicName = __NAME__MEMORY_CHECKS }
5657
};
58+
private static string[] KnownUsingsWithAssertClasses => new string[]
59+
{
60+
"using NUnit.Framework;",
61+
"using UnityEngine.Assertions",
62+
"using static System.Diagnostics.Debug;"
63+
};
5764

58-
internal static async Task<Dictionary<Assert.GroupAttribute, ulong>> CountMethodCallsAsync(string projectPath)
65+
internal static async Task<Dictionary<Assert.GroupAttribute, uint>> CountMethodCallsAsync(string projectPath)
5966
{
6067
try
6168
{
6269
Dictionary<MethodInfo, Assert.GroupAttribute> methodToGroupMap = GetAssertionsMappedToGroups();
63-
List<Task<Dictionary<Assert.GroupAttribute, ulong>>> jobs = CreateCountingTasks(methodToGroupMap, projectPath);
70+
List<Task<Dictionary<Assert.GroupAttribute, uint>>> jobs = CreateCountingTasks(methodToGroupMap, projectPath);
6471

65-
return await CombineResults(jobs, methodToGroupMap);
72+
return await CombineResults(jobs);
6673
}
6774
catch (Exception ex)
6875
{
6976
ex.Log();
7077
return null;
7178
}
7279
}
73-
7480
private static bool ContainsOverload(Dictionary<MethodInfo, Assert.GroupAttribute> result, MethodInfo method)
7581
{
7682
foreach (KeyValuePair<MethodInfo, Assert.GroupAttribute> item in result)
@@ -104,9 +110,7 @@ private static string GetMethodPrefixFromUsingStatements(string script)
104110
{
105111
return string.Empty;
106112
}
107-
else if (script.Contains("using DevTools;") &&
108-
!script.Contains("using NUnit.Framework;") &&
109-
!script.Contains("using static System.Diagnostics.Debug;"))
113+
else if (script.Contains("using DevTools;") && KnownUsingsWithAssertClasses.All(__using => !script.Contains(__using)))
110114
{
111115
return "Assert.";
112116
}
@@ -129,9 +133,9 @@ private static uint CountSubstrings(string instance, string value)
129133

130134
return count;
131135
}
132-
private static List<Task<Dictionary<Assert.GroupAttribute, ulong>>> CreateCountingTasks(Dictionary<MethodInfo, Assert.GroupAttribute> methodToGroupMap, string path)
136+
private static List<Task<Dictionary<Assert.GroupAttribute, uint>>> CreateCountingTasks(Dictionary<MethodInfo, Assert.GroupAttribute> methodToGroupMap, string path)
133137
{
134-
List<Task<Dictionary<Assert.GroupAttribute, ulong>>> tasks = new List<Task<Dictionary<Assert.GroupAttribute, ulong>>>(256);
138+
List<Task<Dictionary<Assert.GroupAttribute, uint>>> tasks = new List<Task<Dictionary<Assert.GroupAttribute, uint>>>(256);
135139

136140
DirectoryExtensions.ForEachFile(path,
137141
(file) =>
@@ -141,17 +145,17 @@ private static uint CountSubstrings(string instance, string value)
141145
return;
142146
}
143147

144-
tasks.Add(Task<Dictionary<Assert.GroupAttribute, ulong>>.Factory.StartNew(
148+
tasks.Add(Task<Dictionary<Assert.GroupAttribute, uint>>.Factory.StartNew(
145149
() =>
146150
{
147-
Dictionary<Assert.GroupAttribute, ulong> callCounts = new Dictionary<Assert.GroupAttribute, ulong>();
151+
Dictionary<Assert.GroupAttribute, uint> callCounts = new Dictionary<Assert.GroupAttribute, uint>();
148152
string script = File.ReadAllText(file);
149153
string prefix = GetMethodPrefixFromUsingStatements(script);
150154

151155
foreach (KeyValuePair<MethodInfo, Assert.GroupAttribute> methodMapping in methodToGroupMap)
152156
{
153157
Assert.GroupAttribute group = methodMapping.Value;
154-
ulong numCalls = CountSubstrings(script, prefix + methodMapping.Key.Name);
158+
uint numCalls = CountSubstrings(script, prefix + methodMapping.Key.Name);
155159

156160
if (callCounts.ContainsKey(group))
157161
{
@@ -169,13 +173,13 @@ private static uint CountSubstrings(string instance, string value)
169173

170174
return tasks;
171175
}
172-
private static async Task<Dictionary<Assert.GroupAttribute, ulong>> CombineResults(List<Task<Dictionary<Assert.GroupAttribute, ulong>>> jobs, Dictionary<MethodInfo, Assert.GroupAttribute> methodToGroupMap)
176+
private static async Task<Dictionary<Assert.GroupAttribute, uint>> CombineResults(List<Task<Dictionary<Assert.GroupAttribute, uint>>> jobs)
173177
{
174-
Dictionary<Assert.GroupAttribute, ulong> result = await jobs[0]; // at the very least this very script is assigned a job
178+
Dictionary<Assert.GroupAttribute, uint> result = await jobs[0]; // at the very least this very script is assigned a job
175179

176180
for (int i = 1; i < jobs.Count; i++)
177181
{
178-
foreach (KeyValuePair<Assert.GroupAttribute, ulong> callCount in await jobs[i])
182+
foreach (KeyValuePair<Assert.GroupAttribute, uint> callCount in await jobs[i])
179183
{
180184
result[callCount.Key] += callCount.Value;
181185
}

Assert.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ public static void IsSmallerOrEqual<T>(T value, T limit)
505505
where T : IComparable<T>
506506
{
507507
#if COMPARISON_CHECKS
508-
if (value.CompareTo(limit) == 1)
508+
if (value.CompareTo(limit) > 0)
509509
{
510510
throw new ArgumentOutOfRangeException(ASSERTION_FAILED_TAG + $"{ value } was expected to be smaller than or equal to { limit }.");
511511
}
@@ -519,7 +519,7 @@ public static void IsSmaller<T>(T value, T limit)
519519
where T : IComparable<T>
520520
{
521521
#if COMPARISON_CHECKS
522-
if (value.CompareTo(limit) != -1)
522+
if (value.CompareTo(limit) > -1)
523523
{
524524
throw new ArgumentOutOfRangeException(ASSERTION_FAILED_TAG + $"{ value } was expected to be smaller than { limit }.");
525525
}
@@ -533,7 +533,7 @@ public static void IsGreaterOrEqual<T>(T value, T limit)
533533
where T : IComparable<T>
534534
{
535535
#if COMPARISON_CHECKS
536-
if (value.CompareTo(limit) == -1)
536+
if (value.CompareTo(limit) < 0)
537537
{
538538
throw new ArgumentOutOfRangeException(ASSERTION_FAILED_TAG + $"{ value } was expected to be greater than or equal to { limit }.");
539539
}
@@ -547,7 +547,7 @@ public static void IsGreater<T>(T value, T limit)
547547
where T : IComparable<T>
548548
{
549549
#if COMPARISON_CHECKS
550-
if (value.CompareTo(limit) != 1)
550+
if (value.CompareTo(limit) < 1)
551551
{
552552
throw new ArgumentOutOfRangeException(ASSERTION_FAILED_TAG + $"{ value } was expected to be greater than { limit }.");
553553
}
@@ -561,7 +561,7 @@ public static void IsNotSmaller<T>(T value, T limit)
561561
where T : IComparable<T>
562562
{
563563
#if COMPARISON_CHECKS
564-
if (value.CompareTo(limit) == -1)
564+
if (value.CompareTo(limit) < 0)
565565
{
566566
throw new ArgumentOutOfRangeException(ASSERTION_FAILED_TAG + $"{ value } was expected not to be smaller than { limit }.");
567567
}
@@ -575,7 +575,7 @@ public static void IsNotGreater<T>(T value, T limit)
575575
where T : IComparable<T>
576576
{
577577
#if COMPARISON_CHECKS
578-
if (value.CompareTo(limit) == 1)
578+
if (value.CompareTo(limit) > 0)
579579
{
580580
throw new ArgumentOutOfRangeException(ASSERTION_FAILED_TAG + $"{ value } was expected not to be greater than { limit }.");
581581
}

Unity/Editor/SafetyCheckSettingsWindow.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ internal class SafetyCheckSettingsWindow : EditorWindow
2020
private bool firstLoad;
2121
private bool anythingChanged;
2222

23-
private Dictionary<Assert.GroupAttribute, ulong> methodCallCounts = null;
23+
private Dictionary<Assert.GroupAttribute, uint> methodCallCounts = null;
2424
private Dictionary<Assert.GroupAttribute, bool> definesToCheckMarks;
2525

2626

@@ -48,7 +48,7 @@ private ulong TotalMethodCalls
4848
{
4949
ulong count = 0;
5050

51-
foreach (KeyValuePair<Assert.GroupAttribute, ulong> assertion in methodCallCounts)
51+
foreach (KeyValuePair<Assert.GroupAttribute, uint> assertion in methodCallCounts)
5252
{
5353
count += assertion.Value;
5454
}

UnreachableException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22

33
namespace DevTools
44
{

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "csharpdevtools",
33
"displayName": "C Sharp Dev Tools",
4-
"version": "1.0.9",
4+
"version": "1.0.10",
55
"description": "C Sharp Dev Tools is a small framework for defensive development with conditionally compiled assertions and logging tools.",
66
"author": {
77
"name": "Maximilian Kalimon",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "csharpdevtools",
33
"displayName": "C Sharp Dev Tools",
4-
"version": "1.0.9",
4+
"version": "1.0.10",
55
"description": "C Sharp Dev Tools is a small framework for defensive development with conditionally compiled assertions and logging tools.",
66
"author": {
77
"name": "Maximilian Kalimon",

0 commit comments

Comments
 (0)