# Note: --silent rather than --quiet to suppress module update diagnostics.
#
test.options += --no-default-options --serial-stop --silent --buildfile -

# We disable bdep auto-synchronization since we will potentially be updating
# the module from multiple parallel tests. Note that we've made sure it is
# up-to-date by pre-loading it in the tests project (see bootstrap.build for
# details).
#
+export BDEP_SYNC=0

+cat <<EOI >=bootstrap.build
  project = basics
  amalgamation =
  subprojects =

  using config
  using kconfig
  EOI

+cat <<EOI >=root.build
  kconfig.kconfig.transient = new-def
  EOI

+cat <<EOI >=Kconfig
  config FOO
    bool "Foo support"
    default y

  config BAR
    bool "Bar support"

  config BAZ
    bool "Baz support"
    depends on BAR
    default y
  EOI

: transient
:
mkdir build;
ln -s ../../bootstrap.build ../../root.build ../../Kconfig build/;
$* noop <<EOI >>EOO
  print $kconfig.basics.foo
  print $kconfig.basics.bar
  print $kconfig.basics.baz
  EOI
  true
  false
  false
  EOO

: old-def-file
:
mkdir build;
ln -s ../../bootstrap.build ../../root.build build/;
cat <<EOI >=build/Kconfig;
  config FOO
    bool "Foo support"
    default y

  choice B_CHOICE
    bool "B choice"
    optional

    config BAR
      bool "Use Bar"

    config BAZ
      bool "Use Baz"

  endchoice
  EOI
cat <<EOI >=build/config.kconfig;
  # CONFIG_BAR is not set
  CONFIG_BAZ=y
  EOI
cat <<EOI >=defconfig.kconfig;
  # CONFIG_FOO is not set
  CONFIG_BAR=y
  EOI
$* configure config.kconfig="old-def defconfig.kconfig" <'./:' &build/config.build &build/config.kconfig.old;
cat build/config.kconfig >>EOO
  #
  # Automatically generated file; DO NOT EDIT.
  # basics
  #
  # CONFIG_FOO is not set
  # CONFIG_BAR is not set
  CONFIG_BAZ=y
  EOO

: source
:
mkdir build;
ln -s ../../bootstrap.build ../../root.build build/;
ln -s ../Kconfig ./;
cat <<EOI >=build/Kconfig;
  source "$(SRC_ROOT)/Kconfig"
  EOI
$* noop <<EOI >>EOO
  print $kconfig.basics.foo
  print $kconfig.basics.bar
  print $kconfig.basics.baz
  EOI
  true
  false
  false
  EOO

# NOTE: paths passed to Kconfig on Windows use forward slashes.

: source-error
:
mkdir build;
ln -s ../../bootstrap.build ../../root.build build/;
cat <<EOI >=build/Kconfig;
  source "$(SRC_ROOT)/Kconfig"
  EOI
$* noop <'' 2>>~%EOE% != 0
  %.+/source-error/build/Kconfig:1: error: unable to open file ".+/source-error/Kconfig"%
  EOE

: syntax-error
:
mkdir build;
ln -s ../../bootstrap.build ../../root.build build/;
cat <<EOI >=build/Kconfig;
  source abc
  EOI
$* noop <'' 2>>~%EOE% != 0
  %.+/Kconfig:2: error: syntax error%
  %.+/Kconfig:1: error: invalid statement%
  EOE

: value-warning
:
mkdir build;
ln -s ../../bootstrap.build ../../root.build ../../Kconfig build/;
cat <<EOI >=build/config.kconfig;
  JUNK
  EOI
$* configure config.kconfig=def <'./:' 2>>~%EOE% &build/config.build &build/config.kconfig.old
  %.+/build/config.kconfig.new:1: warning: unexpected data: JUNK%
  EOE
