Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: add spread suite for cmake plugin #2183

Merged
merged 3 commits into from
Aug 2, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions spread.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ restore: $SETUP_DIR/restore.sh
suites:
tests/spread/plugins/autotools/:
summary: tests of snapcraft's Autotools plugin
tests/spread/plugins/cmake/:
summary: tests of snapcraft's CMake plugin
tests/spread/plugins/go/:
summary: tests of snapcraft's Go plugin

Expand Down
81 changes: 0 additions & 81 deletions tests/integration/plugins/test_cmake_plugin.py

This file was deleted.

32 changes: 0 additions & 32 deletions tests/integration/snapd/test_cmake_snap.py

This file was deleted.

Binary file removed tests/integration/snaps/cmake-hello/icon.png
Binary file not shown.
4 changes: 0 additions & 4 deletions tests/integration/snaps/cmake-hello/test.c

This file was deleted.

40 changes: 40 additions & 0 deletions tests/spread/plugins/cmake/rebuild/task.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
summary: Build and run a basic cmake snap

environment:
SNAP_DIR: ../snaps/cmake-with-lib

prepare: |
. "$SETUP_DIR/config.sh"
set_outdated_step_action "clean"

restore: |
. "$SETUP_DIR/config.sh"
clear_config

cd "$SNAP_DIR"
snapcraft clean
rm -f ./*.snap

execute: |
cd "$SNAP_DIR"
output="$(snapcraft prime)"

# Assert that cmake actually configured and built from scratch
echo "$output" | MATCH "The CXX compiler identification"
echo "$output" | MATCH "Building CXX object CMakeFiles/foo.dir/foo.cpp.o"
echo "$output" | MATCH "Building CXX object CMakeFiles/usefoo.dir/main.cpp.o"

[ "$(./prime/bin/usefoo)" = "foo" ]

# Modify the source code
cp new_foo.cpp src/foo.cpp

# Prime again. This should rebuild
output="$(snapcraft prime)"

# Assert that cmake did not start from scratch, and reused everything it could
echo "$output" | MATCH -v "The CXX compiler identification"
echo "$output" | MATCH -v "Building CXX object CMakeFiles/usefoo.dir/main.cpp.o"
echo "$output" | MATCH "Building CXX object CMakeFiles/foo.dir/foo.cpp.o"

[ "$(./prime/bin/usefoo)" = "new foo" ]
15 changes: 15 additions & 0 deletions tests/spread/plugins/cmake/run/task.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
summary: Build and run a basic cmake snap

environment:
SNAP_DIR: ../snaps/cmake-hello

restore: |
cd "$SNAP_DIR"
snapcraft clean
rm -f ./*.snap

execute: |
cd "$SNAP_DIR"
snapcraft
sudo snap install cmake-hello_*.snap --dangerous
[ "$(cmake-hello)" = "hello world" ]
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.2)
cmake_minimum_required(VERSION 2.6)
project(cmake-hello C)
add_executable(cmake-hello test.c)
install(TARGETS cmake-hello RUNTIME DESTINATION bin)
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
name: cmake-hello
version: 0.1
version: 1.0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is missing quotes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, fixed.

summary: test the cmake plugin
description: |
This is a basic cmake snap. It just prints a hello world.
If you want to add other functionalities to this snap, please don't.
Make a new one.
icon: icon.png
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great, we do not need icons :-)


grade: devel
confinement: strict

build-packages: [gcc, libc6-dev]
Expand Down
7 changes: 7 additions & 0 deletions tests/spread/plugins/cmake/snaps/cmake-hello/test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <stdio.h>

int main()
{
printf("hello world\n");
return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ parts:
my-part:
plugin: cmake
source: src/
build-packages: [g++]
17 changes: 17 additions & 0 deletions tests/spread/setup/config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh -e

export CONFIG_FILE_PATH="$HOME/.config/snapcraft/cli.cfg"
mkdir -p "$(dirname "$CONFIG_FILE_PATH")"

set_outdated_step_action()
{
cat <<- EOF > "$CONFIG_FILE_PATH"
[Lifecycle]
outdated_step_action = $1
EOF
}

clear_config()
{
rm -f "$CONFIG_FILE_PATH"
}