Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1a5b23d

Browse files
jack-pappasKevinRansom
authored andcommitted
Surface area test output improvements. (dotnet#2445)
Re-implemented the way the test which compares actual vs. expectedsurface area works, so that when they don't match exactly, the outputonly displays the members which don't match. The new output messagealso shows which members were "unexpectedly present" and"unexpectedly missing", which makes it easier to diagnose the causeof the test failure.
1 parent798345d commit1a5b23d

File tree

1 file changed

+57
-16
lines changed

1 file changed

+57
-16
lines changed

‎src/fsharp/FSharp.Core.Unittests/LibraryTestFx.fs‎

Lines changed: 57 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,8 @@ let CheckThrowsInvalidOperationExn f = CheckThrowsExn<InvalidOperationExceptio
5656
letCheckThrowsFormatException f= CheckThrowsExn<FormatException> f
5757

5858
// Verifies two sequences are equal (same length, equiv elements)
59-
letVerifySeqsEqual seq1 seq2=
60-
Assert.AreEqual(Seq.length seq1, Seq.length seq2,"Sequences are different lengths.")
61-
62-
Seq.zip seq1 seq2
63-
|> Seq.iteri(fun i(a,b)->if a<> bthen Assert.Fail("Sequences are different in position {0}\n Expected: {1}\n But was: {2}", i, a, b))
59+
letVerifySeqsEqual(seq1:seq<'T>)(seq2:seq<'T>)=
60+
CollectionAssert.AreEqual(seq1, seq2)
6461

6562
letsleep(n:int32)=
6663
#if FX_NO_THREAD
@@ -117,21 +114,65 @@ module SurfaceArea =
117114
#endif
118115

119116
letactual=
120-
types
121-
|> Array.collect getTypeMemberStrings
122-
|> Array.sort
123-
|> String.concat"\r\n"
117+
types|> Array.collect getTypeMemberStrings
124118

125119
asm,actual
126120

127121
// verify public surface area matches expected
128-
letverify expected platform fileName=
129-
letworkDir= TestContext.CurrentContext.WorkDirectory
130-
letlogFile= sprintf"%s\\CoreUnit_%s_Xml.xml" workDir platform
122+
letverify expected platform(fileName:string)=
131123
letnormalize(s:string)=
132-
Regex.Replace(s,"(\\r\\n|\\n)+","\r\n").Trim([|'\r';'\n'|])
124+
Regex.Replace(s,"(\\r\\n|\\n|\\r)+","\r\n").Trim()
125+
133126
letasm,actualNotNormalized= getActual()
134-
letactual= actualNotNormalized|> normalize
135-
letexpected= expected|> normalize
127+
letactual= actualNotNormalized|> Seq.map normalize|> Seq.filter(String.IsNullOrWhiteSpace>>not)|> set
136128

137-
Assert.AreEqual(expected, actual, sprintf"\r\nAssembly:%A\r\n--------------------- ACTUAL -------------------\r\n%s\r\n--------------------EXPECTED--------------------\r\n%s\r\n-----------------\r\n Expected and actual surface area don't match. To see the delta, run\r\nwindiff%s%s" asm actual expected fileName logFile)
129+
letexpected=
130+
// Split the "expected" string into individual lines, then normalize it.
131+
(normalize expected).Split([|"\r\n";"\n";"\r"|], StringSplitOptions.RemoveEmptyEntries)
132+
|> set
133+
134+
//
135+
// Find types/members which exist in exactly one of the expected or actual surface areas.
136+
//
137+
138+
/// Surface area types/members which were expected to be found but missing from the actual surface area.
139+
letunexpectedlyMissing= Set.difference expected actual
140+
141+
/// Surface area types/members present in the actual surface area but weren't expected to be.
142+
letunexpectedlyPresent= Set.difference actual expected
143+
144+
// If both sets are empty, the surface areas match so allow the test to pass.
145+
if Set.isEmpty unexpectedlyMissing
146+
&& Set.isEmpty unexpectedlyPresentthen
147+
Assert.Pass()
148+
149+
letlogFile=
150+
letworkDir= TestContext.CurrentContext.WorkDirectory
151+
sprintf"%s\\CoreUnit_%s_Xml.xml" workDir platform
152+
153+
// The surface areas don't match; prepare an easily-readable output message.
154+
letmsg=
155+
let inlinenewLine(sb:System.Text.StringBuilder)= sb.AppendLine()|> ignore
156+
letsb= System.Text.StringBuilder()
157+
Printf.bprintf sb"Assembly:%A" asm
158+
newLine sb
159+
sb.AppendLine"Expected and actual surface area don't match. To see the delta, run:"|> ignore
160+
Printf.bprintf sb" windiff%s%s" fileName logFile
161+
newLine sb
162+
newLine sb
163+
sb.Append"Unexpectedly missing (expected, not actual):"|> ignore
164+
for sin unexpectedlyMissingdo
165+
newLine sb
166+
sb.Append""|> ignore
167+
sb.Append s|> ignore
168+
newLine sb
169+
newLine sb
170+
sb.Append"Unexpectedly present (actual, not expected):"|> ignore
171+
for sin unexpectedlyPresentdo
172+
newLine sb
173+
sb.Append""|> ignore
174+
sb.Append s|> ignore
175+
newLine sb
176+
sb.ToString()
177+
178+
Assert.Fail msg

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp