📄 test.vb
字号:
If m_ResponseFile <> "" Then filesToCheck.Add(m_ResponseFile) If m_RspFile <> "" Then filesToCheck.Add(m_RspFile) If m_DefaultRspFile <> "" Then filesToCheck.Add(m_DefaultRspFile) For Each item As String In filesToCheck fileDate = IO.File.GetLastWriteTime(item) If fileDate > lastDate Then lastDate = fileDate End If Next Return lastDate End Get End Property Private ReadOnly Property GetACPath() As String Get If m_AC <> String.Empty Then Return m_AC Return IO.Path.GetFullPath("..\..\ac\bin\ac.exe".Replace("\", IO.Path.DirectorySeparatorChar)) End Get End Property Function GetExecutor() As String Return IO.Path.GetFullPath("..\..\rt-execute\rt-execute.exe".Replace("\", IO.Path.DirectorySeparatorChar)) End Function ''' <summary> ''' Returns true if new verifications have been created (only if source files has changed ''' or vbnc compiler has changed since last run). ''' </summary> ''' <returns></returns> ''' <remarks></remarks> Function CreateVerifications() As Boolean Initialize() If Me.Parent IsNot Nothing AndAlso (Me.Parent.SkipCleanTests AndAlso Me.IsDirty = False) Then Return False Dim vbnccmdline As String() = Helper.QuoteStrings(Me.GetTestCommandLineArguments(False)) Dim vbccmdline As String() = Helper.QuoteStrings(Me.GetTestCommandLineArguments(True)) Dim vbc As ExternalProcessVerification = Nothing Dim compiler As String = Nothing Dim vbccompiler As String = Nothing If Me.Parent IsNot Nothing Then vbccompiler = Me.Parent.VBCPath End If If vbccompiler <> String.Empty Then vbc = New ExternalProcessVerification(Me, vbccompiler, Join(vbccmdline, " ")) vbc.Process.WorkingDirectory = m_BasePath vbc.Name = "VBC Compile (verifies that the test itself is correct)" If m_IsNegativeTest Then vbc.NegativeError = m_NegativeError End If compiler = Me.Compiler If compiler Is Nothing AndAlso Me.Parent IsNot Nothing Then compiler = Me.Parent.VBNCPath End If If compiler Is Nothing Then Throw New Exception("No compiler specified.") End If m_Compilation = New ExternalProcessVerification(Me, compiler, Join(vbnccmdline, " ")) m_Compilation.Process.WorkingDirectory = m_BasePath m_Compilation.Name = "VBNC Compile" 'm_Compilation.Process.UseTemporaryExecutable = True If m_IsNegativeTest Then m_Compilation.NegativeError = m_NegativeError m_Verifications.Clear() If vbc IsNot Nothing AndAlso IsSourceDirty Then m_Verifications.Add(vbc) m_Verifications.Add(m_Compilation) If m_IsNegativeTest = False Then If vbccompiler <> String.Empty AndAlso Me.m_Target = "exe" AndAlso Me.Name.Contains("SelfCompile") = False Then m_Verifications.Add(New ExternalProcessVerification(Me, Me.GetOutputVBCAssembly)) m_Verifications(m_Verifications.Count - 1).Name = "Test executable verification" End If 'm_Verifications.Add(New XMLVerifier(Me)) 'm_Verifications(m_Verifications.Count - 1).Name = "Xml verification" Dim ac As String ac = GetACPath If ac <> String.Empty AndAlso vbccompiler <> String.Empty AndAlso IO.File.Exists(ac) AndAlso IO.File.Exists(vbccompiler) Then m_Verifications.Add(New ExternalProcessVerification(Me, GetACPath, "%OUTPUTASSEMBLY% %OUTPUTVBCASSEMBLY%")) m_Verifications(m_Verifications.Count - 1).Name = "Assembly Comparison Verification" End If Dim peverify As String peverify = Environment.ExpandEnvironmentVariables(PEVerifyPath) If peverify <> String.Empty AndAlso IO.File.Exists(peverify) Then m_Verifications.Add(New ExternalProcessVerification(Me, peverify, "%OUTPUTASSEMBLY% /nologo")) m_Verifications(m_Verifications.Count - 1).Name = "Type Safety and Security Verification" End If If Me.m_Target = "exe" Then Dim executor As String executor = GetExecutor() If executor <> String.Empty AndAlso IO.File.Exists(executor) Then m_Verifications.Add(New ExternalProcessVerification(Me, executor)) Else m_Verifications.Add(New ExternalProcessVerification(Me, Me.GetOutputAssembly)) End If m_Verifications(m_Verifications.Count - 1).Name = "Output executable verification" End If If vbccompiler <> String.Empty Then Dim bootStrappedExe As String bootStrappedExe = IO.Path.Combine(IO.Path.GetDirectoryName(IO.Path.GetDirectoryName(vbccompiler)), Helper.NormalizePath("tests\SelfTest\testoutput\SelfCompile.exe")) If IO.File.Exists(bootStrappedExe) AndAlso False Then Dim epv As New ExternalProcessVerification(Me, bootStrappedExe, Join(vbnccmdline, " ")) m_Verifications.Add(epv) m_Verifications(m_Verifications.Count - 1).Name = "Bootstrapped verification" epv.Process.WorkingDirectory = m_BasePath epv.Process.UseTemporaryExecutable = True If m_IsNegativeTest Then epv.NegativeError = m_NegativeError End If End If End If m_Result = Results.NotRun Return True End Function Sub SaveTest() Const DATETIMEFORMAT As String = "yyyy-MM-dd HHmm" Dim compiler As String Dim filename As String Try compiler = "(" & VBNCVerification.Process.FileVersion.FileVersion & " " & VBNCVerification.Process.LastWriteDate.ToString(DATETIMEFORMAT) & ")" compiler &= "." & m_Result.ToString filename = IO.Path.Combine(Me.OutputPath, Me.Name & "." & compiler & ".testresult") Using contents As New Xml.XmlTextWriter(filename, Nothing) contents.Formatting = Xml.Formatting.Indented If False Then Dim ser As New Xml.Serialization.XmlSerializer(GetType(Test)) ser.Serialize(contents, Me) Else contents.WriteStartDocument(True) contents.WriteStartElement("Test") contents.WriteElementString("Name", Me.Name) contents.WriteStartElement("Date") contents.WriteValue(Me.LastRun) contents.WriteEndElement() contents.WriteElementString("Compiler", compiler) contents.WriteElementString("Result", Me.Result.ToString) contents.WriteElementString("IsNegativeTest", Me.IsNegativeTest.ToString) contents.WriteElementString("NegativeError", Me.NegativeError.ToString) contents.WriteElementString("TestDuration", Me.TestDuration.ToString) contents.WriteStartElement("Verifications") For Each ver As VerificationBase In Me.Verifications contents.WriteStartElement(ver.GetType.Name) contents.WriteElementString("Name", ver.Name) contents.WriteElementString("Result", ver.Result.ToString) contents.WriteElementString("Run", ver.Run.ToString) contents.WriteElementString("NegativeError", ver.NegativeError.ToString) contents.WriteElementString("DescriptiveMessage", ver.DescriptiveMessage) contents.WriteEndElement() Next contents.WriteEndElement() contents.WriteEndElement() contents.WriteEndDocument() End If End Using Catch ex As Exception Debug.WriteLine(ex.Message & vbNewLine & ex.StackTrace) End Try End Sub Sub DoTest() If CreateVerifications() = False Then Return End If RaiseEvent Executing(Me) Dim StartTime, EndTime As Date StartTime = Date.Now For Each v As VerificationBase In m_Verifications If v.Verify = False Then m_Result = Results.Failed Exit For End If Next EndTime = Date.Now m_TestDuration = EndTime - StartTime m_LastRun = StartTime If m_Result = Results.NotRun Then m_Result = Results.Success End If SaveTest() m_LoadedOldResults = False LoadOldResults() RaiseEvent Executed(Me) End Sub ReadOnly Property VBNCVerification() As ExternalProcessVerification Get For Each ver As VerificationBase In m_Verifications If ver.Name.Contains("VBNC Compile") Then Return DirectCast(ver, ExternalProcessVerification) End If Next Return Nothing End Get End Property ReadOnly Property Message() As String Get Dim result As String = "" For Each v As VerificationBase In m_Verifications If v IsNot Nothing Then result &= v.DescriptiveMessage & vbNewLine & New String("*"c, 50) & vbNewLine End If Next Return result End Get End Property Shared Function GetTestName(ByVal Filename As String) As String Dim result As String result = IO.Path.GetFileNameWithoutExtension(Filename) If Filename Like "*.[0-9].vb" Then 'Multi file test. result = IO.Path.GetFileNameWithoutExtension(result) End If Return result End Function Sub New() End Sub Sub New(ByVal Path As String, ByVal Parent As Tests) m_Parent = Parent If Path.EndsWith(IO.Path.DirectorySeparatorChar) Then Path = Path.Remove(Path.Length - 1, 1) End If m_BasePath = IO.Path.GetDirectoryName(Path) m_Files.Add(Path) m_Name = GetTestName(Path) 'Test to see if it is a negative test. 'Negative tests are: '0001.vb '0001-2.vb '0001-3 sometest.vb If m_NegativeRegExpTest.IsMatch(m_Name) Then Dim firstNonNumber As Integer = m_Name.Length For i As Integer = 0 To m_Name.Length - 1 If Char.IsNumber(m_Name(i)) = False Then firstNonNumber = i Exit For End If Next m_IsNegativeTest = Integer.TryParse(m_Name.Substring(0, firstNonNumber), m_NegativeError) End If m_OutputPath = IO.Path.Combine(m_BasePath, DefaultOutputPath) End Sub Private Function IsNoConfig(ByVal text As String) As Boolean Return text.IndexOf("/noconfig", StringComparison.OrdinalIgnoreCase) >= 0 End Function Private Function GetTarget(ByVal text As String, ByVal DefaultTarget As String) As String Dim prefixes As String() = New String() {"/target:", "/t:", "-target:", "-t:"} For Each prefix As String In prefixes If text.IndexOf(prefix & "exe", StringComparison.OrdinalIgnoreCase) >= 0 Then Return "exe" If text.IndexOf(prefix & "winexe", StringComparison.OrdinalIgnoreCase) >= 0 Then Return "winexe" If text.IndexOf(prefix & "library", StringComparison.OrdinalIgnoreCase) >= 0 Then Return "dll" If text.IndexOf(prefix & "module", StringComparison.OrdinalIgnoreCase) >= 0 Then Return "netmodule" Next Return DefaultTarget End Function Private Function GetTargetExtension(ByVal Target As String) As String Select Case Target Case "winexe", "exe" Return "exe" Case "library", "dll" Return "dll" Case "netmodule", "module" Return "netmodule" Case Else Return "exe" End Select End Function Protected Overrides Sub Finalize() MyBase.Finalize() End SubEnd Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -