Repository: bevyengine/bevy
File: crates/bevy_asset/src/lib.rs (Rust)

Code before:
            }
        }

        app.init_asset::<TestAsset>()
            .register_asset_loader(NestedLoadOfSubassetLoader);

        let asset_server = app.world().resource::<AssetServer>().clone();
        let handle = asset_server.load::<TestAsset>("empty.txt");

        run_app_until(&mut app, |_world| match asset_server.load_state(&handle) {
            LoadState::Loading => None,
            LoadState::Failed(err) => {
                let error_message = format!("{err}");
                assert!(error_message.contains("Requested to load an asset path (a.cool.ron#A) with a subasset, but this is unsupported"), "what? \"{error_message}\"");
                Some(())
            }
            state => panic!("Unexpected asset state: {state:?}"),
        });
    }

    #[test]
    fn error_on_immediate_load_of_self_dependency() {
        let (mut app, dir, _source_events) = create_app_with_source_event_sender();
        let asset_server = app.world().resource::<AssetServer>().clone();

        dir.insert_asset_text(Path::new("abc.cool.ron"), "");

        struct ImmediateSelfLoader;

        impl AssetLoader for ImmediateSelfLoader {
            type Asset = TestAsset;
            type Error = crate::loader::LoadDirectError;
            type Settings = ();

            async fn load(
                &self,
                _: &mut dyn Reader,
                _: &Self::Settings,
                load_context: &mut LoadContext<'_>,
            ) -> Result<Self::Asset, Self::Error> {
                let asset_path = load_context.asset_path().clone();
                let loaded_asset = load_context
                    .loader()
                    .immediate()
                    .load::<TestAsset>(asset_path)
                    .await?;
                load_context.add_loaded_labeled_asset("myself".to_string(), loaded_asset);
                Ok(TestAsset)
            }

            fn extensions(&self) -> &[&str] {

Review comment (suggestion):
Can we use a different extension, just because in a lot of these asset tests `cool.ron` refers to `CoolText` assets. Whatever extension you want!

Repeat below.

Code after:
        run_app_until(&mut app, |_world| match asset_server.load_state(&handle) {
            LoadState::Loading => None,
            LoadState::Failed(err) => {
                let error_message = format!("{err}");
                assert!(error_message.contains("Requested to load an asset path (a.cool.ron#A) with a subasset, but this is unsupported"), "what? \"{error_message}\"");
                Some(())
            }
            state => panic!("Unexpected asset state: {state:?}"),
        });
    }

    #[test]
    fn error_on_immediate_load_of_self_path() {
        let (mut app, dir, _source_events) = create_app_with_source_event_sender();
        let asset_server = app.world().resource::<AssetServer>().clone();

        // Extension "rsp" for Recursive Self Path (RSP).
        dir.insert_asset_text(Path::new("abc.rsp"), "");

        struct ImmediateSelfLoader;

        impl AssetLoader for ImmediateSelfLoader {
            type Asset = TestAsset;
            type Error = crate::loader::LoadDirectError;
            type Settings = ();

            async fn load(
                &self,
                _: &mut dyn Reader,
                _: &Self::Settings,
                load_context: &mut LoadContext<'_>,
            ) -> Result<Self::Asset, Self::Error> {
                let asset_path = load_context.path().clone();
                let loaded_asset = load_context
                    .loader()
                    .immediate()
                    .load::<TestAsset>(asset_path)
                    .await?;
                load_context.add_loaded_labeled_asset("myself".to_string(), loaded_asset);
                Ok(TestAsset)
            }

            fn extensions(&self) -> &[&str] {
                &["rsp"]
            }
        }

        app.init_asset::<TestAsset>()
            .register_asset_loader(ImmediateSelfLoader);

        let handle: Handle<TestAsset> = asset_server.load("abc.rsp");