# file      : tests/pkg-verify.testscript
# license   : MIT; see accompanying LICENSE file

.include common.testscript

# Source repository:
#
# pkg-verify
# |-- foo-1.tar.gz
# |-- foo-2.tar.gz         (manifest with unknown name)
# |-- libbaz-1.0.0.tar.gz  (manifest with unsatisfiable toolchain constraint)
# `-- not-a-package.tar.gz

: valid-package
:
$* $src/foo-1.tar.gz 2>'valid package foo 1'

: manifest
:
$* --manifest $src/foo-1.tar.gz >>EOO
  : 1
  name: foo
  version: 1
  summary: The "Foo" utility
  license: MIT
  url: http://www.example.org/foo
  email: foo-users@example.org
  EOO

: no-package
:
$* 2>>EOE != 0
error: archive path argument expected
  info: run 'bpkg help pkg-verify' for more information
EOE

: not-a-package
:
{
  : verbose
  :
  $* $src/not-a-package.tar.gz 2>>/~%EOE% != 0
  %.+
  %error: .+/not-a-package.tar.gz does not appear to be a bpkg package%
  EOE

  : silent
  :
  $* --silent $src/not-a-package.tar.gz != 0
}

: unknown-name
:
: Test that package manifest that contains an unknown name is properly handled.
:
{
  : verbose
  :
  $* $src/foo-2.tar.gz 2>>/~%EOE% != 0
  foo-2/manifest:10:1: error: unknown name 'color' in package manifest
  %  info: package archive .+/foo-2.tar.gz%
  EOE

  : silent
  :
  $* --silent $src/foo-2.tar.gz != 0

  : ignore
  :
  $* --ignore-unknown $src/foo-2.tar.gz 2>'valid package foo 2'
}

: manifest-expand
:
$* --deep --ignore-unknown --manifest $src/foo-2.tar.gz >>EOO
  : 1
  name: foo
  version: 2
  summary: The "Foo" utility
  license: MIT
  description:\
  This package contains the foo utility.

  \
  description-type: text/plain
  changes:\
  Version 2

    * First public release.

  \
  changes-type: text/plain
  url: http://www.example.org/foo
  email: foo-users@example.org
  depends: bar == 2
  bootstrap-build:\
  project = foo

  \
  EOO

: incomplete-dependency
:
$* --ignore-unknown --manifest $src/foo-2.tar.gz >>EOO
  : 1
  name: foo
  version: 2
  summary: The "Foo" utility
  license: MIT
  description-file: README
  changes-file: NEWS
  url: http://www.example.org/foo
  email: foo-users@example.org
  depends: bar == $
  EOO

: no-bootstrap-build
:
{
  : no-deep
  :
  $* --manifest $src/foo-3.tar.gz >>EOO
    : 1
    name: foo
    version: 3
    summary: The "Foo" utility
    license: MIT
    description-file: README
    changes-file: NEWS
    url: http://www.example.org/foo
    email: foo-users@example.org
    depends: bar == $
    EOO

  : deep
  :
  $* --deep --manifest $src/foo-3.tar.gz 2>>/~%EOE% != 0
    %error: unable to find bootstrap.build file in package archive .+/foo-3.tar.gz%
    EOE
}

: compatibility
:
{
  : fail
  :
  $* --manifest $src/libbaz-1.0.0.tar.gz 2>>/~%EOE% != 0
    %error: unable to satisfy constraint \(build2 >= 65536.0.0\) for package .+/libbaz-1.0.0.tar.gz%
    %  info: available build2 version is .+%
    EOE

  : success
  :
  $* --manifest --ignore-unknown $src/libbaz-1.0.0.tar.gz >>EOO
    : 1
    name: libbaz
    version: 1.0.0
    summary: libbaz
    license: MIT
    description: libbaz library
    url: http://example.org
    email: pkg@example.org
    depends: * build2 >= 65536.0.0
    depends: * bpkg >= 65536.0.0
    EOO
}
