fn write_test_file()

in yaml_test_runner/src/generator.rs [551:606]


fn write_test_file(
    test: YamlTests,
    relative_path: &Path,
    generated_dir: &Path,
) -> anyhow::Result<()> {
    if test.skip_test("*") {
        info!(
            r#"skipping all tests in {} because it's included in skip.yml"#,
            test.path,
        );
        return Ok(());
    }

    let mut path = test_file_path(relative_path)?;
    path = generated_dir.join(path);
    path.set_extension("rs");

    fs::create_dir_all(path.parent().unwrap())?;
    let mut file = File::create(&path)?;
    file.write_all(
        r#"/*
 * Licensed to Elasticsearch B.V. under one or more contributor
 * license agreements. See the NOTICE file distributed with
 * this work for additional information regarding copyright
 * ownership. Elasticsearch B.V. licenses this file to you under
 * the Apache License, Version 2.0 (the "License"); you may
 * not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *	http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
// -----------------------------------------------
// This file is generated, please do not edit it manually.
// Run the following in the root of the repo:
//
// cargo run -p yaml_test_runner -- --branch <branch> --token <token> --path <rest specs path>
// -----------------------------------------------
"#
        .as_bytes(),
    )?;

    let tokens = test.build();
    let generated = tokens.to_string();
    let mut file = OpenOptions::new().append(true).open(&path)?;
    file.write_all(generated.as_bytes())?;
    file.write_all(b"\n")?;

    Ok(())
}