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

PR: Remove CI constraints used with windows-2019 #24

Merged
merged 5 commits into from
Mar 3, 2022
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
2 changes: 1 addition & 1 deletion .github/workflows/windows_stable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ jobs:
# run: Expand-Archive ngrok.zip
# - name: Auth
# if: ${{ failure() }}
# run: .\ngrok\ngrok.exe authtoken <ngrok token>
# run: .\ngrok\ngrok.exe authtoken 1raaG4z7gsaCRlLw8cRkUWW6ItF_2LWTUFxXwd6UeeJNAAAci
# - name: Enable TS
# if: ${{ failure() }}
# run: Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server'-name "fDenyTSConnections" -Value 0
Expand Down
21 changes: 10 additions & 11 deletions src/pty/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use windows::Win32::Globalization::{MultiByteToWideChar, WideCharToMultiByte, CP
use windows::core::{HRESULT, Error};

use std::ptr;
use std::env;
use std::sync::mpsc;
use std::thread;
use std::time::Duration;
Expand Down Expand Up @@ -549,16 +548,16 @@ impl PTYProcess {
self.process = process;
self.close_process = close_process;

if env::var_os("CONPTY_CI").is_some() {
// For some reason, the CI requires a flush of the handle before
// reading from a thread.
let result = read(4096, true, self.conout, false).unwrap();
println!("{:?}", result);
let result = read(4096, true, self.conout, false).unwrap();
println!("{:?}", result);
let res: Result<u32, OsString> = self.write(OsString::from("\r\n\r\n"));
res.unwrap();
}
// if env::var_os("CONPTY_CI").is_some() {
// // For some reason, the CI requires a flush of the handle before
// // reading from a thread.
// let result = read(4096, true, self.conout, false).unwrap();
// println!("{:?}", result);
// let result = read(4096, true, self.conout, false).unwrap();
// println!("{:?}", result);
// let res: Result<u32, OsString> = self.write(OsString::from("\r\n\r\n"));
// res.unwrap();
// }

self.reader_process_out.send(Some(process)).unwrap();
unsafe {
Expand Down
8 changes: 2 additions & 6 deletions src/pty/conpty/pty_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use windows::Win32::System::Threading::{
use windows::Win32::UI::WindowsAndMessaging::{ShowWindow, SW_HIDE};
use windows::core::{HRESULT, Error};

use std::{mem, env, ptr};
use std::{mem, ptr};
use std::mem::MaybeUninit;
use std::ffi::OsString;
use std::os::windows::prelude::*;
Expand Down Expand Up @@ -207,10 +207,6 @@ impl PTYImpl for ConPTY {
CloseHandle(input_read_side);
CloseHandle(output_write_side);

if env::var_os("CI").is_some() {
env::set_var("CONPTY_CI", "1");
}

let pty_process = PTYProcess::new(input_write_side, output_read_side, true);

Ok(Box::new(ConPTY {
Expand Down Expand Up @@ -391,7 +387,7 @@ impl Drop for ConPTY {
DeleteProcThreadAttributeList(self.startup_info.lpAttributeList);
ClosePseudoConsole(self.handle);

if env::var_os("CI").is_none() && self.console_allocated {
if self.console_allocated {
FreeConsole();
}
}
Expand Down
45 changes: 25 additions & 20 deletions tests/conpty.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![cfg(feature="conpty")]

use std::ffi::OsString;
use std::{thread, time, env};
use std::{thread, time};
use regex::Regex;

use winptyrs::{PTY, PTYArgs, PTYBackend, MouseMode, AgentConfig};
Expand Down Expand Up @@ -123,36 +123,41 @@ fn set_size_conpty() {

pty.set_size(90, 30).unwrap();

if &env::var("CI").unwrap_or("0".to_owned()) == "1" {
return;
}
// if &env::var("CI").unwrap_or("0".to_owned()) == "1" {
// return;
// }

pty.write("cls\r\n".into()).unwrap();
pty.write("cls\r\n".into()).unwrap();
pty.write("cls\r\n".into()).unwrap();
pty.write("cls\r\n".into()).unwrap();

pty.write("powershell -command \"&{(get-host).ui.rawui.WindowSize;}\"\r\n".into()).unwrap();
let regex = Regex::new(r".*Width.*").unwrap();
let mut output_str = "";
let mut out: OsString;
let mut count = 0;
while count < 5 || (cols != 90 && rows != 30) {
pty.write("powershell -command \"&{(get-host).ui.rawui.WindowSize;}\"\r\n".into()).unwrap();
let regex = Regex::new(r".*Width.*").unwrap();
let mut output_str = "";
let mut out: OsString;

while !regex.is_match(output_str) {
out = pty.read(1000, false).unwrap();
output_str = out.to_str().unwrap();
}
while !regex.is_match(output_str) {
out = pty.read(1000, false).unwrap();
output_str = out.to_str().unwrap();
}

println!("{:?}", output_str);
println!("{:?}", output_str);

let parts: Vec<&str> = output_str.split("\r\n").collect();
let num_regex = Regex::new(r"\s+(\d+)\s+(\d+).*").unwrap();
for part in parts {
if num_regex.is_match(part) {
for cap in num_regex.captures_iter(part) {
cols = cap[1].parse().unwrap();
rows = cap[2].parse().unwrap();
let parts: Vec<&str> = output_str.split("\r\n").collect();
let num_regex = Regex::new(r"\s+(\d+)\s+(\d+).*").unwrap();
for part in parts {
if num_regex.is_match(part) {
for cap in num_regex.captures_iter(part) {
cols = cap[1].parse().unwrap();
rows = cap[2].parse().unwrap();
}
}
}

count += 1;
}

assert_eq!(cols, 90);
Expand Down
42 changes: 23 additions & 19 deletions tests/winpty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,31 +115,35 @@ fn set_size_winpty() {
pty.set_size(90, 30).unwrap();
pty.write("cls\r\n".into()).unwrap();

pty.write("powershell -command \"&{(get-host).ui.rawui.WindowSize;}\"\r\n".into()).unwrap();
let regex = Regex::new(r".*Width.*").unwrap();
let mut output_str = "";
let mut out: OsString;

while !regex.is_match(output_str) {
out = pty.read(1000, false).unwrap();
output_str = out.to_str().unwrap();
}
let mut count = 0;
while count < 5 || (cols != 90 && rows != 30) {
pty.write("powershell -command \"&{(get-host).ui.rawui.WindowSize;}\"\r\n".into()).unwrap();
let regex = Regex::new(r".*Width.*").unwrap();
let mut output_str = "";
let mut out: OsString;

while !regex.is_match(output_str) {
out = pty.read(1000, false).unwrap();
output_str = out.to_str().unwrap();
}

let parts: Vec<&str> = output_str.split("\r\n").collect();
let num_regex = Regex::new(r"\s+(\d+)\s+(\d+).*").unwrap();
for part in parts {
if num_regex.is_match(part) {
for cap in num_regex.captures_iter(part) {
cols = cap[1].parse().unwrap();
rows = cap[2].parse().unwrap();
let parts: Vec<&str> = output_str.split("\r\n").collect();
let num_regex = Regex::new(r"\s+(\d+)\s+(\d+).*").unwrap();
for part in parts {
if num_regex.is_match(part) {
for cap in num_regex.captures_iter(part) {
cols = cap[1].parse().unwrap();
rows = cap[2].parse().unwrap();
}
}
}
}

if &env::var("CI").unwrap_or("0".to_owned()) == "0" {
count += 1;
}
// if &env::var("CI").unwrap_or("0".to_owned()) == "0" {
assert_eq!(cols, 90);
assert_eq!(rows, 30);
}
// }
}

#[test]
Expand Down