How do I skip all tests in a subtest if windows? - windows

I tried this, but it doesn't seem to work
subtest 'catalyst scripts that should be executable' => sub {
plan({ skip_all => 'skip failing executable tests on windows' }) if $^O eq 'MSWin32';
my $should_exec = [ #{ $dzpcs->scripts } ];
foreach ( #{ $should_exec } ) {
ok ( -x $_ , "$_" . ' is executable' );
}
};
Here's what I got in my cpants report.
plan() doesn't understand HASH(0x286f4cc) at t/02-MintingProfileCatalyst.t line 46.
# Child (catalyst scripts that should be executable) exited without calling finalize()
# Failed test 'catalyst scripts that should be executable'
# at C:/strawberry/perl/lib/Test/Builder.pm line 252.
# Tests were run but no plan was declared and done_testing() was not seen.
So I guess it's not a hash, not really sure what it is then... what's the cleanest way to make this work? (p.s. I can't test win32, I only have my Linux box)

plan takes two parameters, not a hashref:
plan( skip_all => 'skip failing executable tests on windows' ) if $^O eq 'MSWin32';
Not everything uses Moose. ;-)
Note: for testing purposes, you could change eq to ne, so it will skip the tests on your Linux box. Just remember to change it back afterwards.

Related

Gradle execute a command with spaces and pipe output while running

I am trying to do an Xcode build in Gradle. Requirements:
Some of my arguments have spaces in them.
I want to pipe the output through xcpretty. Otherwise gitlab complains that there is too much output and I can't see any errors toward the end of the build
I don't want to wait for the command to complete before seeing the output. I want to be able to watch it build, like any ci job
Gradle exec{} doesn't seem to let me pipe the output while building. I can save the output to a file but that doesn't let me watch the build
I.e.,
exec {
executable 'xcodebuild'
ext.output = {
return standardOutput.toString()
}
args = [
'archive',
'-project',
"${buildDir}/iPhone/Unity-iPhone.xcodeproj/",
"-archivePath",
"${buildDir}/iPhone/Unity-iPhone.xcarchive",
"-sdk", "iphoneos",
"GCC_GENERATE_DEBUGGING_SYMBOLS=YES",
"DEBUG_INFORMATION_FORMAT=dwarf-with-dsym",
"DWARF_DSYM_FILE_SHOULD_ACCOMPANY_PRODUCT=NO",
"DWARF_DSYM_FOLDER_PATH=iOS_Dsym",
"DEBUGGING_SYMBOLS=YES",
"DEVELOPMENT_TEAM=RPGSNMH65P",
"CODE_SIGN_IDENTITY=${appleIdentity}",
"CODE_SIGN_STYLE=Manual",
"USYM_UPLOAD_AUTH_TOKEN=${appcenter_login_token}",
"PROVISIONING_PROFILE_SPECIFIER_APP=${provisioningProfile}",
"-configuration", "Release",
"-scheme", "${schemeName}",
"| xcpretty"
]
}
doesn't work
I can't use groovy "xcodebuild ... CODE_SIGN_IDENTITY=${"${appleIdentity}"} ... | xcpretty".execute() because my code signing identity contains spaces and for some reason groovy wants to stick its own quotes into the command string when it finds spaces.
I tried the array execute method but ended up with the same problem.
def cmd = [
'xcodebuild ',
'archive',
'-project',
"${buildDir}/iPhone/Unity-iPhone.xcodeproj/",
"-archivePath",
"${buildDir}/iPhone/Unity-iPhone.xcarchive",
"-sdk", "iphoneos",
"GCC_GENERATE_DEBUGGING_SYMBOLS=YES",
"DEBUG_INFORMATION_FORMAT=dwarf-with-dsym",
"DWARF_DSYM_FILE_SHOULD_ACCOMPANY_PRODUCT=NO",
"DWARF_DSYM_FOLDER_PATH=iOS_Dsym",
"DEBUGGING_SYMBOLS=YES",
"DEVELOPMENT_TEAM=RPGSNMH65P",
"CODE_SIGN_IDENTITY=${appleIdentity}",
"CODE_SIGN_STYLE=Manual",
"USYM_UPLOAD_AUTH_TOKEN=${appcenter_login_token}",
"PROVISIONING_PROFILE_SPECIFIER_APP=${provisioningProfile}",
"-configuration", "Release",
"-scheme", "${schemeName}"
]
println cmd
def proc = cmd.execute()
... except that it's even harder to debug because I can't see the actual command being executed.
I have found various solutions online but nothing that fits these requirements

Terminate / Skip / Stop all tests from all spec files if any one test fails in cypress

am trying to skip all other tests from all spec files if one test fails and found a working solution over here Is there a reliable way to have Cypress exit as soon as a test fails?. However, this looks to be working only if the test fails in it() assertions. How can we skip the tests if somethings fails in beforeach()
For eg:
before(() => {
cy.get('[data-name="email-input"]').type(email);
cy.get('[data-name="password-input"]').type(email);
cy.get('[data-name="account-save-btn"]').click();
});
And if something goes wrong (for eg: CypressError: Timed out retrying: Expected to find element: '[data-name="email-input"]', but never found it.) in above code then stop/ skip all tests in all spec files.
Just in case anyone is looking answer for the same question. I have found a solution and would like to share.
To implement the solution I have used a cookie that I will set to value true if something fails and before executing each test cypress will check the value of cookie. If the value of cookie is true it skips the test.
Cypress.on('fail', error => {
document.cookie = "shouldSkip=true" ;
throw error;
});
function stopTests() {
cy.getCookie('shouldSkip').then(cookie => {
if (cookie && typeof cookie === 'object' && cookie.value === 'true') {
Cypress.runner.stop();
}
});
}
beforeEach(stopTests);
Also to note: Tests should be written in it() block and avoid using before() to write tests
As of Cypress 10, tests don't run if before or beforeEach hook fails.

Where is the ruby function 'powershell' defined?

I am using the msutter DSC module for puppet. While reading through the source code, I come across code like this (in dsc_configuration_provider.rb):
def create
Puppet.debug "\n" + ps_script_content('set')
output = powershell(ps_script_content('set'))
Puppet.debug output
end
What file defines the powershell function or method? Is it a ruby builtin? A puppet builtin? Inherited from a class? I know that it is being used to send text to powershell as a command and gathering results, but I need to see the source code to understand how to improve its error logging for my purposes, because certain powershell errors are being swallowed and no warnings are being printed to the Puppet log.
These lines in file dsc_provider_helpers.rb may be relevant:
provider.commands :powershell =>
if File.exists?("#{ENV['SYSTEMROOT']}\\sysnative\\WindowsPowershell\\v1.0\\powershell.exe")
"#{ENV['SYSTEMROOT']}\\sysnative\\WindowsPowershell\\v1.0\\powershell.exe"
elsif File.exists?("#{ENV['SYSTEMROOT']}\\system32\\WindowsPowershell\\v1.0\\powershell.exe")
"#{ENV['SYSTEMROOT']}\\system32\\WindowsPowershell\\v1.0\\powershell.exe"
else
'powershell.exe'
end
Surely this defines where the Powershell executable is located, but gives no indication how it is called and how its return value is derived. Are stdout and stderr combined? Am I given the text output or just the error code? etc.
This is core Puppet logic. When a provider has a command, like
commands :powershell => some binary
That is hooked up as a function powershell(*args).
You can see it with other providers like Chocolatey:
commands :chocolatey => chocolatey_command
def self.chocolatey_command
if Puppet::Util::Platform.windows?
# must determine how to get to params in ruby
#default_location = $chocolatey::params::install_location || ENV['ALLUSERSPROFILE'] + '\chocolatey'
chocopath = ENV['ChocolateyInstall'] ||
('C:\Chocolatey' if File.directory?('C:\Chocolatey')) ||
('C:\ProgramData\chocolatey' if File.directory?('C:\ProgramData\chocolatey')) ||
"#{ENV['ALLUSERSPROFILE']}\chocolatey"
chocopath += '\bin\choco.exe'
else
chocopath = 'choco.exe'
end
chocopath
end
Then other locations can just call chocolatey like a function with args:
chocolatey(*args)

Why won't gradle Exec task run my command?

I have read around stackoverflow and the gradle forms, but I am still stumped. The ultimate goal here is that after I copy some files, I want to set the writable flag -- because 'copy' doesn't like overwriting read-only files on 'nix (huh...), nor can it be forced to do so (harumph!).
Here is the outline of what I have:
task setPermissions (type : Exec) {
executable = 'chmod -R +w'
}
// ... a little while later ...
task('somethingElse') << {
// ... unrelated stuff ...
def String targetDir = "$aVar/theTarget"
// >> TASK CALL <<
setPermissions {
commandLine = [executable + " $targetDir"]
}
// but that doesn't work... this does...
proc = Runtime.getRuntime().exec("chmod -R +w $deployDir")
proc.waitFor()
}
I have tried variations in "setPermissions".
Trial 1:
commandLine = 'chmod'
args = '-R', '+w'
In which case I appended the target directory to "args" when I called setPermissions.
Trial 2:
commandLine = 'chmod -R +w'
In which case I appended the target directory to "commandLine" when I called setPermissions. I also tried making it the only "args" value.
Trial 3:
commandLine = 'chmod', '-R', '+w'
In which case I appended the target directory to "commandLine" when I called setPermissions. I also tried making it the only "args" value.
So what am I doing wrong here that an Exec task won't run this properly, but the Rt.gR.exec() will?
You can't call a task from another task. You'll have to make one depend on the other, or call the Project.exec method from a task action. The syntax for configuring the exec method is exactly the same as for the Exec task.
PS: Have you tried to use Copy.fileMode instead of chmod?

How to continue a Jenkins build even though a build step failed?

I am using a Phing build script with Jenkins and would like to run it end to end on a job and capture all the reports. The problem is it stop building on a failed build step. Is there a way or a plugin that would continue the job even on failures?
Thanks
I don't know a lot about Phing but, since it's based on Ant, if the build step you are executing has a "failonerror" attribute you should be able to set it to false so that the entire build doesn't fail if the step returns an error.
Yes, use try, catch block in you pipeline scripts
example:
try {
// do some stuff that potentially fails
} catch (error) {
// do stuff if try fails
} finally {
// when you need some clean up to do
}
Or alternatively if you use sh commands to run these tests, consider running your sh scripts with the "|| true" suffix, this tells the linux sh script to exit with a result code of 0, even if your real command exited with an exit code.
example:
stage('Test') {
def testScript = ""
def testProjects = findFiles(glob: 'test/**/project.json')
if (!fileExists('reports/xml')) {
if (!fileExists('reports')) {
sh "mkdir reports"
}
sh "mkdir reports/xml"
}
for(prj in testProjects) {
println "Test project located, running tests: " + prj.path
def matcher = prj.path =~ 'test\\/(.+)\\/project.json'
testScript += "dotnet test --no-build '${prj.path}' -xml 'reports/xml/${matcher[0][1]}.Results.xml' || true\n"
}
sh testScript

Resources