# 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
            }
            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 {
    ParseCtRevs filename /Bepa 2
} -result {/Bepa/2}

test rev-1.2 {
    ClearCase revisions
} -body {
    ParseCtRevs filename /Bepa 22
} -result {/Bepa/22}

test rev-1.3 {
    ClearCase revisions
} -body {
    ParseCtRevs filename /Bepa Bepa/12
} -result {/Apa/Bepa/12}

test rev-1.4 {
    ClearCase revisions
} -body {
    ParseCtRevs filename /Bepa Cepa/2
} -result {/Apa/Cepa/2}

test rev-1.5 {
    ClearCase revisions
} -body {
    ParseCtRevs filename /Apa/Bepa/Cepa ../5
} -result {/Apa/Bepa/5}

test rev-1.6 {
    ClearCase revisions
} -body {
    ParseCtRevs filename /Apa/Bepa ""
} -result {/Apa/Bepa/12}

test rev-1.7 {
    ClearCase revisions
} -body {
    ParseCtRevs filename /Apa/Bepa -1
} -result {/Apa/Bepa/11}

test rev-1.8 {
    ClearCase revisions
} -body {
    ParseCtRevs filename /Apa/Bepa Apa/-3
} -result {/Apa/19}

test rev-1.9 {
    ClearCase revisions
} -body {
    ParseCtRevs filename /Apa/Cepa -5
} -result {/Apa/Cepa/0}

test rev-2.1 {
    Detecting, CVS
} -body {
    detectRevSystem apa
} -result {CVS}

test rev-2.2 {
    Detecting, CVS
} -body {
    set ::auto_execs(cvs) ""
    detectRevSystem apa
} -result {}

test rev-2.3 {
    Detecting, RCS
} -body {
    file mkdir RCS
    set ch [open RCS/apa,v w]
    puts $ch x
    close $ch
    detectRevSystem apa
} -result {RCS}

test rev-2.4 {
    Detecting, RCS
} -body {
    set ::auto_execs(rcs) ""
    detectRevSystem apa
} -cleanup {
    file delete -force RCS
} -result {}

test rev-2.5 {
    Detecting, CT
} -body {
    set ::auto_execs(cleartool) "x"
    unset -nocomplain ::ct_pwv
    detectRevSystem apa
} -result {}

test rev-2.6 {
    Detecting, CT
} -body {
    set ::auto_execs(cleartool) "x"
    set ::ct_pwv "** NONE **"
    detectRevSystem apa
} -cleanup {
    file delete -force RCS
} -result {}

test rev-2.7 {
    Detecting, CT
} -body {
    set ::auto_execs(cleartool) "x"
    set ::ct_pwv "gurka"
    detectRevSystem apa
} -cleanup {
    file delete -force RCS
} -result {CT}
