# Tests for revision control functions                      -*- tcl -*-
#----------------------------------------------------------------------
# $Revision$
#----------------------------------------------------------------------

# Overload exec during these tests
stub exec {args} {
    set cmd [lindex $args 0]
    switch -- $cmd {
        cleartool {
            # cleartool lshistory -short $filename
            # cleartool pwv -s
            # cleartool get -to $outfile $filerev
            # cleartool ls $::diff($top,RevFile)
            if {[lindex $args 1] eq "lshistory"} {
                return [join [list x@/Apa/Bepa/12 x@/Apa/Cepa/2 x@/Apa/22 x@/Apa] \n]
            }
            if {[lindex $args 1] eq "pwv"} {
                return $::ct_pwv
            }
            if {[lindex $args 1] eq "ls"} {
                return $::ct_ls
            }
            return
        }
        cvs {
            # cvs -z3 update -p ?-r rev? $filename > $outfile
            return
        }
        co {
            # co -p$rev $filename > $outfile
            return
        }
        default {
            eval _stub_exec $args
        }
    }
}

test rev-1.1 {
    ClearCase revisions
} -body {
    set ::ct_ls @@/Bepa/5
    eskil::rev::CT::ParseRevs filename 2
} -result {/Bepa/2}

test rev-1.2 {
    ClearCase revisions
} -body {
    set ::ct_ls @@/Bepa/5
    eskil::rev::CT::ParseRevs filename 22
} -result {/Bepa/22}

test rev-1.3 {
    ClearCase revisions
} -body {
    set ::ct_ls @@/Bepa/5
    eskil::rev::CT::ParseRevs filename Bepa/12
} -result {/Apa/Bepa/12}

test rev-1.4 {
    ClearCase revisions
} -body {
    set ::ct_ls @@/Bepa/5
    eskil::rev::CT::ParseRevs filename Cepa/2
} -result {/Apa/Cepa/2}

test rev-1.5 {
    ClearCase revisions
} -body {
    set ::ct_ls @@/Apa/Bepa/Cepa/7
    eskil::rev::CT::ParseRevs filename ../5
} -result {/Apa/Bepa/5}

test rev-1.6 {
    ClearCase revisions
} -body {
    set ::ct_ls @@/Apa/Bepa/12
    eskil::rev::CT::ParseRevs filename ""
} -result {/Apa/Bepa/12}

test rev-1.7 {
    ClearCase revisions
} -body {
    set ::ct_ls @@/Apa/Bepa/7
    eskil::rev::CT::ParseRevs filename -1
} -result {/Apa/Bepa/11}

test rev-1.8 {
    ClearCase revisions
} -body {
    set ::ct_ls @@/Apa/Bepa/7
    eskil::rev::CT::ParseRevs filename Apa/-3
} -result {/Apa/19}

test rev-1.9 {
    ClearCase revisions
} -body {
    set ::ct_ls @@/Apa/Cepa/7
    eskil::rev::CT::ParseRevs filename -5
} -result {/Apa/Cepa/0}

test rev-2.1 {
    Detecting, CVS
} -body {
    set f [tcltest::makeFile {} _rev2_1]
    detectRevSystem $f
} -cleanup {
    tcltest::removeFile {} _rev2_1
} -result {CVS}

test rev-2.2 {
    Detecting, CVS
} -body {
    set ::auto_execs(cvs) ""
    set f [tcltest::makeFile {} _rev2_2]
    detectRevSystem $f
} -cleanup {
    tcltest::removeFile {} _rev2_2
} -result {}

test rev-2.3 {
    Detecting, RCS
} -body {
    set f [tcltest::makeFile {} _rev2_3]
    file mkdir RCS
    set ch [open RCS/_rev2_3,v w]
    puts $ch x
    close $ch
    set ::auto_execs(rcs) "x"
    detectRevSystem $f
} -cleanup {
    tcltest::removeFile {} _rev2_3
} -result {RCS}

test rev-2.4 {
    Detecting, RCS
} -body {
    set f [tcltest::makeFile {} _rev2_4]
    set ::auto_execs(rcs) ""
    detectRevSystem $f
} -cleanup {
    tcltest::removeFile {} _rev2_4
    file delete -force RCS
} -result {}

test rev-2.5 {
    Detecting, CT
} -body {
    set f [tcltest::makeFile {} _rev2_5]
    set ::auto_execs(cleartool) "x"
    unset -nocomplain ::ct_pwv
    detectRevSystem $f
} -cleanup {
    tcltest::removeFile {} _rev2_5
} -result {}

test rev-2.6 {
    Detecting, CT
} -body {
    set f [tcltest::makeFile {} _rev2_6]
    set ::auto_execs(cleartool) "x"
    set ::ct_pwv "** NONE **"
    detectRevSystem $f
} -cleanup {
    tcltest::removeFile {} _rev2_6
} -result {}

test rev-2.7 {
    Detecting, CT
} -body {
    set f [tcltest::makeFile {} _rev2_7]
    set ::auto_execs(cleartool) "x"
    set ::ct_pwv "gurka"
    detectRevSystem $f
} -cleanup {
    tcltest::removeFile {} _rev2_7
} -result {CT}

test rev-2.8 {
    Detecting, GIT
} -body {
    set f [tcltest::makeFile {} _rev2_8]
    set ::auto_execs(git) "x"
    set apa [file isdirectory .git]
    if {!$apa} {
        file mkdir .git
    }
    set res [detectRevSystem $f]
    if {!$apa} {
        file delete .git
    }
    set res
} -cleanup {
    tcltest::removeFile {} _rev2_8
} -result {GIT}

test rev-2.9 {
    Detecting, HG
} -body {
    set f [tcltest::makeFile {} _rev2_9]
    set ::auto_execs(hg) "x"
    set apa [file isdirectory .hg]
    if {!$apa} {
        file mkdir .hg
    }
    set res [detectRevSystem $f]
    if {!$apa} {
        file delete .hg
    }
    set res
} -cleanup {
    tcltest::removeFile {} _rev2_9
} -result {HG}

test rev-2.10 {
    Detecting, SVN
} -body {
    set f [tcltest::makeFile {} _rev2_10]
    set ::auto_execs(svn) "x"
    set apa [file isdirectory .svn]
    if {!$apa} {
        file mkdir .svn
    }
    set res [detectRevSystem $f]
    if {!$apa} {
        file delete .svn
    }
    set res
} -cleanup {
    tcltest::removeFile {} _rev2_10
} -result {SVN}
