Unpacking Software Livestream

Join our monthly Unpacking Software livestream to hear about the latest news, chat and opinion on packaging, software deployment and lifecycle management!

Learn More

Chocolatey Product Spotlight

Join the Chocolatey Team on our regular monthly stream where we put a spotlight on the most recent Chocolatey product releases. You'll have a chance to have your questions answered in a live Ask Me Anything format.

Learn More

Chocolatey Coding Livestream

Join us for the Chocolatey Coding Livestream, where members of our team dive into the heart of open source development by coding live on various Chocolatey projects. Tune in to witness real-time coding, ask questions, and gain insights into the world of package management. Don't miss this opportunity to engage with our team and contribute to the future of Chocolatey!

Learn More

Calling All Chocolatiers! Whipping Up Windows Automation with Chocolatey Central Management

Webinar from
Wednesday, 17 January 2024

We are delighted to announce the release of Chocolatey Central Management v0.12.0, featuring seamless Deployment Plan creation, time-saving duplications, insightful Group Details, an upgraded Dashboard, bug fixes, user interface polishing, and refined documentation. As an added bonus we'll have members of our Solutions Engineering team on-hand to dive into some interesting ways you can leverage the new features available!

Watch On-Demand
Chocolatey Community Coffee Break

Join the Chocolatey Team as we discuss all things Community, what we do, how you can get involved and answer your Chocolatey questions.

Watch The Replays
Chocolatey and Intune Overview

Webinar Replay from
Wednesday, 30 March 2022

At Chocolatey Software we strive for simple, and teaching others. Let us teach you just how simple it could be to keep your 3rd party applications updated across your devices, all with Intune!

Watch On-Demand
Chocolatey For Business. In Azure. In One Click.

Livestream from
Thursday, 9 June 2022

Join James and Josh to show you how you can get the Chocolatey For Business recommended infrastructure and workflow, created, in Azure, in around 20 minutes.

Watch On-Demand
The Future of Chocolatey CLI

Livestream from
Thursday, 04 August 2022

Join Paul and Gary to hear more about the plans for the Chocolatey CLI in the not so distant future. We'll talk about some cool new features, long term asks from Customers and Community and how you can get involved!

Watch On-Demand
Hacktoberfest Tuesdays 2022

Livestreams from
October 2022

For Hacktoberfest, Chocolatey ran a livestream every Tuesday! Re-watch Cory, James, Gary, and Rain as they share knowledge on how to contribute to open-source projects such as Chocolatey CLI.

Watch On-Demand

Downloads:

500

Downloads of v 1.0:

500

Last Update:

07 Jul 2016

Package Maintainer(s):

Software Author(s):

  • Chantisnake

Tags:

ctest admin chocolatey

ctest

  • 1
  • 2
  • 3

1.0 | Updated: 07 Jul 2016

Downloads:

500

Downloads of v 1.0:

500

Maintainer(s):

Software Author(s):

  • Chantisnake

ctest 1.0

  • 1
  • 2
  • 3

Some Checks Have Failed or Are Not Yet Complete

Not All Tests Have Passed


Validation Testing Failed


Verification Testing Passed

Details

Scan Testing Successful:

No detections found in any package files

Details
Package Approved

This package was approved by moderator ferventcoder on 11 Jul 2016.

WARNING

This package is unlisted and hidden from package listings.

Description

This is a testing utility for you chocolatey package.

When you run ctest, you need to give it a path.
Then ctest script will index all the file in that folder recursively.

Then it will match all the *.nuspec file and do choco pack on the *.nuspec file respectively.

Then try to install and uninstall all the packed chocolatey package.

you can find this project at github: https://github.com/chantisnake/ctest


tools\chocolateyinstall.ps1
$path = Join-Path $(Split-Path -parent $MyInvocation.MyCommand.Definition) 'ctest.ps1'

Install-ChocolateyPowershellCommand -PackageName 'ctest' -PSFileFullPath $path
tools\ctest.ps1
param (
    [string] $Path = './',
    [switch] $pre,
    [switch] $Run,
    [Switch] $Continue
)

$chocoFilePath = 'choco'

function Test-Admin { 
    $identity = [System.Security.Principal.WindowsIdentity]::GetCurrent() 
    $principal = new-object System.Security.Principal.WindowsPrincipal($identity) 
    $admin = [System.Security.Principal.WindowsBuiltInRole]::Administrator 
    $principal.IsInRole($admin) 
} 


function Get-Files($path = $pwd) 
{ 
    foreach ($item in Get-ChildItem $path)
    {

        if (Test-Path $item.FullName -PathType Container) 
        {
            $item
            Get-Files -path $item.FullName
        } 
        else 
        { 
            $item
        }
    } 
}

function Start-PackTest($packagePath, $packageName) {
    Write-Host ''
    Write-Host 'starting packing test' -ForegroundColor Magenta

    $location = Get-Location
    Set-Location $packagePath

    # run command
    $process = Start-Process -FilePath $chocoFilePath -ArgumentList 'pack' -NoNewWindow -Wait -ErrorAction Stop -PassThru
    $exitCode = $process.ExitCode

    # see if command is successful 
    if ($exitCode -eq 0) {
        Write-Host ''
        Write-Host "choco pack for package " -NoNewline -ForegroundColor Green
        Write-Host $packageName -ForegroundColor Magenta -NoNewline
        Write-Host " exit normally with exit code 0" -ForegroundColor Green
        $exitOption = Read-Host 'press q to quit, press Enter to continue'
        $exitOption
    }
    else {
        Write-Host ''
        Write-Warning "choco pack for package $packageName fail with exit code $exitCode"
        $exitOption = Read-Host 'press q to quit, press Enter to continue'
        $exitOption
    }

    Set-Location $location

}

function Start-InstallTest ($packagePath ,$packageName) {
    Write-Host ''
    Write-Host 'starting install test' -ForegroundColor Magenta

    $location = Get-Location
    Set-Location $packagePath

    # run command
    if($pre){
        $process = Start-Process -FilePath $chocoFilePath -ArgumentList "install $packageName -fdv -s $pwd -pre" -NoNewWindow -Wait -ErrorAction Stop -PassThru
    }
    else {
        $process = Start-Process -FilePath $chocoFilePath -ArgumentList "install $packageName -fdv -s $pwd" -NoNewWindow -Wait -ErrorAction Stop -PassThru
    }
    $exitCode = $process.ExitCode

    # see if command is successful 
    if ($exitCode -eq 0) {
        Write-Host ''
        Write-Host "choco install for package " -NoNewline -ForegroundColor Green
        Write-Host $packageName -ForegroundColor Magenta -NoNewline
        Write-Host " exit normally with exit code 0" -ForegroundColor Green
        $exitOption = Read-Host 'press q to quit, press Enter to continue'
        $exitOption
    }
    else {
        Write-Host ''
        Write-Warning "choco install for package $packageName fail with exit code $exitCode"
        $exitOption = Read-Host 'press q to quit, press Enter to continue'
        $exitOption
    }

    # go back to starting location
    Set-Location $location
}

function Start-UninstallTest ($packagePath, $packageName) {
    Write-Host ''
    Write-Host 'starting uninstall test' -ForegroundColor Magenta

    # run command
    $process = Start-Process -FilePath $chocoFilePath -ArgumentList "uninstall $packageName -debug" -NoNewWindow -Wait -ErrorAction Stop -PassThru
    $exitCode = $process.ExitCode

    # see if command is successful 
    if ($exitCode -eq 0) {
        Write-Host ''
        Write-Host "choco uninstall for package " -NoNewline -ForegroundColor Green
        Write-Host $packageName -ForegroundColor Magenta -NoNewline
        Write-Host " exit normally with exit code 0" -ForegroundColor Green
        $exitOption = Read-Host 'press q to quit, press Enter to continue'
        $exitOption
    }
    else {
        Write-Host ''
        Write-Warning "choco uninstall for package $packageName failed with exit code $exitCode"
        $exitOption = Read-Host 'press q to quit, press Enter to ignore the error and continue'
        $exitOption
    }

}

function Start-ChocoPush ($packagePath) {
    $location = Get-Location
    Set-Location $packagePath
    $process = Start-Process -FilePath $chocoFilePath -ArgumentList 'push' -NoNewWindow -Wait -ErrorAction Stop -PassThru
    if ($process.ExitCode -eq 0) {
        Write-Host 'push Successful' -ForegroundColor Green
    }
    else {
        Write-Warning 'Push have failed, you may need to mannul push later'
    }
    Set-Location $location
}

function Invoke-CTestCore ($infoObject) {
    foreach ($package in $infoObject.psobject.properties) {
        # get basic info
        $packagePath = [System.IO.Path]::GetDirectoryName($package.name)
        $packageName = [System.IO.Path]::GetFileNameWithoutExtension($package.name)

        Write-Host ''
        Write-Host 'starting to test package with the name' -ForegroundColor Green
        Write-Host $packageName -ForegroundColor Green

        # starts packing test
        if ($package.Value.packed) {
            Write-Host 'Package has passed the pack test'
        }
        else {
            $exitOption = Start-PackTest -packagePath $packagePath -packageName $packageName
            # handle exit option
            if ($exitOption -eq 'q') {
                # save infoDict and exit
                $infoObject | ConvertTo-Json > ./ctest_profile
                Write-Host 'info saved, you can run `ctest <path> -continue` to restore the test' -ForgroundColor Green
                return
            }
            else {
                # update infoDict
                $package.Value.packed = $true
            }
        }
        
        # start installing package
        if ($package.Value.install) {
            Write-Host 'Package has passed the install test'
        }
        else {
            $exitOption = Start-InstallTest -packagePath $packagePath -packageName $packageName
            # handle exit option
            if ($exitOption -eq 'q') {
                # save infoDict and exit
                $infoObject | ConvertTo-Json > ./ctest_profile
                Write-Host 'info saved, you can run `ctest <path> -continue` to restore the test' -ForgroundColor Green
                return
            }
            else {
                # update infoDict
                $package.Value.install = $true
            }
        }
        

        # start uninstall test
        if ($package.Value.uninstall) {
            Write-Host 'Package has passed the uninstall test'
        }
        else {
            $exitOption = Start-UninstallTest -packageName $packageName
            # handle exit option
            if ($exitOption -eq 'q') {
                # save infoDict and exit
                $infoObject | ConvertTo-Json > ./ctest_profile
                Write-Host 'info saved, you can run `ctest <path> -continue` to restart the test' -ForgroundColor Green
                return
            }
            else {
                # update infoDict
                $package.Value.uninstall = $true
            }
        }  
    }

    Write-Host 'Test finished' -ForegroundColor Green

    Write-Host 'All test is passed, do you want to push?' -ForegroundColor Magenta
    $option = Read-Host 'Press [Y]es to push, everything else will exit the script'
    if ($option.ToLower() -eq 'y' -or $option.ToLower() -eq 'yes') {
        Start-ChocoPush -packagePath $packagePath
    }

    Write-Host 'do you want to reinstall the package in case you need to use it?' 
    $option = Read-Host 'press enter to reinstall, input q to exit'
    if ($option.ToLower() -ne 'q' -and $option.ToLower() -ne 'quit') {
         Start-InstallTest -packagePath $packagePath -packageName $packageName
    }

}

function Start-CTest {

    Write-Host ''
    Write-Host 'indexing the directory' -ForegroundColor Green
    Write-Host 'this can take super long time if you are running in huge dir' -ForegroundColor Magenta
    Write-Host 'so Please do not start this script in a huge dir' -ForegroundColor Magenta

    $files = Get-Files -path $PWD

    $nuspecFiles = $files| where {$_.name -match '.*\.nuspec'}

    Write-Host ''
    Write-Host 'here is all the nuspec file I have found' -ForegroundColor Green
    Write-Host $nuspecFiles -ForegroundColor Magenta
    Write-Host 'we will start testing with all these files'
    Read-Host 'Press Enter to Continue'

    Write-Host ''
    Write-Host 'initializing test' -ForegroundColor Magenta
    $default = @{'packed' = $false; 'install'= $false; 'uninstall'=$false}

    # creating info object
    $infoObject = New-Object -TypeName psobject
    foreach ($file in $nuspecFiles) {
        Add-Member -InputObject $infoObject -MemberType NoteProperty -Name $file.FullName -Value $default
    }
    Write-Host 'infoObject is initiated' -ForegroundColor Magenta

    Invoke-CTestCore $infoObject

}

function Resume-CTest {

    # reading the infoDict
    Write-Host 'Reading the old profile'
    $infoObject = Get-Content ./ctest_profile | ConvertFrom-Json
    
    Invoke-CTestCore -infoObject $infoObject

}

function Initialize-ResumedCTest {

    Write-Host 'Trying to find the old Profile'
    if (-Not (Test-Path ./ctest_profile)) {
        Write-Warning 'previous ctest profile not found.' 
        Write-Warning 'Starting a new test'
        Start-CTest
    }
    else {
        Write-Host 'old Profile found'
        Resume-CTest 
    }
}

function Initialize-AutoCTest{

    if(Test-Path ./ctest_profile) {
        Write-Host 'found the old test profile' -ForegroundColor Magenta
        Write-Host 'Do you want to continue the old test?' -ForegroundColor Magenta
        $option = Read-Host 'enter [Y]es for continue else we will start a new test'
        if ($option.ToLower -eq 'yes' -or $option.ToLower() -eq 'y') {
            Write-Host 'continue the old test' -ForgroundColor Magenta
            Resume-CTest
        }
        else {
            Write-Host 'removing the old test profile' -ForegroundColor Magenta
            Remove-Item ./ctest_profile
            Write-Host 'starting a new test' -ForgroundColor Magenta
            Start-CTest
        }
    }
    else {
        Write-Host 'cannot find the old test profile' -ForegroundColor Magenta
        Write-Host 'starting a new test' -ForegroundColor Magenta
        Start-CTest
    }

}

####################################################
# MAIN
####################################################

if (-Not (Test-Admin)) {
    Write-Warning 'You are not running in admin. Your test may fail'
    Read-Host 'Press Ctrl-C to quit, Press Enter to ignore the warning and continue'
}

$location = Get-Location

Set-Location $path

if ($Run) {
    Start-CTest
}
elseif ($Continue) {
    Initialize-ResumedCTest
}
else {
    Initialize-AutoCTest
}

Set-Location $location

Write-Host 'exiting the script. Have a Nice day' -ForegroundColor Green



Log in or click on link to see number of positives.

In cases where actual malware is found, the packages are subject to removal. Software sometimes has false positives. Moderators do not necessarily validate the safety of the underlying software, only that a package retrieves software from the official distribution point and/or validate embedded software against official distribution point (where distribution rights allow redistribution).

Chocolatey Pro provides runtime protection from possible malware.

Add to Builder Version Downloads Last Updated Status

This package has no dependencies.

Discussion for the ctest Package

Ground Rules:

  • This discussion is only about ctest and the ctest package. If you have feedback for Chocolatey, please contact the Google Group.
  • This discussion will carry over multiple versions. If you have a comment about a particular version, please note that in your comments.
  • The maintainers of this Chocolatey Package will be notified about new comments that are posted to this Disqus thread, however, it is NOT a guarantee that you will get a response. If you do not hear back from the maintainers after posting a message below, please follow up by using the link on the left side of this page or follow this link to contact maintainers. If you still hear nothing back, please follow the package triage process.
  • Tell us what you love about the package or ctest, or tell us what needs improvement.
  • Share your experiences with the package, or extra configuration or gotchas that you've found.
  • If you use a url, the comment will be flagged for moderation until you've been whitelisted. Disqus moderated comments are approved on a weekly schedule if not sooner. It could take between 1-5 days for your comment to show up.
comments powered by Disqus