# -*- 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

package require portmpkg 1.0
package require portpkg 1.0
source ./library.tcl
macports_worker_init


test pkg_main {
    Port pkg main unit test.
} -constraints {
    root darwin
} -setup {
    global os.platform os.major os.arch destpath package.destpath configure.build_arch
    global subport version revision package.flat maintainers description categories
    global supported_archs porturl
    env_init

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

    set contents_dir $destpath/fondu-060102_1.mpkg/Contents/
    set packages_dir $destpath/fondu-060102_1.mpkg/Contents/Packages
    set res_dir $destpath/fondu-060102_1.mpkg/Contents/Resources

    set mport [mportopen file://.]
    set workername [ditem_key $mport workername]

} -body {
    if {[$workername eval eval_targets pkg] != 0} {
        return "FAIL: cannot create pkg. Maybe should update ports tree ?"
    }

    if {![file exists $pwd/work/fondu-060102_1.pkg]} {
        return "FAIL: missing pkg file"
    }

    return "Package pkg successful."

} -cleanup {
    mportclose $mport
    file delete -force $destpath
    file delete -force $pwd/work
    
} -result "Package pkg successful."


cleanupTests
