proc runTest { testDir testFile } {
    global argc argv

    set saveDir [pwd]
    cd $testDir

    if { $::tcl_platform(platform) eq "windows" } {
        set tclsh "tclsh.exe"
    } else {
        set tclsh "tclsh"
    }
    puts "Running test $testFile ..."
    catch {exec $tclsh $testFile}

    cd $saveDir
}

proc getTestName { num } {
    return [format "Example%s" $num]
}

set testList { "02" "02a" "03" "04" "05" "06" "07" "09" "10" "11" "12" "13" "14" }

set startInd 0
set endInd   [expr [llength $testList] - 1]

if { $argc == 1 } {
    set startInd [lsearch -ascii $testList [lindex $argv 0]]
    set endInd   [lsearch -ascii $testList [lindex $argv 0]]
} elseif { $argc > 1 } {
    set startInd [lsearch -ascii $testList [lindex $argv 0]]
    set endInd   [lsearch -ascii $testList [lindex $argv 1]]
}

set curInd 0
foreach testNum $testList {
    if { $curInd >= $startInd && $curInd <= $endInd } {
        set testName [getTestName $testNum]
        runTest $testName "$testName.tcl"
    }
    incr curInd
}
exit 0
