@@ -3,6 +3,7 @@ use rstest::rstest;
33use std:: path:: { Path , PathBuf } ;
44use tempfile:: TempDir ;
55
6+ use crate :: prelude:: * ;
67use crate :: results:: walltime_results:: WalltimeResults ;
78
89fn assert_results_snapshots ( profile_dir : & Path , project_name : & str ) {
@@ -84,6 +85,14 @@ fn test_build_and_run(#[case] project_name: &str) {
8485 . join ( "testdata/projects" )
8586 . join ( project_name) ;
8687
88+ if !can_build_project ( & project_dir) {
89+ warn ! (
90+ "Skipping project {} because it requires a different Go version" ,
91+ project_name
92+ ) ;
93+ return ;
94+ }
95+
8796 let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
8897 let profile_dir = temp_dir. path ( ) . join ( "profile" ) ;
8998 let cli = crate :: cli:: Cli {
@@ -96,3 +105,54 @@ fn test_build_and_run(#[case] project_name: &str) {
96105
97106 assert_results_snapshots ( & profile_dir, project_name) ;
98107}
108+
109+ fn can_build_project ( project_dir : & Path ) -> bool {
110+ if let Some ( required_version) = project_go_version ( project_dir) {
111+ let current_version = go_version ( ) . unwrap ( ) ;
112+ info ! (
113+ "Project requires Go {}, current version is {}" ,
114+ required_version, current_version
115+ ) ;
116+ required_version. matches ( & current_version)
117+ } else {
118+ true
119+ }
120+ }
121+
122+ fn go_version ( ) -> anyhow:: Result < semver:: Version > {
123+ use anyhow:: Context ;
124+
125+ let output = std:: process:: Command :: new ( "go" ) . arg ( "version" ) . output ( ) ?;
126+ if !output. status . success ( ) {
127+ panic ! ( "Failed to get Go version" ) ;
128+ }
129+ let output = String :: from_utf8_lossy ( & output. stdout ) ;
130+
131+ // Example output: go version go1.24.9 linux/amd64
132+ let go_version_str = output
133+ . split_whitespace ( )
134+ . nth ( 2 )
135+ . context ( "Failed to parse Go version" ) ?
136+ . strip_prefix ( "go" )
137+ . context ( "Failed to strip 'go' prefix" ) ?;
138+ Ok ( semver:: Version :: parse ( go_version_str) ?)
139+ }
140+
141+ // Check whether the go.mod expects a specific Go version, and skip the test if not met
142+ fn project_go_version ( project_dir : & Path ) -> Option < semver:: VersionReq > {
143+ let go_mod_path = project_dir. join ( "go.mod" ) ;
144+ if !go_mod_path. exists ( ) {
145+ return None ;
146+ }
147+
148+ let go_mod_content = std:: fs:: read_to_string ( go_mod_path) . unwrap_or_default ( ) ;
149+ for line in go_mod_content. lines ( ) {
150+ let Some ( version_str) = line. strip_prefix ( "go " ) else {
151+ continue ;
152+ } ;
153+
154+ return semver:: VersionReq :: parse ( version_str) . ok ( ) ;
155+ }
156+
157+ None
158+ }
0 commit comments