summaryrefslogtreecommitdiff
path: root/test/end-to-end/target-tests/configure-vars.sh
blob: e55581f784e8c604ea20b1b57baf372dbebe0b5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/sh
# Copyright 2022 Huawei Cloud Computing Technology Co., Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -e

TOOL=$(realpath ./bin/tool-under-test)
mkdir -p .root
BUILDROOT=$(realpath .root)
mkdir -p out
OUTDIR=$(realpath out)

mkdir src
cd src
touch ROOT
cat > TARGETS <<'EOI'
{ "copy foo":
  { "type": "configure"
  , "arguments_config": ["FOO"]
  , "target": "use bar"
  , "config":
    { "type": "let*"
    , "bindings":
      [["BAR", {"type": "var", "name": "FOO"}], ["FOO", "REDACTED"]]
    , "body": {"type": "env", "vars": ["BAR", "FOO"]}
    }
  }
, "use bar":
  { "type": "file_gen"
  , "arguments_config": ["BAR"]
  , "data": {"type": "var", "name": "BAR", "default": "bar"}
  , "name": "out.txt"
  }
}
EOI


echo
${TOOL} analyse --local-build-root "${BUILDROOT}" \
        --dump-vars "${OUTDIR}/vars.json" \
        --dump-targets "${OUTDIR}/targets.json" \
        -D '{"FOO": "the value", "BAR": "unused!"}' 'copy foo' 2>&1
echo
cat "${OUTDIR}/vars.json"
echo
cat "${OUTDIR}/targets.json"
echo
copy_configs=$(cat "${OUTDIR}/targets.json" | jq -acM '."@" | ."" | ."" | ."copy foo"')
echo "${copy_configs}"
[ $(echo "${copy_configs}" | jq length) -eq 1 ]
config=$(echo "${copy_configs}" | jq '.[0]')
echo $config
[ $(echo "$config" | jq -acM 'keys') = '["FOO"]' ]
echo "$config" | jq -acM '."FOO"'
[ "$(echo "$config" | jq -acM '."FOO"')" = '"the value"' ]
[ "$(cat "${OUTDIR}/vars.json")" = '["FOO"]' ]

echo DONE