Skip to content

Conversation

@katrinafyi
Copy link
Contributor

I think it would be useful to be able to define test fixtures within the test code. Most of the time, fixtures are really simple with only a few links. The current system needs you to make a directory and file in the fixtures folder which is a bit inconvenient. Also, when reading the test code, you'd have to separately open the fixture file to learn the content of the test.

With this change, the test files are defined in the test code so it's all visible at one location. It looks like this:

        let temp = tempdir()?;
        let dir = DirBuilder::new(temp.path());

        let file_without_ext = dir.str(
            "file-without-ext",
            r#"
# Test File
[Example](https://example.com)
[Local](local.md)
            "#,
        )?;

However, the DirBuilder code is pretty simple and doesn't need to exist. If this idea was something which we want, it could simply be done using writeln! in the test code. DirBuilder does make it slightly easier because Rust's filesystem functions are a bit disorganised and hard to find/use. I don't really mind either way.

@thomas-zahner
Copy link
Member

Most of the time, fixtures are really simple with only a few links.

True, maybe we could replace some/many fixtures with such inline definitions.

If this idea was something which we want, it could simply be done using writeln! in the test code.

I don't understand what you mean here. Isn't writeln! what's used right now? Or do you refer to other tests which haven't changed so far?

@katrinafyi
Copy link
Contributor Author

katrinafyi commented Nov 4, 2025

Oh, I'm thinking of future test cases. I mean that instead of adding this new DirBuilder, we could just use writeln! more often when writing new tests. I think DirBuilder does improve the ease of writing these test files, but only very slightly. So maybe it's not worth adding.

Another thought I've had is that test files could be defined in Rust using TOML:

make_dir!(r#"
"test_file.md" = '''
[link](https://asd.com)
'''

"test_file.html" = '''
<p> fdsjaio </p>
'''
"#)

This was my original idea when thinking about this problem, but maybe this is even more crazy :')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants