0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CTest で特定のテストを sudo 経由で実行する

Posted at

スーパーユーザー権限が前提の機能をテストしたいときに。
元ネタはここ。

前準備として次の内容のスクリプトを作って chmod で実行可能にしておく。
場所は ${CMAKE_SOURCE_DIR}/cmake/sudo.sh あたりに。

# !/bin/sh

/usr/bin/sudo $*

で、 CTest の設定時に次のようにする。

add_executable(my-test
    main.cpp
)
add_test(
    NAME MyTest
    COMMAND ${CMAKE_SOURCE_DIR}/cmake/sudo.sh $<TARGET_FILE:my-test>
)

こうすると ctest したときに sudo 経由で実行してくれる。
sudoers でパスワードを要求するようにしてるともちろんパスワード聞かれるので都度いれるかたちで。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?