22//!
33//! These tests verify the IDE metadata export functionality works correctly.
44
5- use std:: process:: Command ;
6-
7- fn get_binary_path ( ) -> String {
8- // Try release binary first, then debug
9- // Use EXE_SUFFIX for cross-platform compatibility (.exe on Windows, empty on Unix)
10- let exe_suffix = std:: env:: consts:: EXE_SUFFIX ;
11- let release_path = format ! ( "target/release/tmpltool{}" , exe_suffix) ;
12- let debug_path = format ! ( "target/debug/tmpltool{}" , exe_suffix) ;
13-
14- if std:: path:: Path :: new ( & release_path) . exists ( ) {
15- release_path
16- } else if std:: path:: Path :: new ( & debug_path) . exists ( ) {
17- debug_path
18- } else {
19- panic ! ( "Binary not found. Please run 'cargo build' first." ) ;
20- }
5+ use assert_cmd:: Command ;
6+ use predicates:: prelude:: * ;
7+
8+ #[ allow( deprecated) ]
9+ fn tmpltool ( ) -> Command {
10+ Command :: cargo_bin ( "tmpltool" ) . unwrap ( )
2111}
2212
2313#[ test]
2414fn test_ide_json_outputs_valid_json ( ) {
25- let output = Command :: new ( get_binary_path ( ) )
15+ let output = tmpltool ( )
2616 . args ( [ "--ide" , "json" ] )
2717 . output ( )
2818 . expect ( "Failed to execute command" ) ;
@@ -44,7 +34,7 @@ fn test_ide_json_outputs_valid_json() {
4434
4535#[ test]
4636fn test_ide_yaml_outputs_valid_yaml ( ) {
47- let output = Command :: new ( get_binary_path ( ) )
37+ let output = tmpltool ( )
4838 . args ( [ "--ide" , "yaml" ] )
4939 . output ( )
5040 . expect ( "Failed to execute command" ) ;
@@ -65,7 +55,7 @@ fn test_ide_yaml_outputs_valid_yaml() {
6555
6656#[ test]
6757fn test_ide_toml_outputs_valid_toml ( ) {
68- let output = Command :: new ( get_binary_path ( ) )
58+ let output = tmpltool ( )
6959 . args ( [ "--ide" , "toml" ] )
7060 . output ( )
7161 . expect ( "Failed to execute command" ) ;
@@ -86,7 +76,7 @@ fn test_ide_toml_outputs_valid_toml() {
8676
8777#[ test]
8878fn test_ide_json_structure ( ) {
89- let output = Command :: new ( get_binary_path ( ) )
79+ let output = tmpltool ( )
9080 . args ( [ "--ide" , "json" ] )
9181 . output ( )
9282 . expect ( "Failed to execute command" ) ;
@@ -139,41 +129,26 @@ fn test_ide_json_structure() {
139129#[ test]
140130fn test_ide_exits_without_rendering ( ) {
141131 // --ide should exit before trying to render a template
142- let output = Command :: new ( get_binary_path ( ) )
132+ tmpltool ( )
143133 . args ( [ "--ide" , "json" , "nonexistent_template.tmpl" ] )
144- . output ( )
145- . expect ( "Failed to execute command" ) ;
146-
147- // Should succeed because --ide exits early
148- assert ! (
149- output. status. success( ) ,
150- "Command should succeed even with nonexistent template"
151- ) ;
152-
153- let stdout = String :: from_utf8_lossy ( & output. stdout ) ;
154- let parsed: Result < serde_json:: Value , _ > = serde_json:: from_str ( & stdout) ;
155- assert ! ( parsed. is_ok( ) , "Should still output valid JSON" ) ;
134+ . assert ( )
135+ . success ( ) ;
156136}
157137
158138#[ test]
159139fn test_ide_invalid_format ( ) {
160- let output = Command :: new ( get_binary_path ( ) )
140+ tmpltool ( )
161141 . args ( [ "--ide" , "invalid_format" ] )
162- . output ( )
163- . expect ( "Failed to execute command" ) ;
164-
165- assert ! ( !output. status. success( ) , "Command should fail" ) ;
166-
167- let stderr = String :: from_utf8_lossy ( & output. stderr ) ;
168- assert ! (
169- stderr. contains( "invalid" ) || stderr. contains( "possible values" ) ,
170- "Error should indicate invalid format"
171- ) ;
142+ . assert ( )
143+ . failure ( )
144+ . stderr (
145+ predicate:: str:: contains ( "invalid" ) . or ( predicate:: str:: contains ( "possible values" ) ) ,
146+ ) ;
172147}
173148
174149#[ test]
175150fn test_ide_json_contains_expected_functions ( ) {
176- let output = Command :: new ( get_binary_path ( ) )
151+ let output = tmpltool ( )
177152 . args ( [ "--ide" , "json" ] )
178153 . output ( )
179154 . expect ( "Failed to execute command" ) ;
@@ -201,7 +176,7 @@ fn test_ide_json_contains_expected_functions() {
201176
202177#[ test]
203178fn test_ide_json_categories_present ( ) {
204- let output = Command :: new ( get_binary_path ( ) )
179+ let output = tmpltool ( )
205180 . args ( [ "--ide" , "json" ] )
206181 . output ( )
207182 . expect ( "Failed to execute command" ) ;
0 commit comments