############################################################################### # # common.eagle -- # # Written by Joe Mistachkin. # Released to the public domain, use at your own risk! # ############################################################################### if {[isEagle]} then { proc getBuildDirectory {} { # # NOTE: See if the "native" runtime option has been added. If so, use the # directory for the mixed-mode assembly. To enable this option via # the command line, enter a command similar to the following (all on # one line): # # EagleShell.exe -initialize -runtimeOption native # -file .\path\to\all.eagle # if {[hasRuntimeOption native]} then { return [file join [file dirname $::path] bin \ [expr {[haveConstraint imageRuntime40] ? "2010" : "2008"}] \ [machineToPlatform $::tcl_platform(machine)] $::test_configuration] } else { return [file join [file dirname $::path] bin \ [expr {[haveConstraint imageRuntime40] ? "2010" : "2008"}] \ $::test_configuration bin] } } proc getBuildFileName { fileName } { return [file nativename \ [file join [getBuildDirectory] [file tail $fileName]]] } proc getBinaryDirectory {} { return [info binary] } proc getBinaryFileName { fileName } { return [file nativename \ [file join [getBinaryDirectory] [file tail $fileName]]] } proc tryCopyBuildFile { fileName } { # # NOTE: If we cannot copy the assembly then it is probably already loaded. # set sourceFileName [getBuildFileName $fileName] if {![file exists $sourceFileName]} then { tputs $::test_channel [appendArgs \ "---- skipped copying build file \"" $sourceFileName \ "\", it does not exist\n"] return } set targetFileName [getBinaryFileName $fileName] if {[catch {file copy -force $sourceFileName $targetFileName}] == 0} then { tputs $::test_channel [appendArgs \ "---- copied build file from \"" $sourceFileName "\" to \"" \ $targetFileName \"\n] } else { tputs $::test_channel [appendArgs \ "---- failed to copy build file from \"" $sourceFileName "\" to \"" \ $targetFileName \"\n] } } proc tryDeleteBinaryFile { fileName } { set fileName [getBinaryFileName $fileName] if {![file exists $fileName]} then { tputs $::test_channel [appendArgs \ "---- skipped deleting binary file \"" $fileName \ "\", it does not exist\n"] return } if {[catch {file delete $fileName}] == 0} then { tputs $::test_channel [appendArgs \ "---- deleted binary file \"" $fileName \"\n] } else { tputs $::test_channel [appendArgs \ "---- failed to delete binary file \"" $fileName \"\n] } } proc tryCopyAssembly { fileName {pdb true} } { tryCopyBuildFile $fileName if {$pdb} then { tryCopyBuildFile [appendArgs [file rootname $fileName] .pdb] } } proc tryDeleteAssembly { fileName {pdb true} } { tryDeleteBinaryFile $fileName if {$pdb} then { tryDeleteBinaryFile [appendArgs [file rootname $fileName] .pdb] } } proc tryLoadAssembly { fileName } { set fileName [getBuildFileName $fileName] if {[catch {set assembly \ [object load -loadtype File $fileName]}] == 0} then { # # NOTE: Now, add the necessary test constraint. # addConstraint [file rootname [file tail $fileName]] # # NOTE: Return the full path of the loaded file. # return $fileName } return "" } proc enumerableToString { enumerable } { set result [list] if {[string length $enumerable] == 0 || $enumerable eq "null"} then { return $result } object foreach -alias item $enumerable { if {[string length $item] > 0} then { lappend result [$item ToString] } } return $result } proc compileCSharpWith { text resultsVarName errorsVarName fileNames args } { # # NOTE: Create the base command to evaluate and add the property settings # that are almost always needed by our unit tests (i.e. the System # and System.Data assembly references). # set command [list compileCSharp $text results errors \ ReferencedAssemblies.Add System.dll ReferencedAssemblies.Add \ System.Data.dll ReferencedAssemblies.Add System.Xml.dll] # # NOTE: Add all the provided file names as assembly references. # foreach fileName $fileNames { lappend command ReferencedAssemblies.Add [getBuildFileName $fileName] } # # NOTE: Add the extra arguments, if any, to the command to evaluate. # eval lappend command $args # # NOTE: Alias the compiler local results and errors variables to the # variable names provided by our caller. # upvar 1 $resultsVarName results upvar 1 $errorsVarName errors # # NOTE: Evaluate the constructed [compileCSharp] command and return the # result. # eval $command } proc setupDb {fileName {mode ""} {delete ""} {extra ""} {varName db}} { set fileName [file join [getTemporaryPath] $fileName] if {[string length $delete] == 0 || $delete} then { catch {file delete $fileName} } upvar 1 $varName db set connection {Data Source=${fileName}} if {[string length $mode] > 0} then { append connection {;Journal Mode=${mode}} } if {[string length $extra] > 0} then { append connection \; $extra } set db [sql open -type SQLite [subst $connection]] } proc cleanupDb {fileName {varName db}} { upvar 1 $varName db catch {sql close $db} catch {file delete [file join [getTemporaryPath] $fileName]} } proc runSQLiteTestPrologue {} { # # NOTE: Skip running our custom prologue if the main one has been skipped. # if {![info exists ::no(prologue.eagle)]} then { tryDeleteAssembly SQLite.Interop.dll tryDeleteAssembly System.Data.SQLite.dll tryDeleteAssembly System.Data.SQLite.Linq.dll tryCopyAssembly SQLite.Interop.dll tryCopyAssembly System.Data.SQLite.dll tryCopyAssembly System.Data.SQLite.Linq.dll tryLoadAssembly System.Data.SQLite.dll tryLoadAssembly System.Data.SQLite.Linq.dll } } proc runSQLiteTestEpilogue {} { # # NOTE: Skip running our custom epilogue if the main one has been skipped. # if {![info exists ::no(epilogue.eagle)]} then { # # NOTE: For now, nothing is done here. # } } }