blob: 40b00412caef75d991aa7640c426f95b2f888fba [file] [log] [blame]
// Copyright 2020 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#[cfg(test)]
mod test {
use anyhow::Error;
use argh::FromArgs;
// TODO(anp): add or expand tests to ensure logging is initialized correctly.
#[derive(FromArgs)]
/// Test component.
struct Options {
#[argh(switch)]
/// test argument that should always be off
should_be_false: bool,
}
#[fuchsia::test]
fn empty_test() {}
#[fuchsia::test(logging = false)]
fn empty_test_without_logging() {}
#[fuchsia::test(logging = true)]
fn empty_test_with_logging() {}
#[fuchsia::test(logging_tags = ["foo", "bar"])]
async fn empty_test_with_logging_tags() {}
#[fuchsia::test(logging_tags = ["foo"])]
async fn empty_test_with_single_logging_tag() {}
#[fuchsia::test(logging_tags = [])]
async fn empty_test_with_empty_logging_tags() {}
#[allow(dead_code)]
#[fuchsia::test(add_test_attr = false)]
fn empty_test_without_add_test_attr() {
// With `add_test_attr = false`, this function won't get a #[test] annotation, and therefore
// is expected to _not_ run during tests.
assert!(false)
}
#[test]
#[fuchsia::test(add_test_attr = false)]
fn empty_test_without_add_test_attr_with_explicit_test_attr_before() {}
#[fuchsia::test(add_test_attr = false)]
#[test]
fn empty_test_without_add_test_attr_with_explicit_test_attr_after() {}
#[fuchsia::test(add_test_attr = true)]
fn empty_test_with_add_test_attr() {}
#[fuchsia::test]
async fn empty_async_test() {}
#[fuchsia::test(threads = 1)]
async fn empty_singlethreaded_test() {}
#[fuchsia::test(threads = 2)]
async fn empty_multithreaded_test() {}
#[cfg(target_os = "fuchsia")]
#[fuchsia::test(allow_stalls)]
async fn empty_allow_stalls_test() {}
#[cfg(target_os = "fuchsia")]
#[fuchsia::test(allow_stalls = false)]
async fn empty_not_allow_stalls_test() {}
#[cfg(target_os = "fuchsia")]
#[fuchsia::test(allow_stalls = true)]
async fn empty_very_allow_stalls_test() {}
#[cfg(target_os = "fuchsia")]
#[fuchsia::test(allow_stalls = true, threads = 1)]
async fn empty_very_singlethreaded_allow_stalls_test() {}
#[fuchsia::component]
#[test]
fn empty_component_test() {}
#[fuchsia::component]
#[test]
async fn empty_async_component_test() {}
#[fuchsia::component(threads = 1)]
#[test]
async fn empty_async_singlethreaded_component_test() {}
#[fuchsia::component(threads = 2)]
#[test]
async fn empty_async_multithreaded_component_test() {}
#[fuchsia::test]
fn empty_test_with_result() -> Result<(), Error> {
Ok(())
}
#[fuchsia::test]
async fn empty_async_test_with_result() -> Result<(), Error> {
Ok(())
}
#[fuchsia::test(threads = 1)]
async fn empty_singlethreaded_test_with_result() -> Result<(), Error> {
Ok(())
}
#[fuchsia::test(threads = 2)]
async fn empty_multithreaded_test_with_result() -> Result<(), Error> {
Ok(())
}
#[cfg(target_os = "fuchsia")]
#[fuchsia::test(allow_stalls = false)]
async fn empty_not_allow_stalls_test_with_result() -> Result<(), Error> {
Ok(())
}
#[cfg(target_os = "fuchsia")]
#[fuchsia::test(allow_stalls = true)]
async fn empty_allow_stalls_test_with_result() -> Result<(), Error> {
Ok(())
}
#[cfg(target_os = "fuchsia")]
#[fuchsia::test(allow_stalls = false, threads = 1)]
async fn empty_very_singlethreaded_not_allow_stalls_test_with_result() -> Result<(), Error> {
Ok(())
}
#[allow(dead_code)]
#[fuchsia::component(add_test_attr = true)]
fn empty_component_test_with_add_test_attr() {
// `add_test_attr = true` should only have an effect when using fuchsia::test, not
// fuchsia::component. With fuchsia::component, this function shouldn't get a #[test]
// annotation, and therefore is expected to _not_ run during tests.
assert!(false)
}
// TODO(fxbug.dev/81029): We combine #[fuchsia::component] and #[test] here as a kludge to
// enable testing of the fuchsia::component code in a unit test.
// Real users of the fuchsia library should not do this, and the ability to do so is not
// guaranteed to be present in the future.
#[fuchsia::component]
#[test]
fn empty_component_test_with_result() -> Result<(), Error> {
Ok(())
}
// TODO(fxbug.dev/81029): We combine #[fuchsia::component] and #[test] here as a kludge to
// enable testing of the fuchsia::component code in a unit test.
// Real users of the fuchsia library should not do this, and the ability to do so is not
// guaranteed to be present in the future.
#[fuchsia::component]
#[test]
async fn empty_async_component_test_with_result() -> Result<(), Error> {
Ok(())
}
// TODO(fxbug.dev/81029): We combine #[fuchsia::component] and #[test] here as a kludge to
// enable testing of the fuchsia::component code in a unit test.
// Real users of the fuchsia library should not do this, and the ability to do so is not
// guaranteed to be present in the future.
#[fuchsia::component(threads = 1)]
#[test]
async fn empty_async_singlethreaded_component_test_with_result() -> Result<(), Error> {
Ok(())
}
// TODO(fxbug.dev/81029): We combine #[fuchsia::component] and #[test] here as a kludge to
// enable testing of the fuchsia::component code in a unit test.
// Real users of the fuchsia library should not do this, and the ability to do so is not
// guaranteed to be present in the future.
#[fuchsia::component(threads = 2)]
#[test]
async fn empty_async_multithreaded_component_test_with_result() -> Result<(), Error> {
Ok(())
}
// TODO(fxbug.dev/81029): We combine #[fuchsia::component] and #[test] here as a kludge to
// enable testing of the fuchsia::component code in a unit test.
// Real users of the fuchsia library should not do this, and the ability to do so is not
// guaranteed to be present in the future.
#[fuchsia::component(logging_tags = [])]
#[test]
async fn component_with_empty_logging_tags() -> Result<(), Error> {
Ok(())
}
// TODO(fxbug.dev/81029): We combine #[fuchsia::component] and #[test] here as a kludge to
// enable testing of the fuchsia::component code in a unit test.
// Real users of the fuchsia library should not do this, and the ability to do so is not
// guaranteed to be present in the future.
#[fuchsia::component(logging_tags = ["foo"])]
#[test]
async fn component_with_single_logging_tag() -> Result<(), Error> {
Ok(())
}
// TODO(fxbug.dev/81029): We combine #[fuchsia::component] and #[test] here as a kludge to
// enable testing of the fuchsia::component code in a unit test.
// Real users of the fuchsia library should not do this, and the ability to do so is not
// guaranteed to be present in the future.
#[fuchsia::component(logging_tags = ["foo", "bar"])]
#[test]
async fn component_with_logging_tags() -> Result<(), Error> {
Ok(())
}
// fuchsia::component with arguments can't be written as a test
// (since argh will parse command line arguments and these will be arguments defining
// the test execution environment)
#[allow(dead_code)]
#[fuchsia::component]
fn empty_component_test_with_argument(opt: Options) {
assert_eq!(opt.should_be_false, false);
}
// fuchsia::component with arguments can't be written as a test
// (since argh will parse command line arguments and these will be arguments defining
// the test execution environment)
#[allow(dead_code)]
#[fuchsia::component]
async fn empty_async_component_test_with_argument(opt: Options) {
assert_eq!(opt.should_be_false, false);
}
// fuchsia::component with arguments can't be written as a test
// (since argh will parse command line arguments and these will be arguments defining
// the test execution environment)
#[allow(dead_code)]
#[fuchsia::component(threads = 1)]
async fn empty_async_singlethreaded_component_test_with_argument(opt: Options) {
assert_eq!(opt.should_be_false, false);
}
// fuchsia::component with arguments can't be written as a test
// (since argh will parse command line arguments and these will be arguments defining
// the test execution environment)
#[allow(dead_code)]
#[fuchsia::component(threads = 2)]
async fn empty_async_multithreaded_component_test_with_argument(opt: Options) {
assert_eq!(opt.should_be_false, false);
}
// fuchsia::component with arguments can't be written as a test
// (since argh will parse command line arguments and these will be arguments defining
// the test execution environment)
#[allow(dead_code)]
#[fuchsia::component]
fn empty_component_test_with_argument_and_result(opt: Options) -> Result<(), Error> {
assert_eq!(opt.should_be_false, false);
Ok(())
}
// fuchsia::component with arguments can't be written as a test
// (since argh will parse command line arguments and these will be arguments defining
// the test execution environment)
#[allow(dead_code)]
#[fuchsia::component]
async fn empty_async_component_test_with_argument_and_result(
opt: Options,
) -> Result<(), Error> {
assert_eq!(opt.should_be_false, false);
Ok(())
}
// fuchsia::component with arguments can't be written as a test
// (since argh will parse command line arguments and these will be arguments defining
// the test execution environment)
#[allow(dead_code)]
#[fuchsia::component(threads = 1)]
async fn empty_async_singlethreaded_component_test_with_argument_and_result(
opt: Options,
) -> Result<(), Error> {
assert_eq!(opt.should_be_false, false);
Ok(())
}
// fuchsia::component with arguments can't be written as a test
// (since argh will parse command line arguments and these will be arguments defining
// the test execution environment)
#[allow(dead_code)]
#[fuchsia::component(threads = 2)]
async fn empty_async_multithreaded_component_test_with_argument_and_result(
opt: Options,
) -> Result<(), Error> {
assert_eq!(opt.should_be_false, false);
Ok(())
}
}