{"id":18498330,"url":"https://github.com/softdevteam/lang_tester","last_synced_at":"2025-04-12T19:47:48.884Z","repository":{"id":45000744,"uuid":"186050880","full_name":"softdevteam/lang_tester","owner":"softdevteam","description":"Rust testing framework for compilers and VMs","archived":false,"fork":false,"pushed_at":"2025-02-24T09:40:42.000Z","size":264,"stargazers_count":51,"open_issues_count":1,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-03T23:09:55.569Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/softdevteam.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-05-10T20:32:43.000Z","updated_at":"2025-04-02T13:45:49.000Z","dependencies_parsed_at":"2023-02-14T18:16:13.487Z","dependency_job_id":"cec34b72-461f-4b8c-bf11-5e85a60ca6c4","html_url":"https://github.com/softdevteam/lang_tester","commit_stats":{"total_commits":159,"total_committers":6,"mean_commits":26.5,"dds":0.08176100628930816,"last_synced_commit":"d0bb2589b3ffb6a9100dc9e6fa500c7d218a3c66"},"previous_names":[],"tags_count":32,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softdevteam%2Flang_tester","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softdevteam%2Flang_tester/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softdevteam%2Flang_tester/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/softdevteam%2Flang_tester/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/softdevteam","download_url":"https://codeload.github.com/softdevteam/lang_tester/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248625497,"owners_count":21135513,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T13:38:46.604Z","updated_at":"2025-04-12T19:47:48.860Z","avatar_url":"https://github.com/softdevteam.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# lang_tester\n\nThis crate provides a simple language testing framework designed to help when\nyou are testing things like compilers and virtual machines. It allows users to\nexpress simple tests for process success/failure and for stderr/stdout, including\nembedding those tests directly in the source file. It is loosely based on the\n[`compiletest_rs`](https://crates.io/crates/compiletest_rs) crate, but is much\nsimpler (and hence sometimes less powerful), and designed to be used for\ntesting non-Rust languages too.\n\nFor example, a Rust language tester, loosely in the spirit of\n[`compiletest_rs`](https://crates.io/crates/compiletest_rs), looks as follows:\n\n```rust\nuse std::{env, fs::read_to_string, path::PathBuf, process::Command};\n\nuse lang_tester::LangTester;\nuse tempfile::TempDir;\n\nfn main() {\n    // We use rustc to compile files into a binary: we store those binary files\n    // into `tempdir`. This may not be necessary for other languages.\n    let tempdir = TempDir::new().unwrap();\n    LangTester::new()\n        .test_dir(\"examples/rust_lang_tester/lang_tests\")\n        // Only use files named `*.rs` as test files.\n        .test_path_filter(|p| p.extension().and_then(|x| x.to_str()) == Some(\"rs\"))\n        // Treat lines beginning with \"#\" inside a test as comments.\n        .comment_prefix(\"#\")\n        // Extract the first sequence of commented line(s) as the tests.\n        .test_extract(|p| {\n            read_to_string(p)\n                .unwrap()\n                .lines()\n                // Skip non-commented lines at the start of the file.\n                .skip_while(|l| !l.starts_with(\"//\"))\n                // Extract consecutive commented lines.\n                .take_while(|l| l.starts_with(\"//\"))\n                .map(|l| \u0026l[COMMENT_PREFIX.len()..])\n                .collect::\u003cVec\u003c_\u003e\u003e()\n                .join(\"\\n\")\n        })\n        // We have two test commands:\n        //   * `Compiler`: runs rustc.\n        //   * `Run-time`: if rustc does not error, and the `Compiler` tests\n        //     succeed, then the output binary is run.\n        .test_cmds(move |p| {\n            // Test command 1: Compile `x.rs` into `tempdir/x`.\n            let mut exe = PathBuf::new();\n            exe.push(\u0026tempdir);\n            exe.push(p.file_stem().unwrap());\n            let mut compiler = Command::new(\"rustc\");\n            compiler.args(\u0026[\"-o\", exe.to_str().unwrap(), p.to_str().unwrap()]);\n            // Test command 2: run `tempdir/x`.\n            let runtime = Command::new(exe);\n            vec![(\"Compiler\", compiler), (\"Run-time\", runtime)]\n        })\n        .run();\n}\n```\n\nThis defines a lang tester that uses all `*.rs` files in a given directory as\ntest files, running two test commands against them: `Compiler` (i.e. `rustc`);\nand `Run-time` (the compiled binary).\n\nUsers can then write test files such as the following:\n\n```rust\n// Compiler:\n//   stderr:\n//     warning: unused variable: `x`\n//       ...unused_var.rs:12:9\n//       ...\n//\n// Run-time:\n//   stdout: Hello world\nfn main() {\n    let x = 0;\n    println!(\"Hello world\");\n}\n```\n\nThe above file contains 4 meaningful tests, two specified by the user and\ntwo implied by defaults: the `Compiler` should succeed (e.g. return a `0` exit\ncode when run on Unix), and its `stderr` output should warn about an unused\nvariable on line 12; and the resulting binary should succeed produce `Hello\nworld` on `stdout`.\n\n\n## Integration with Cargo.\n\nTests created with lang_tester can be used as part of an existing test suite and\ncan be run with the `cargo test` command. For example, if the Rust source file\nthat runs your lang tests is `lang_tests/run.rs` then add the following to your\nCargo.toml:\n\n```\n[[test]]\nname = \"lang_tests\"\npath = \"lang_tests/run.rs\"\nharness = false\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoftdevteam%2Flang_tester","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoftdevteam%2Flang_tester","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoftdevteam%2Flang_tester/lists"}