Skip to content

Commit 36280cb

Browse files
committed
Add some test cases for the ANSI parsing.
Had to rename our println to osprint to avoid clash with libstd's println.
1 parent 78ef4d9 commit 36280cb

File tree

12 files changed

+862
-156
lines changed

12 files changed

+862
-156
lines changed

.github/workflows/rust.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ jobs:
1414
- name: Check Syntax
1515
run: |
1616
cargo check
17+
- name: Test
18+
run: |
19+
cargo test --lib
1720
- name: Install Targets and Tools
1821
run: |
1922
rustup target add thumbv7em-none-eabi
@@ -22,7 +25,8 @@ jobs:
2225
rustup component add llvm-tools-preview
2326
cargo install cargo-binutils
2427
- name: Build
25-
run: ./build.sh --verbose
28+
run: |
29+
./build.sh --verbose
2630
- name: Upload files to Release
2731
if: github.event_name == 'push' && startswith(github.ref, 'refs/tags/')
2832
uses: softprops/action-gh-release@v1

src/commands/block.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Block Device related commands for Neotron OS
22
3-
use crate::{bios, print, println, Ctx, API};
3+
use crate::{bios, osprint, osprintln, Ctx, API};
44

55
pub static LSBLK_ITEM: menu::Item<Ctx> = menu::Item {
66
item_type: menu::ItemType::Callback {
@@ -34,7 +34,7 @@ fn lsblk(_menu: &menu::Menu<Ctx>, _item: &menu::Item<Ctx>, _args: &[&str], _ctx:
3434
let api = API.get();
3535
let mut found = false;
3636

37-
println!("Block Devices:");
37+
osprintln!("Block Devices:");
3838
for dev_idx in 0..=255u8 {
3939
if let bios::FfiOption::Some(device_info) = (api.block_dev_get_info)(dev_idx) {
4040
let (bsize, bunits, dsize, dunits) =
@@ -48,12 +48,12 @@ fn lsblk(_menu: &menu::Menu<Ctx>, _item: &menu::Item<Ctx>, _args: &[&str], _ctx:
4848
(10 * x / (1024 * 1024 * 1024), "GiB", x / 100_000_000, "GB")
4949
}
5050
};
51-
println!("Device {}:", dev_idx);
52-
println!(" Name: {}", device_info.name);
53-
println!(" Type: {:?}", device_info.device_type);
54-
println!(" Block size: {}", device_info.block_size);
55-
println!(" Num Blocks: {}", device_info.num_blocks);
56-
println!(
51+
osprintln!("Device {}:", dev_idx);
52+
osprintln!(" Name: {}", device_info.name);
53+
osprintln!(" Type: {:?}", device_info.device_type);
54+
osprintln!(" Block size: {}", device_info.block_size);
55+
osprintln!(" Num Blocks: {}", device_info.num_blocks);
56+
osprintln!(
5757
" Card Size: {}.{} {} ({}.{} {})",
5858
bsize / 10,
5959
bsize % 10,
@@ -62,30 +62,30 @@ fn lsblk(_menu: &menu::Menu<Ctx>, _item: &menu::Item<Ctx>, _args: &[&str], _ctx:
6262
dsize % 10,
6363
dunits
6464
);
65-
println!(" Ejectable: {}", device_info.ejectable);
66-
println!(" Removable: {}", device_info.removable);
67-
println!(" Media Present: {}", device_info.media_present);
68-
println!(" Read Only: {}", device_info.read_only);
65+
osprintln!(" Ejectable: {}", device_info.ejectable);
66+
osprintln!(" Removable: {}", device_info.removable);
67+
osprintln!(" Media Present: {}", device_info.media_present);
68+
osprintln!(" Read Only: {}", device_info.read_only);
6969
found = true;
7070
}
7171
}
7272
if !found {
73-
println!(" None");
73+
osprintln!(" None");
7474
}
7575
}
7676

7777
/// Called when the "read_block" command is executed.
7878
fn read_block(_menu: &menu::Menu<Ctx>, _item: &menu::Item<Ctx>, args: &[&str], _ctx: &mut Ctx) {
7979
let api = API.get();
8080
let Ok(dev_idx) = args[0].parse::<u8>() else {
81-
println!("Couldn't parse {:?}", args[0]);
81+
osprintln!("Couldn't parse {:?}", args[0]);
8282
return;
8383
};
8484
let Ok(block_idx) = args[1].parse::<u64>() else {
85-
println!("Couldn't parse {:?}", args[1]);
85+
osprintln!("Couldn't parse {:?}", args[1]);
8686
return;
8787
};
88-
println!("Reading block {}:", block_idx);
88+
osprintln!("Reading block {}:", block_idx);
8989
let mut buffer = [0u8; 512];
9090
match (api.block_read)(
9191
dev_idx,
@@ -97,16 +97,16 @@ fn read_block(_menu: &menu::Menu<Ctx>, _item: &menu::Item<Ctx>, args: &[&str], _
9797
// Carry on
9898
let mut count = 0;
9999
for chunk in buffer.chunks(32) {
100-
print!("{:03x}: ", count);
100+
osprint!("{:03x}: ", count);
101101
for b in chunk {
102-
print!("{:02x}", *b);
102+
osprint!("{:02x}", *b);
103103
}
104104
count += chunk.len();
105-
println!();
105+
osprintln!();
106106
}
107107
}
108108
bios::ApiResult::Err(e) => {
109-
println!("Failed to read: {:?}", e);
109+
osprintln!("Failed to read: {:?}", e);
110110
}
111111
}
112112
}

src/commands/config.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Configuration related commands for Neotron OS
22
3-
use crate::{config, println, Ctx};
3+
use crate::{config, osprintln, Ctx};
44

55
pub static COMMAND_ITEM: menu::Item<Ctx> = menu::Item {
66
item_type: menu::ItemType::Callback {
@@ -27,66 +27,66 @@ fn command(_menu: &menu::Menu<Ctx>, _item: &menu::Item<Ctx>, args: &[&str], ctx:
2727
"reset" => match config::Config::load() {
2828
Ok(new_config) => {
2929
ctx.config = new_config;
30-
println!("Loaded OK.");
30+
osprintln!("Loaded OK.");
3131
}
3232
Err(e) => {
33-
println!("Error loading; {}", e);
33+
osprintln!("Error loading; {}", e);
3434
}
3535
},
3636
"save" => match ctx.config.save() {
3737
Ok(_) => {
38-
println!("Saved OK.");
38+
osprintln!("Saved OK.");
3939
}
4040
Err(e) => {
41-
println!("Error saving: {}", e);
41+
osprintln!("Error saving: {}", e);
4242
}
4343
},
4444
"vga" => match args.get(1).cloned() {
4545
Some("on") => {
4646
ctx.config.set_vga_console(true);
47-
println!("VGA now on");
47+
osprintln!("VGA now on");
4848
}
4949
Some("off") => {
5050
ctx.config.set_vga_console(false);
51-
println!("VGA now off");
51+
osprintln!("VGA now off");
5252
}
5353
_ => {
54-
println!("Give on or off as argument");
54+
osprintln!("Give on or off as argument");
5555
}
5656
},
5757
"serial" => match (args.get(1).cloned(), args.get(1).map(|s| s.parse::<u32>())) {
5858
(_, Some(Ok(baud))) => {
59-
println!("Turning serial console on at {} bps", baud);
59+
osprintln!("Turning serial console on at {} bps", baud);
6060
ctx.config.set_serial_console_on(baud);
6161
}
6262
(Some("off"), _) => {
63-
println!("Turning serial console off");
63+
osprintln!("Turning serial console off");
6464
ctx.config.set_serial_console_off();
6565
}
6666
_ => {
67-
println!("Give off or an integer as argument");
67+
osprintln!("Give off or an integer as argument");
6868
}
6969
},
7070
"print" => {
71-
println!("VGA : {}", ctx.config.get_vga_console());
71+
osprintln!("VGA : {}", ctx.config.get_vga_console());
7272
match ctx.config.get_serial_console() {
7373
None => {
74-
println!("Serial: off");
74+
osprintln!("Serial: off");
7575
}
7676
Some((_port, config)) => {
77-
println!("Serial: {} bps", config.data_rate_bps);
77+
osprintln!("Serial: {} bps", config.data_rate_bps);
7878
}
7979
}
8080
}
8181
_ => {
82-
println!("config print - print the config");
83-
println!("config help - print this help text");
84-
println!("config reset - load config from BIOS store");
85-
println!("config save - save config to BIOS store");
86-
println!("config vga on - turn VGA on");
87-
println!("config vga off - turn VGA off");
88-
println!("config serial off - turn serial console off");
89-
println!("config serial <baud> - turn serial console on with given baud rate");
82+
osprintln!("config print - print the config");
83+
osprintln!("config help - print this help text");
84+
osprintln!("config reset - load config from BIOS store");
85+
osprintln!("config save - save config to BIOS store");
86+
osprintln!("config vga on - turn VGA on");
87+
osprintln!("config vga off - turn VGA off");
88+
osprintln!("config serial off - turn serial console off");
89+
osprintln!("config serial <baud> - turn serial console on with given baud rate");
9090
}
9191
}
9292
}

src/commands/fs.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use embedded_sdmmc::VolumeIdx;
44

5-
use crate::{bios, print, println, Ctx};
5+
use crate::{bios, osprint, osprintln, Ctx};
66

77
pub static DIR_ITEM: menu::Item<Ctx> = menu::Item {
88
item_type: menu::ItemType::Callback {
@@ -28,7 +28,7 @@ pub static LOAD_ITEM: menu::Item<Ctx> = menu::Item {
2828
/// Called when the "dir" command is executed.
2929
fn dir(_menu: &menu::Menu<Ctx>, _item: &menu::Item<Ctx>, _args: &[&str], _ctx: &mut Ctx) {
3030
fn work() -> Result<(), embedded_sdmmc::Error<bios::Error>> {
31-
println!("Listing files on Block Device 0, /");
31+
osprintln!("Listing files on Block Device 0, /");
3232
let bios_block = crate::fs::BiosBlock();
3333
let time = crate::fs::BiosTime();
3434
let mut mgr = embedded_sdmmc::VolumeManager::new(bios_block, time);
@@ -41,60 +41,61 @@ fn dir(_menu: &menu::Menu<Ctx>, _item: &menu::Item<Ctx>, _args: &[&str], _ctx: &
4141
let padding = 8 - dir_entry.name.base_name().len();
4242
for b in dir_entry.name.base_name() {
4343
let ch = *b as char;
44-
print!("{}", if ch.is_ascii_graphic() { ch } else { '?' });
44+
osprint!("{}", if ch.is_ascii_graphic() { ch } else { '?' });
4545
}
4646
for _ in 0..padding {
47-
print!(" ");
47+
osprint!(" ");
4848
}
49-
print!(" ");
49+
osprint!(" ");
5050
let padding = 3 - dir_entry.name.extension().len();
5151
for b in dir_entry.name.extension() {
5252
let ch = *b as char;
53-
print!("{}", if ch.is_ascii_graphic() { ch } else { '?' });
53+
osprint!("{}", if ch.is_ascii_graphic() { ch } else { '?' });
5454
}
5555
for _ in 0..padding {
56-
print!(" ");
56+
osprint!(" ");
5757
}
5858
if dir_entry.attributes.is_directory() {
59-
print!(" <DIR> ");
59+
osprint!(" <DIR> ");
6060
} else {
61-
print!(" {:-13}", dir_entry.size,);
61+
osprint!(" {:-13}", dir_entry.size,);
6262
}
63-
print!(
63+
osprint!(
6464
" {:02}/{:02}/{:04}",
6565
dir_entry.mtime.zero_indexed_day + 1,
6666
dir_entry.mtime.zero_indexed_month + 1,
6767
u32::from(dir_entry.mtime.year_since_1970) + 1970
6868
);
69-
println!(
69+
osprintln!(
7070
" {:02}:{:02}",
71-
dir_entry.mtime.hours, dir_entry.mtime.minutes
71+
dir_entry.mtime.hours,
72+
dir_entry.mtime.minutes
7273
);
7374
total_bytes += dir_entry.size as u64;
7475
num_files += 1;
7576
})?;
76-
println!("{:-9} file(s) {:-13} bytes", num_files, total_bytes);
77+
osprintln!("{:-9} file(s) {:-13} bytes", num_files, total_bytes);
7778
Ok(())
7879
}
7980

8081
match work() {
8182
Ok(_) => {}
8283
Err(e) => {
83-
println!("Error: {:?}", e);
84+
osprintln!("Error: {:?}", e);
8485
}
8586
}
8687
}
8788

8889
/// Called when the "load" command is executed.
8990
fn load(_menu: &menu::Menu<Ctx>, _item: &menu::Item<Ctx>, args: &[&str], ctx: &mut Ctx) {
9091
let Some(filename) = args.first() else {
91-
println!("Need a filename");
92+
osprintln!("Need a filename");
9293
return;
9394
};
9495
match ctx.tpa.load_program(filename) {
9596
Ok(_) => {}
9697
Err(e) => {
97-
println!("Error: {:?}", e);
98+
osprintln!("Error: {:?}", e);
9899
}
99100
}
100101
}

0 commit comments

Comments
 (0)