Add --example as an option to test

For running tests that are part of examples.

Change-Id: I15bf304629e2232198c7405ab198c145e45a6b1b
diff --git a/src/lib.rs b/src/lib.rs
index 3b03fed..c4cb676 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -815,6 +815,12 @@
                         .help("Test only the specified test target"),
                 )
                 .arg(
+                    Arg::with_name(EXAMPLE)
+                        .long(EXAMPLE)
+                        .takes_value(true)
+                        .help("Test a specific example from the examples/ dir."),
+                )
+                .arg(
                     Arg::with_name("package")
                         .short("p")
                         .long("package")
@@ -867,8 +873,8 @@
                 )
                 .arg(Arg::with_name("tests").long("tests").help("Build all the tests"))
                 .arg(
-                    Arg::with_name("example")
-                        .long("example")
+                    Arg::with_name(EXAMPLE)
+                        .long(EXAMPLE)
                         .takes_value(true)
                         .help("Build a specific example from the examples/ dir."),
                 )
@@ -985,9 +991,9 @@
                         .help("Name of the bin target to run"),
                 )
                 .arg(
-                    Arg::with_name("example")
-                        .long("example")
-                        .value_name("example")
+                    Arg::with_name(EXAMPLE)
+                        .long(EXAMPLE)
+                        .value_name(EXAMPLE)
                         .help("Run a specific example from the examples/ dir."),
                 ),
         )
@@ -1173,6 +1179,10 @@
             params.push("--bin");
             params.push(bin);
         }
+        if let Some(example) = test_matches.value_of(EXAMPLE) {
+            params.push("--example");
+            params.push(example);
+        }
         if let Some(test_params) = test_matches.values_of("test_params") {
             params.extend(test_params.collect::<Vec<_>>());
         }
@@ -1219,7 +1229,7 @@
         if build_matches.is_present("tests") {
             params.push("--tests");
         }
-        if let Some(example) = build_matches.value_of("example") {
+        if let Some(example) = build_matches.value_of(EXAMPLE) {
             params.push("--example");
             params.push(example);
         }
@@ -1284,7 +1294,7 @@
             params.push("--bin");
             params.push(bin);
         }
-        if let Some(example) = run_matches.value_of("example") {
+        if let Some(example) = run_matches.value_of(EXAMPLE) {
             params.push("--example");
             params.push(example);
         }