xref: /llvm-project/lldb/test/Shell/ScriptInterpreter/Python/command_relative_import.test (revision da0b62dfb3ca597f618b1f88226b440bc7ca3960)
100bb397bSJonas Devlieghere# RUN: rm -rf %t && mkdir -p %t/foo/bar/baz
200bb397bSJonas Devlieghere# RUN: split-file %S/Inputs/relative.split %t/foo
300bb397bSJonas Devlieghere# RUN: split-file %S/Inputs/hello.split %t/foo/bar
400bb397bSJonas Devlieghere# RUN: mv %t/foo/bar/hello.py %t/foo/bar/baz
500bb397bSJonas Devlieghere# RUN: echo 'command source %t/foo/bar/hello.in' >> %t/foo/zip.in
600bb397bSJonas Devlieghere
700bb397bSJonas Devlieghere# RUN: %lldb --script-language python \
800bb397bSJonas Devlieghere# RUN:    -o 'command source %t/foo/magritte.in' \
900bb397bSJonas Devlieghere# RUN:    -o 'command source %t/foo/zip.in' \
1000bb397bSJonas Devlieghere# RUN:    -o 'command source %t/foo/magritte.in' \
11*da0b62dfSQiu Chaofan# RUN;    -o 'zip' \
1200bb397bSJonas Devlieghere# RUN:    -o 'hello'
13*da0b62dfSQiu Chaofan# RUN     -o 'magritte' 2>&1 | FileCheck %s
1400bb397bSJonas Devlieghere
1500bb397bSJonas Devlieghere# The first time importing 'magritte' fails because we didn't pass -c.
1600bb397bSJonas Devlieghere# CHECK: ModuleNotFoundError: No module named 'magritte'
1700bb397bSJonas Devlieghere# CHECK-NOT: Ceci n'est pas une pipe
1800bb397bSJonas Devlieghere# CHECK: 95126
1900bb397bSJonas Devlieghere# CHECK: Hello, World!
2000bb397bSJonas Devlieghere# The second time importing 'magritte' works, even without passing -c because
2100bb397bSJonas Devlieghere# we added '%t/foo' to the Python path when importing 'zip'.
2200bb397bSJonas Devlieghere# CHECK: Ceci n'est pas une pipe
2300bb397bSJonas Devlieghere
2400bb397bSJonas Devlieghere# Cannot use `-o` here because the driver puts the commands in a file and
2500bb397bSJonas Devlieghere# sources them.
2600bb397bSJonas Devliegherecommand script import -c %t/foo/magritte.py
2700bb397bSJonas Devliegherequit
2800bb397bSJonas Devlieghere# RUN: cat %s | %lldb --script-language python 2>&1 | FileCheck %s --check-prefix ERROR
2900bb397bSJonas Devlieghere# ERROR: error: command script import -c can only be specified from a command file
30