Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: codegenerate tests with ignore_output #622

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions codegen/src/tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct ToolCommandTest {

pub test_input: String,

pub test_output: String,
pub test_output: Option<String>,
}

#[derive(Debug, serde::Deserialize, schemars::JsonSchema, Clone)]
Expand Down Expand Up @@ -110,18 +110,23 @@ impl Tool {

let test_fn_name = format!("test_{module_name}_{language}_{id}",);

let test_output = if let Some(output) = &test.test_output {
format!("Some(r#\"{output}\"#.to_owned())")
} else {
"None".to_owned()
};

let test_code = format!(
"{INDENT}#[test_with::executable({bin})]
{INDENT}fn {test_fn_name}() {{
{INDENT}{INDENT}let input = r#\"{input}\"#;
{INDENT}{INDENT}let output = r#\"{output}\"#;
{INDENT}{INDENT}let output = {test_output};
{INDENT}{INDENT}let file_ext = crate::fttype::get_file_extension(\"{language}\");
{INDENT}{INDENT}let snippet =
{INDENT}{INDENT}{INDENT}crate::execution::setup_snippet(input, &file_ext).expect(\"it to create a snippet file\");
{INDENT}{INDENT}let result = crate::tools::{module_name}::run(snippet.path())
{INDENT}{INDENT}{INDENT}.expect(\"it to be successful\")
{INDENT}{INDENT}{INDENT}.1
{INDENT}{INDENT}{INDENT}.expect(\"it to be some\");
{INDENT}{INDENT}{INDENT}.1;
{INDENT}{INDENT}assert_eq!(result, output);
{INDENT}}}",
bin = if self.npm.is_some() {
Expand All @@ -130,7 +135,6 @@ impl Tool {
&self.binary
},
input = test.test_input,
output = test.test_output,
language = test.language,
);

Expand Down
22 changes: 21 additions & 1 deletion mdsf/src/tools/actionlint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,24 @@ pub fn run(file_path: &std::path::Path) -> Result<(bool, Option<String>), MdsfEr
}

#[cfg(test)]
mod test_actionlint {}
mod test_actionlint {
#[test_with::executable(actionlint)]
fn test_actionlint_yaml_e8ea2c4c1494f1e5() {
let input = r#"name: action
on: push
jobs:
format:
runs-on: ubuntu-latest
steps:
- run: mdsf format .
"#;
let output = None;
let file_ext = crate::fttype::get_file_extension("yaml");
let snippet =
crate::execution::setup_snippet(input, &file_ext).expect("it to create a snippet file");
let result = crate::tools::actionlint::run(snippet.path())
.expect("it to be successful")
.1;
assert_eq!(result, output);
}
}
12 changes: 7 additions & 5 deletions mdsf/src/tools/alejandra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub fn run(file_path: &std::path::Path) -> Result<(bool, Option<String>), MdsfEr
#[cfg(test)]
mod test_alejandra {
#[test_with::executable(alejandra)]
fn test_alejandra_nix_f38bff8f20c2aa02() {
fn test_alejandra_nix_cb336d27233de4f0() {
let input = r#"{
lib, buildPythonPackage, fetchFromGitHub, redis }:

Expand Down Expand Up @@ -65,7 +65,8 @@ buildPythonPackage rec {
};
}
"#;
let output = r#"{
let output = Some(
r#"{
lib,
buildPythonPackage,
fetchFromGitHub,
Expand Down Expand Up @@ -94,14 +95,15 @@ buildPythonPackage rec {
maintainers = [maintainers.globin];
};
}
"#;
"#
.to_owned(),
);
let file_ext = crate::fttype::get_file_extension("nix");
let snippet =
crate::execution::setup_snippet(input, &file_ext).expect("it to create a snippet file");
let result = crate::tools::alejandra::run(snippet.path())
.expect("it to be successful")
.1
.expect("it to be some");
.1;
assert_eq!(result, output);
}
}
12 changes: 7 additions & 5 deletions mdsf/src/tools/auto_optional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,23 @@ pub fn run(file_path: &std::path::Path) -> Result<(bool, Option<String>), MdsfEr
#[cfg(test)]
mod test_auto_optional {
#[test_with::executable(auto-optional)]
fn test_auto_optional_python_c43199b18f48026d() {
fn test_auto_optional_python_d5dd242171892fcc() {
let input = r#"def foo(bar: str = None):
pass
"#;
let output = r#"from typing import Optional
let output = Some(
r#"from typing import Optional
def foo(bar: Optional[str] = None):
pass
"#;
"#
.to_owned(),
);
let file_ext = crate::fttype::get_file_extension("python");
let snippet =
crate::execution::setup_snippet(input, &file_ext).expect("it to create a snippet file");
let result = crate::tools::auto_optional::run(snippet.path())
.expect("it to be successful")
.1
.expect("it to be some");
.1;
assert_eq!(result, output);
}
}
12 changes: 7 additions & 5 deletions mdsf/src/tools/autoflake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub fn run(file_path: &std::path::Path) -> Result<(bool, Option<String>), MdsfEr
#[cfg(test)]
mod test_autoflake {
#[test_with::executable(autoflake)]
fn test_autoflake_python_27cfd9b948e80d7f() {
fn test_autoflake_python_a676d36968f04ba0() {
let input = r#"import math
import re
import os
Expand All @@ -57,7 +57,8 @@ def foo():
print(sys.version)
return math.pi
"#;
let output = r#"import math
let output = Some(
r#"import math
import sys


Expand All @@ -68,14 +69,15 @@ def foo():
except ImportError as exception:
print(sys.version)
return math.pi
"#;
"#
.to_owned(),
);
let file_ext = crate::fttype::get_file_extension("python");
let snippet =
crate::execution::setup_snippet(input, &file_ext).expect("it to create a snippet file");
let result = crate::tools::autoflake::run(snippet.path())
.expect("it to be successful")
.1
.expect("it to be some");
.1;
assert_eq!(result, output);
}
}
12 changes: 7 additions & 5 deletions mdsf/src/tools/autopep_8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,19 @@ pub fn run(file_path: &std::path::Path) -> Result<(bool, Option<String>), MdsfEr
#[cfg(test)]
mod test_autopep_8 {
#[test_with::executable(autopep8)]
fn test_autopep_8_python_a868b5ad9905fc3f() {
fn test_autopep_8_python_4b452a82df29cac2() {
let input = r#"def add( a: int , b:int)->int: return a+b"#;
let output = r#"def add(a: int, b: int) -> int: return a+b
"#;
let output = Some(
r#"def add(a: int, b: int) -> int: return a+b
"#
.to_owned(),
);
let file_ext = crate::fttype::get_file_extension("python");
let snippet =
crate::execution::setup_snippet(input, &file_ext).expect("it to create a snippet file");
let result = crate::tools::autopep_8::run(snippet.path())
.expect("it to be successful")
.1
.expect("it to be some");
.1;
assert_eq!(result, output);
}
}
24 changes: 14 additions & 10 deletions mdsf/src/tools/beautysh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,50 +36,54 @@ pub fn run(file_path: &std::path::Path) -> Result<(bool, Option<String>), MdsfEr
#[cfg(test)]
mod test_beautysh {
#[test_with::executable(beautysh)]
fn test_beautysh_shell_f8c934ee37e2888() {
fn test_beautysh_shell_8e9f54ab33ca6912() {
let input = r#"#!/bin/shell

add() {
echo "$1" + "$2"
}
"#;
let output = r#"#!/bin/shell
let output = Some(
r#"#!/bin/shell

add() {
echo "$1" + "$2"
}
"#;
"#
.to_owned(),
);
let file_ext = crate::fttype::get_file_extension("shell");
let snippet =
crate::execution::setup_snippet(input, &file_ext).expect("it to create a snippet file");
let result = crate::tools::beautysh::run(snippet.path())
.expect("it to be successful")
.1
.expect("it to be some");
.1;
assert_eq!(result, output);
}

#[test_with::executable(beautysh)]
fn test_beautysh_bash_a6831a7ad31bd0a6() {
fn test_beautysh_bash_6cff8bc2ed5fa12f() {
let input = r#"#!/bin/bash

add() {
echo "$1" + "$2"
}
"#;
let output = r#"#!/bin/bash
let output = Some(
r#"#!/bin/bash

add() {
echo "$1" + "$2"
}
"#;
"#
.to_owned(),
);
let file_ext = crate::fttype::get_file_extension("bash");
let snippet =
crate::execution::setup_snippet(input, &file_ext).expect("it to create a snippet file");
let result = crate::tools::beautysh::run(snippet.path())
.expect("it to be successful")
.1
.expect("it to be some");
.1;
assert_eq!(result, output);
}
}
36 changes: 21 additions & 15 deletions mdsf/src/tools/biome_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub fn run(file_path: &std::path::Path) -> Result<(bool, Option<String>), MdsfEr
#[cfg(test)]
mod test_biome_format {
#[test_with::executable(npx)]
fn test_biome_format_json_90a326e29048e3cd() {
fn test_biome_format_json_3bf561a65ea19c27() {
let input = r#"
{
"key": "value",
Expand All @@ -53,23 +53,25 @@ mod test_biome_format {
, null]
}
"#;
let output = r#"{
let output = Some(
r#"{
"key": "value",
"key2": ["value2", "value3", 1, null]
}
"#;
"#
.to_owned(),
);
let file_ext = crate::fttype::get_file_extension("json");
let snippet =
crate::execution::setup_snippet(input, &file_ext).expect("it to create a snippet file");
let result = crate::tools::biome_format::run(snippet.path())
.expect("it to be successful")
.1
.expect("it to be some");
.1;
assert_eq!(result, output);
}

#[test_with::executable(npx)]
fn test_biome_format_javascript_4845e9b01c23667f() {
fn test_biome_format_javascript_8b78b3bf4549dcd5() {
let input = r#"
async function asyncAddition(
a,b
Expand All @@ -78,22 +80,24 @@ mod test_biome_format {
}

"#;
let output = r#"async function asyncAddition(a, b) {
let output = Some(
r#"async function asyncAddition(a, b) {
return a + b;
}
"#;
"#
.to_owned(),
);
let file_ext = crate::fttype::get_file_extension("javascript");
let snippet =
crate::execution::setup_snippet(input, &file_ext).expect("it to create a snippet file");
let result = crate::tools::biome_format::run(snippet.path())
.expect("it to be successful")
.1
.expect("it to be some");
.1;
assert_eq!(result, output);
}

#[test_with::executable(npx)]
fn test_biome_format_typescript_8154bfdbd3b72275() {
fn test_biome_format_typescript_4c7d2a2ce681e640() {
let input = r#"
async function asyncAddition(
a:number,b:number
Expand All @@ -104,17 +108,19 @@ number>
}

"#;
let output = r#"async function asyncAddition(a: number, b: number): Promise<number> {
let output = Some(
r#"async function asyncAddition(a: number, b: number): Promise<number> {
return a + b;
}
"#;
"#
.to_owned(),
);
let file_ext = crate::fttype::get_file_extension("typescript");
let snippet =
crate::execution::setup_snippet(input, &file_ext).expect("it to create a snippet file");
let result = crate::tools::biome_format::run(snippet.path())
.expect("it to be successful")
.1
.expect("it to be some");
.1;
assert_eq!(result, output);
}
}
12 changes: 7 additions & 5 deletions mdsf/src/tools/black.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,20 @@ pub fn run(file_path: &std::path::Path) -> Result<(bool, Option<String>), MdsfEr
#[cfg(test)]
mod test_black {
#[test_with::executable(black)]
fn test_black_python_229ec2b01c2bfe3c() {
fn test_black_python_fb3e2d124e8bebbb() {
let input = r#"def add( a: int , b:int)->int: return a+b"#;
let output = r#"def add(a: int, b: int) -> int:
let output = Some(
r#"def add(a: int, b: int) -> int:
return a + b
"#;
"#
.to_owned(),
);
let file_ext = crate::fttype::get_file_extension("python");
let snippet =
crate::execution::setup_snippet(input, &file_ext).expect("it to create a snippet file");
let result = crate::tools::black::run(snippet.path())
.expect("it to be successful")
.1
.expect("it to be some");
.1;
assert_eq!(result, output);
}
}
Loading
Loading