Pester's XML report contains only the file name, not full path - powershell

I'm new to Pester, I was testing the things locally then i got this problem. When i generate the XML report in pester it contains this line
<package name="code"><class name="code/cal" sourcefilename="cal.ps1">
but when i generate the HTML file using ReportGenerator, it gives "file does not exist (any more)". So i change the above code snippet it started giving the result without any error. i.e.,
<package name="code"><class name="code/cal" sourcefilename=".\code\cal.ps1">
i have below directory structure
root
|_ code #contains all the main scripts
|_ test #contains all the test scripts
I even tried adding this code in the AfterAll block, but the XML file gets generated only after its execution. so it's giving a file not found error.
AfterAll{
$script_name = "cal.ps1"
$script_path = (".\code\" + "cal.ps1")
(Get-Content "coverage.xml").replace( $script_name , ( $script_path + $script_name ) ) | Set-Content "coverage.xml"
}
So, is there any way for doing that change automatically?
Thanks in advance

Related

CMake collect sources from folders using batch script (without GLOB)

I want to collect all the source or header files from a specified folder, also matching a curtain naming convention. I don't want to use GLOBbing, and also couldn't find any examples of an approach using only cmake.
One answer from this question suggests to use ls *.cpp into CMakeLists.txt. So I though of getting a list of sources via invoking a batch script in CMakeLists.
But something is wrong. Though it seems that the output is totally correct, CMake can not find those files. The path is (visually) correct: if I manually type it into add_executable, generating will succeed.
While I still want to know how to achieve the initial intent, I am extremely confused about the reason why totally identical strings compare to false:
CMake log:
-- Manually-typed: C:/Repos/cmake-scanner/src/main.cpp
-- Recieved-batch: C:/Repos/cmake-scanner/src/main.cpp
-- Path strings not identical
CollectSources.bat
#echo off
set arg1=%1
set arg2=%2
powershell -Command "$path = '%1'.Replace('\','/'); $headers = New-Object Collections.Generic.List[string]; ls -Name $path/*.%2 | foreach-object{ $headers.Add($path + '/' + $_)}; $headers"
CMakeLists.txt
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
project(Auto-scanner)
set(HEADERS)
set(SOURCES)
if(WIN32)
execute_process(
COMMAND CMD /c ${CMAKE_CURRENT_SOURCE_DIR}/CollectSources.bat ${CMAKE_CURRENT_SOURCE_DIR}/include h
OUTPUT_VARIABLE res
)
message(STATUS "Found headers: ${res}")
execute_process(
COMMAND CMD /c ${CMAKE_CURRENT_SOURCE_DIR}/CollectSources.bat ${CMAKE_CURRENT_SOURCE_DIR}/src cpp
OUTPUT_VARIABLE res2
)
message(STATUS "Found sources: ${res2}")
set(${HEADERS} ${res})
endif(WIN32)
message(STATUS "Collected headers: ${HEADERS}")
message(STATUS "Manually-typed: C:/Repos/cmake-scanner/src/main.cpp")
message(STATUS "Recieved-batch: ${res2}")
if(NOT "C:/Repos/cmake-scanner/src/main.cpp" STREQUAL "${res2}")
message(STATUS "Path strings not identical")
else()
message(STATUS "Path strings are identical")
endif()
add_executable(${PROJECT_NAME}
${res}
${res2}
)
target_include_directories(${PROJECT_NAME}
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/src
)
and project tree:
cmake-scanner
|-include
| |-IPublicA.h
| |-IPublicB.h
| |-IPublicC.h
| |-IPublicD.h
|-src
|-main.cpp
https://github.com/ElDesalmado/cmake-scanner.git
UPDATE
Strings' comparison by length yields different results, so I thought maybe there are some trailing characters in the output of execute_process.
So I replaced all the newlines that actually might prevent cmake from finding source files.
string(REGEX REPLACE "\n$" "" ...)
So they compare equal, however still could not be located by cmake.
I had some luck with using OUTPUT_STRIP_TRAILING_WHITESPACE in execute_command and main.cpp has been finally located and project generated. But when there are 2 or more sources this doesn't help.
I m going to try outputting sources' names in a single line and see what would occur...
I have solved the issue.
Cmake accepts lists of sources that must be formatted in a way, that sources' paths are separated with a semicolon.
So the solution was to modifiy batch script to output a string line of semicolon-separated file names. Later I will update the repo and provide the batch code.
In order for CMake to recognize the output from the bathc script as a list of Source/Header files, it must not contain any trailing symbols like whitespaces or newlines and file paths must be separated with a semicolon:
path-to-headerA.h;path-to-headerB.h;path-to-headerC.h;
(It is ok if there is a semiciolon at the end of the string line - CMake accepts that).
Working solution
powershell
#echo off
set arg1=%1
set arg2=%2
powershell -Command "$path = '%1'.Replace('\','/'); $headers = ''; get-childitem $path/*.%2 | select-object -expandProperty Name | foreach-object{ $headers += ($path + '/' + $_ + ';')}; Write-output $headers"
CollectSources.cmake
#Collect source files from a given folder
set(DIR_OF_CollectSources_CMAKE ${CMAKE_CURRENT_LIST_DIR})
function(CollectSources path ext ret)
message(STATUS "Collecting sources *.${ext} from ${path}")
execute_process(
COMMAND CMD /c ${DIR_OF_CollectSources_CMAKE}/CollectSources.bat ${path} ${ext}
OUTPUT_VARIABLE res
OUTPUT_STRIP_TRAILING_WHITESPACE
)
message(STATUS "Sources collected:")
foreach(src ${res})
message(${src})
endforeach()
set(${ret} "${res}" PARENT_SCOPE)
endfunction()
usage in CMakeLists.txt:
include(CollectSources)
CollectSources(${CMAKE_CURRENT_SOURCE_DIR}/include h HEADERS)
Example:
https://github.com/ElDesalmado/cmake-scanner.git
CMake output:
-- Collecting sources *.h from C:/Repos/cmake-scanner/include
-- Sources collected:
C:/Repos/cmake-scanner/include/IPublicA.h
C:/Repos/cmake-scanner/include/IPublicB.h
C:/Repos/cmake-scanner/include/IPublicC.h
C:/Repos/cmake-scanner/include/IPublicD.h
-- Collecting sources *.cpp from C:/Repos/cmake-scanner/src
-- Sources collected:
C:/Repos/cmake-scanner/src/lib.cpp
C:/Repos/cmake-scanner/src/main.cpp

How to use get the current directory and use wildcard to find any csv file there?

How can I use relative path and relative (wildcard) files in powershell?
I have tried the following but didn't work:
Powershell -c
$file= Get-ChildItem -Filter *.csv
[System.IO.File]::ReadAllText .\$file .replace('Buyer','Alıcı').
replace('Supplier','Tedarikçi').
replace('FI','Banka').
replace('Supplier Reference','Tedarikçi Referansı').
replace('Buyer Program','Alıcı Programı').
replace('Buy Offer','eklif Al').
replace('Payment Obligation Id','Ödeme Yükümlülüğü Kimliği').
replace('Buyer Unique Doc Id','Alıcı Benzersiz Doküman Kimliği').
replace('Trade Date','Ticaret Tarihi').
replace('Due Date','ödeme tarihi').
replace('Maturity Date','Vade Tarihi').
replace('Currency','Para Birimi').
replace('Certified Value','Sertifikalı Değer').
replace('Buyer Payment Amount','Alıcıya Ödeme Tutarı').
replace('Buyer Fee','Alıcı Ücreti').
replace('Supplier Interest Fees','Tedarikçi Faiz Ücretleri').
replace('Supplier Funds Received','Alınan Tedarikçi Fonu')|sc c:\pstest\test2.csv
I want the script to fetch for any csv file in the same directory where the script is being run, any ideas?
I think there is a lot of suggestions how to get path of running script.
Althought I would do that like this:
$dir = $MyInvocation.MyCommand.Path
$dir = $dir.SubString(0, $dir.LastIndexOf("\") + 1)
Then you got path of script execution and what you need is just to call your script.
. $dir"MyScript.ps1"

phpexcel save file to server ubuntu

I'm with a problem I would like to share to see if I can provide help.
PHP Excel use Ubuntu and want guaradar the file generated in a specific folder of my project directory. I understand that looking information is made as follows, but it is not working properly.
My code is as follows:
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
//header('Content-Disposition: attachment;filename="ReporteSuscriptores.xlsx"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
//$objWriter->save('nameoffile.xls');
$filename = (__DIR__);
$objWriter->save($filename . '/report.xlsx');
Try other alternatives without success as the next block
$objWriter->save('nameoffile.xls');
And I can not save the file generated excel in a specific directory

Publish SSRS by Octopus

I'm building the set up to deploy my SSRS reports through Octopus Deploy, I found out one Octopus Library and I'm working on it, but I've had some issues:
1º ---- Message error: (The path is alright, but it keeps with the same warning)
WARNING: Unable to find datasource SalesDrivers in /Sales Drivers/Data Sources
2º ---- The method doesn't exist
Method invocation failed because [Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy3er_ReportService2005_asmx_wsdl.ReportingService2005] doesn't contain a method named 'LoadReportDefinition'.
The powershell function from the template\library that is throwing the error can been seen below:
#region Update-ReportParamters()
Function Update-ReportParameters($ReportFile)
{
# declare local variables
$ReportParameters = #();
# necessary so that when attempting to use the report execution service, it doesn't puke on you when it can't find the data source
$ReportData = (Remove-SharedReferences -ReportFile $ReportFile)
# get just the report name
$ReportName = $ReportFile.SubString($ReportFile.LastIndexOf("\") + 1)
$ReportName = $ReportName.SubString(0, $ReportName.IndexOf("."))
# create warnings object
$ReportExecutionWarnings = $null
# load the report definition
Write-Host "*********************************************"
#Write-Host $ReportData
#(Remove-SharedReferences -ReportFile $ReportFile)
#Write-Host $ReportExecutionWarnings
$ExecutionInfo = $ReportExecutionProxy.LoadReportDefinition($ReportData, [ref] $ReportExecutionWarnings);
# loop through the report execution parameters
foreach($Parameter in $ExecutionInfo.Parameters)
{
# create new item parameter object
$ItemParameter = New-Object "$ReportServerProxyNamespace.ItemParameter";
# fill in the properties except valid values, that one needs special processing
Copy-ObjectProperties -SourceObject $Parameter -TargetObject $ItemParameter;
# fill in the valid values
$ItemParameter.ValidValues = Convert-ValidValues -SourceValidValues $Parameter.ValidValues;
# add to list
$ReportParameters += $ItemParameter;
}
# force the parameters to update
Write-Host "Updating report parameters for $ReportFolder/$ReportName"
if ($IsReportService2005) {
$ReportServerProxy.SetReportParameters("$ReportFolder/$ReportName", $ReportParameters);
}
elseif ($IsReportService2010) {
$ReportServerProxy.SetItemParameters("$ReportFolder/$ReportName", $ReportParameters);
}
else { Write-Warning 'Report Service Unknown in Update-ReportParameters method. Use ReportService2005 or ReportService2010.' }
}
Anyone knows how I could sort it out?
I have solved a similar problem but took a slightly different approach. Rather than using powershell and octopus directly I used the useful open source tool RSBuild to deploy the reports. It is pretty easy to bundle up the rsbuild.exe executable (it is tiny) and a deploy.config along with your reports inside the octopus package. Then you can use octopus's substitution feature to rewrite the config file and Powershell function to execute the executable. This also has the advantage that you can deploy easily without octopus, the config for data sources and reports is declarative in XML rather than procedural in Powershell and the smarts of your scripted deployment can live alongside your reports rather than buried in Octopus.
So my config looks a bit like:
<?xml version="1.0" encoding="utf-8" ?>
<Settings>
<Globals>
<Global Name="CollapsedHeight">0.5in</Global>
</Globals>
<ReportServers>
<ReportServer Name="RS1" Protocol="http" Host="${ReportServer}" Path="${ReportServerPath}" Timeout="30" />
</ReportServers>
<DataSources>
<DataSource Name="Source1" Publish="true" Overwrite="true" TargetFolder="Data Sources" ReportServer="RS1">
<ConnectionString>data source=${ReportServer};initial catalog=${DatabaseName}</ConnectionString>
<CredentialRetrieval>Store</CredentialRetrieval>
<WindowsCredentials>False</WindowsCredentials>
<UserName>${RepotrUser}</UserName>
<Password>${ReportsPassword}</Password>
</DataSource>
</DataSources>
<Reports>
<ReportGroup Name="Details" DataSourceName="Source1" TargetFolder="Reports"
ReportServer="RS1" CacheTime="10080">
<Report Name="BusinessReportABC">
<FilePath>reports\BusinessReportABC.rdl</FilePath>
</Report>
<!--More reports here-->
</ReportGroup>
</Reports>
</Settings>
My deployed octopacked artefacts contain RSBuild.Core.dll, RSBuild.exe, deploy.config and the reports files
Then I simply call the executable using powershell:
PS> rsbuild deploy.config

File is not getting found in powershell Import-AzurePublishSettingsFile

I am using Powershell for Build Deployment. I am struggling with this line of the code:
$pubsettings = "\\Myserver\AzureScripts\default.publishsettings"
Import-AzurePublishSettingsFile $pubsettings
\\Myserver\AzureScripts\default.publishsettings actually maps to D:\\AzureScripts\default.publishsettings on MyServer
Following are scenarios:
Working directory = \\Myserver\AzureScripts and $pubsettings = "\\Myserver\AzureScripts\default.publishsettings"
Result: File Not Found (System.Exception)
Working directory = \\Myserver\AzureScripts and $pubsettings = "D:\\AzureScripts\default.publishsettings"
Result: File Not Found (System.Exception)
Working directory = D:\\AzureScripts and $pubsettings = "D:\\AzureScripts\default.publishsettings"
Result: File Not Found (System.Exception)
Working directory = D:\\AzureScripts and $pubsettings = "\\Myserver\AzureScripts\default.publishsettings"
Result: File Not Found (System.Exception)
Working directory = \\Myserver\AzureScripts and $pubsettings = ".\default.publishsettings"
Result: File Not Found (System.Exception)
Working directory = D:\\AzureScripts and $pubsettings = ".\default.publishsettings"
Result: Sucessfully File is imported
So My Questions are:
Why First five scenarios are failing and only sixth is passing even though all are equivalent?
How do make 6th case to work like 1st scenario using absolute UNC path?
Try this:
Add-AzureAccount
Get-AzurePublishSettingsFile
Import-AzurePublishSettingsFile "C:\AZURE\azure\xyz.publishsettings"
with xyz.publishsetting file being your publishsetting file.
Note here file-path should be inside quotes and there should not be any empty space in between.