Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generated test for VOID method still tests for a return type #122

Open
Stephanevg opened this issue Sep 18, 2019 · 1 comment
Open

Generated test for VOID method still tests for a return type #122

Stephanevg opened this issue Sep 18, 2019 · 1 comment
Labels
Begginer friendly bug Something isn't working hacktoberfest Good first use to gain a PR for Hacktoberfest

Comments

@Stephanevg
Copy link
Owner

Stephanevg commented Sep 18, 2019

Regarding this class below.

The SetVersionType (and for that matter all the void methods) still have a test to test their return type.

When a method has no return type the test to test for the type should not be generated.

See use case below.

Class PCCPackage {
    [String]$Name
    [version]$Version
    [system.io.DirectoryInfo]$Path
    [String]$OS
    [String]$Type
    [String]$Platform

    PCCPAckage(){

    }

    PccPAckage([String]$Path){
        $P = [System.Io.DirectoryInfo]::New($Path)
        If($P.Exists){
            if(!($P.Name.ToString().ToUpper().StartsWith("PCC.CHK"))){
                Throw "the module folder doesn't start with the required prefexi 'PCC.CHK'!"
            }
            $this.Path = $P
            $this.Name = $p.Name.ToUpper()
            $this.SetValues()
        }else{
            Throw "$($Path) not present"
        }
    }

    PCCPackage([String]$Name,[String]$Path){
        $this.Name = $Name
        $this.Path = $Path
        $This.SetValues()
        
    }

    SetValues(){
        $this._SetVersion()
        $this._SetPlatform()
        $this._SetOS()
        $this._SetType()
    }

    Hidden _SetVersion(){
        try{

            $ver = (Get-Module $this.Path.FullName -ListAvailable -ErrorAction Stop).Version.ToString() 
        }Catch{
            $ver = $null
        }
        $this.Version = $ver
    }

    hidden _SetPlatform(){
        $p =  $this.Name.Split(".")[2]
        $This.Platform =$p
    }

    hidden _SetOS(){
        
        $this.OS = $this.Name.Split(".")[3]
    }

    Hidden _SetType(){
        $t = $this.Name.Split(".")[4]
        $This.Type = $t
    }

    Hidden [String] GetOS(){
        return $this.Os
         
    }

    [String] GetPath(){
        REturn $this.Path.Full
    }
    [version] GetVersion(){
        return $this.version
    }
}

See the _SEtVersion() test

#Public Method
It '[PCCPackage] --> _SetVersion() :  - should return type []' {

# -- Arrange

# -- Act

$Instance = [PCCPackage]::New()
# -- Assert

($Instance._SetVersion()).GetType().Name | should be 

} #End It Block
@Stephanevg Stephanevg added bug Something isn't working hacktoberfest Good first use to gain a PR for Hacktoberfest Begginer friendly labels Sep 18, 2019
@Stephanevg
Copy link
Owner Author

Adding the return types (even VOID ones) actually fixes this issue:

image

We need to implement the same behaviour as for the [VOID] for the NotDefinedreturntypes (which is in the end [VOID]

Si this code exapmle with [VOID]

Class PCCPackage {
    [String]$Name
    [version]$Version
    [system.io.DirectoryInfo]$Path
    [String]$OS
    [String]$Type
    [String]$Platform

    PCCPAckage(){

    }

    PccPAckage([String]$Path){
        $P = [System.Io.DirectoryInfo]::New($Path)
        If($P.Exists){
            if(!($P.Name.ToString().ToUpper().StartsWith("PCC.CHK"))){
                Throw "the module folder doesn't start with the required prefexi 'PCC.CHK'!"
            }
            $this.Path = $P
            $this.Name = $p.Name.ToUpper()
            $this.SetValues()
        }else{
            Throw "$($Path) not present"
        }
    }

    PCCPackage([String]$Name,[String]$Path){
        $this.Name = $Name
        $this.Path = $Path
        $This.SetValues()
        
    }

    [void]SetValues(){
        $this._SetVersion()
        $this._SetPlatform()
        $this._SetOS()
        $this._SetType()
    }

    Hidden [void]_SetVersion(){
        try{

            $ver = (Get-Module $this.Path.FullName -ListAvailable -ErrorAction Stop).Version.ToString() 
        }Catch{
            $ver = $null
        }
        $this.Version = $ver
    }

    hidden [void] _SetPlatform(){
        $p =  $this.Name.Split(".")[2]
        $This.Platform =$p
    }

    hidden [void] _SetOS(){
        
        $this.OS = $this.Name.Split(".")[3]
    }

    Hidden [void] _SetType(){
        $t = $this.Name.Split(".")[4]
        $This.Type = $t
    }

    Hidden [String] GetOS(){
        return $this.Os
         
    }

    [String] GetFullPath(){
        REturn $this.Path.FullName
    }
    [version] GetVersion(){
        return $this.version
    }
}

vikingtiger added a commit to vikingtiger/PSClassUtils that referenced this issue Oct 20, 2019
Methods with undefined return types should be treated like void methods
vikingtiger added a commit to vikingtiger/PSClassUtils that referenced this issue Oct 20, 2019
Methods with undefined return type should be treated like void methods.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Begginer friendly bug Something isn't working hacktoberfest Good first use to gain a PR for Hacktoberfest
Projects
None yet
Development

No branches or pull requests

1 participant