File tree Expand file tree Collapse file tree 2 files changed +16
-6
lines changed Expand file tree Collapse file tree 2 files changed +16
-6
lines changed Original file line number Diff line number Diff line change @@ -190,7 +190,7 @@ mod tests {
190
190
191
191
#[ pg_test]
192
192
#[ search_path( @extschema@) ]
193
- #[ should_panic = "error: the `env` and `option_env` macros are forbidden " ]
193
+ #[ should_panic = "environment variable `PATH` not defined at compile time. " ]
194
194
#[ cfg( feature = "trusted" ) ]
195
195
fn plrust_block_env ( ) -> spi:: Result < ( ) > {
196
196
let definition = r#"
@@ -204,15 +204,14 @@ mod tests {
204
204
205
205
#[ pg_test]
206
206
#[ search_path( @extschema@) ]
207
- #[ should_panic = "error: the `env` and `option_env` macros are forbidden " ]
207
+ #[ should_panic = "the `option_env` macro always returns `None` in the PL/Rust user function " ]
208
208
#[ cfg( feature = "trusted" ) ]
209
209
fn plrust_block_option_env ( ) -> spi:: Result < ( ) > {
210
210
let definition = r#"
211
211
CREATE FUNCTION try_get_path() RETURNS text AS $$
212
- match option_env!("PATH") {
213
- None => Ok(None),
214
- Some(s) => Ok(Some(s.to_string()))
215
- }
212
+ let v = option_env!("PATH")
213
+ .expect("the `option_env` macro always returns `None` in the PL/Rust user function");
214
+ Ok(Some(v.to_string()))
216
215
$$ LANGUAGE plrust;
217
216
"# ;
218
217
Spi :: run ( definition)
Original file line number Diff line number Diff line change @@ -49,6 +49,14 @@ impl Callbacks for PlrustcCallbacks {
49
49
}
50
50
}
51
51
}
52
+ fn clear_env ( ) {
53
+ let all_var_names = std:: env:: vars_os ( )
54
+ . map ( |( name, _) | name)
55
+ . collect :: < Vec < _ > > ( ) ;
56
+ for name in all_var_names {
57
+ std:: env:: remove_var ( name) ;
58
+ }
59
+ }
52
60
53
61
fn main ( ) {
54
62
rustc_driver:: install_ice_hook ( "https://github.com/tcdi/plrust/issues/new" , |_| ( ) ) ;
@@ -58,6 +66,9 @@ fn main() {
58
66
let args =
59
67
rustc_driver:: args:: arg_expand_all ( handler, & std:: env:: args ( ) . collect :: < Vec < _ > > ( ) ) ;
60
68
let config = PlrustcConfig :: from_env_and_args ( & args) ;
69
+ if config. compiling_user_crate ( ) {
70
+ clear_env ( ) ;
71
+ }
61
72
run_compiler (
62
73
args,
63
74
& mut PlrustcCallbacks {
You can’t perform that action at this time.
0 commit comments