Skip to content

Commit ba1c0be

Browse files
author
Chris Patterson
committed
tests: add spread test for rust workspace
Signed-off-by: Chris Patterson <[email protected]>
1 parent fa3fe36 commit ba1c0be

File tree

7 files changed

+117
-0
lines changed

7 files changed

+117
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[workspace]
2+
3+
members = [
4+
"fib",
5+
"calc-fib"
6+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "calc-fib"
3+
version = "0.1.0"
4+
authors = ["Chris Patterson <[email protected]>"]
5+
edition = "2018"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[dependencies]
10+
regex = "1"
11+
fib = { path = "../fib" }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use std::env;
2+
extern crate fib;
3+
4+
fn main() {
5+
let args: Vec<String> = env::args().collect();
6+
7+
if args.len() < 2 {
8+
eprintln!("please specify number");
9+
return
10+
}
11+
12+
let num_string = &args[1];
13+
let number: i32 = match num_string.parse() {
14+
Ok(n) => {
15+
n
16+
},
17+
Err(_) => {
18+
eprintln!("error: not an integer");
19+
return;
20+
}
21+
};
22+
23+
let sum = fib::fib(number);
24+
println!("{}", sum);
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "fib"
3+
version = "0.1.0"
4+
authors = ["Chris Patterson <[email protected]>"]
5+
edition = "2018"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[dependencies]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Terribly inefficient recursive fib routine.
2+
pub fn fib(n: i32) -> u64 {
3+
if n < 0 {
4+
panic!("invalid: {}", n);
5+
}
6+
if n == 0 {
7+
return 0;
8+
} else if n == 1 {
9+
return 1;
10+
} else {
11+
return fib(n - 1) + fib(n - 2)
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: calc-fib
2+
version: "1.0"
3+
summary: Test the rust plugin with sworkspaces.
4+
description: |
5+
This is a basic rust snap with workspaces.
6+
7+
grade: devel
8+
confinement: strict
9+
10+
apps:
11+
calc-fib:
12+
command: bin/calc-fib
13+
14+
parts:
15+
calc-fib:
16+
plugin: rust
17+
source: .
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
summary: Build and run a workspace rust snap
2+
3+
systems:
4+
- ubuntu-18.04
5+
- ubuntu-18.04-64
6+
- ubuntu-18.04-amd64
7+
- ubuntu-18.04-i386
8+
- ubuntu-18.04-armhf
9+
- ubuntu-16.04
10+
- ubuntu-16.04-64
11+
- ubuntu-16.04-amd64
12+
- ubuntu-16.04-i386
13+
- ubuntu-16.04-armhf
14+
15+
environment:
16+
SNAP_DIR: ../snaps/rust-workspace-fib
17+
18+
prepare: |
19+
#shellcheck source=tests/spread/tools/snapcraft-yaml.sh
20+
. "$TOOLS_DIR/snapcraft-yaml.sh"
21+
set_base "$SNAP_DIR/snap/snapcraft.yaml"
22+
23+
restore: |
24+
cd "$SNAP_DIR"
25+
snapcraft clean
26+
rm -f ./*.snap
27+
28+
#shellcheck source=tests/spread/tools/snapcraft-yaml.sh
29+
. "$TOOLS_DIR/snapcraft-yaml.sh"
30+
restore_yaml "snap/snapcraft.yaml"
31+
32+
execute: |
33+
cd "$SNAP_DIR"
34+
snapcraft
35+
sudo snap install calc-fib_*.snap --dangerous
36+
[ "$(calc-fib 8)" = "21" ]

0 commit comments

Comments
 (0)