# -*- 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 ../package_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

source ./library.tcl
macports_worker_init

package require portmdmg
package require portmpkg
package require portpkg
source ../../port1.0/port_autoconf.tcl


# test dmg_main


test package_mdmg {
    Package mdmg unit test.
} -constraints {
    darwin
} -setup {
    set os.major ${macports::os_major}
    set os.arch ${macports::os_arch}

    set subport fondu
    set version 060102
    set revision 1
    set package.destpath $pwd/pkg
    set UI_PREFIX >

    file mkdir $pwd/pkg
    close [open $pwd/pkg/fondu-060102_1.mpkg w+]

} -body {
    if {[portmdmg::package_mdmg $subport $version $revision] != 0} {
        return "FAIL: cannot create mdmg"
    }
    if {![file exists $pwd/pkg/fondu-060102_1.dmg]} {
        return "FAIL: missing .dmg file"
    }
    if {![file exists $pwd/pkg/fondu-060102_1/fondu-060102_1.mpkg]} {
        return "FAIL: invalid package.destpath"
    }
    return "Package dmg successful."

} -cleanup {
    file delete -force $pwd/pkg

} -result "Package dmg successful."


cleanupTests
