# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

package require tcltest 2
namespace import tcltest::*

set pwd [file dirname [file normalize $argv0]]

source ../port_test_autoconf.tcl
package require macports 1.0

array set ui_options {}
#set ui_options(ports_debug)   yes
#set ui_options(ports_verbose) yes
mportinit ui_options

package require portdistcheck 1.0
source ./library.tcl
macports_worker_init


set distcheck_fixture_setup {
    set portpath $pwd
    set filespath $pwd/files

    # dummy env values to satisfy mirror_sites.tcl
    set os.platform darwin
    set os.major 10

    set name gcc_select
    set subport $name
    set distname select-0.1
    set porturl "http://distfiles.macports.org/gcc_select/"
    set master_sites $porturl
    set extract.suffix .tar.gz
    set fetch.type standard
    set license ""

    # replace curl with a mock
    rename curl _save_curl
    proc curl {operation args} {
        global _test_isnewer
        switch $operation {
            isnewer {
                return ${_test_isnewer}
            }
        }
    }
}
set distcheck_fixture_cleanup {
    # restore original curl
    rename curl ""
    rename _save_curl curl
}

test distcheck_moddate_newer {
    Check that files on servers that are newer than the Portfile cause a warning.
} -setup $distcheck_fixture_setup -cleanup $distcheck_fixture_cleanup -body {
    set distcheck.type moddate
    set _test_isnewer 1
    return [portdistcheck::distcheck_main]
} -errorOutput "Warning: port gcc_select: .* is newer than Portfile" -match regexp

test distcheck_moddate_not_newer {
    Check that files on server that are not newer than the Portfile do not cause a warning
} -setup $distcheck_fixture_setup -cleanup $distcheck_fixture_cleanup -body {
    set distcheck.type moddate
    set _test_isnewer 0
    return [portdistcheck::distcheck_main]
} -errorOutput ""


cleanupTests
