Skip to content

Commit

Permalink
In CI added windows_latest, help added and array margin checking.
Browse files Browse the repository at this point in the history
  • Loading branch information
tpanj committed Apr 3, 2024
1 parent f94dcef commit 4112bfa
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 54 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# This is a basic workflow to help you get started with Actions

name: CI

# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "master" branch
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
build:
strategy:
matrix:
os: ["ubuntu-latest", "windows-latest"]
runs-on: ${{ matrix.os }}

steps:
- name: Install V
uses: vlang/setup-v@v1
with:
check-latest: true

- name: Checkout ${{ github.event.repository.name }}
uses: actions/checkout@v2

# Does not check format since works different under different OS
# - name: Check if code is formatted
# run: |
# v fmt -diff .
# v fmt -verify .

- name: Build ${{ github.event.repository.name }}
run: v . -o cht

- name: Run Tests
run: v test .
46 changes: 0 additions & 46 deletions .github/workflows/blank.yml

This file was deleted.

23 changes: 18 additions & 5 deletions src/cht.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import net.http
import os
import os.cmdline

const cht_version := '0.7.0'
const cht_version := '0.7.2'

fn main() {

Expand All @@ -27,16 +27,29 @@ fn main() {
'-Q', '--query' {
use_query = true
}
'-l' { domain = cmdline.option(os.args, '-l', '')
'-l' {
domain = cmdline.option(os.args, '-l', '')
qs += domain.str()
qs += '/'
}
'-v', '--version' { println('cht version ' + cht_version + ' (c) Tadej Panjtar')
'-V', '--version' {
println('cht version ' + cht_version + ' (c) Tadej Panjtar')
exit(0)
}
else { println ('Unknown option: ' + opt)
'-h', '--help' {
println('\nUsage: cht [options...] <URL>')
println('Options:')
println(' -Q, --query Space delimited arguments are parts of query (now default)')
println(' -T, --no_colors Disabling coloring globally')
println(' -V, --version Show version and exits')
println(' -TA,--force_ansi_colors Force ANSI colors')
println(' -l Domain language set')
exit(0)
}
else {
println('Unknown option: "${opt}"')
exit(1)
}
}
}

Expand All @@ -49,7 +62,7 @@ fn main() {
}
first_handeled = true
}
qs = qs.trim('+')
qs = qs.trim('+/')

// Dummy usage to get rid of warnings
if use_query {
Expand Down
8 changes: 5 additions & 3 deletions src/cht_colors_windows.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,18 @@ fn println_colored(s string, use_colors bool, force_ansi_colors bool)! {
if str_first>0 {
for i :=0; i<words.len; i++ {
print(words[i])
if i < words.len -1 {
if i < words.len -1 && i < escapes.len {
C.SetConsoleTextAttribute(hconsole
, (info.wAttributes & 0xFFF0) | a2w_color(escapes[i]))
}
}
}
else {
for i :=0; i<words.len; i++ {
C.SetConsoleTextAttribute(hconsole
, (info.wAttributes & 0xFFF0) | a2w_color(escapes[i]))
if i < words.len -1 && i < escapes.len {
C.SetConsoleTextAttribute(hconsole
, (info.wAttributes & 0xFFF0) | a2w_color(escapes[i]))
}
print(words[i])
}
}
Expand Down
46 changes: 46 additions & 0 deletions test/options_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import os

const output_search_terms = [
'Usage',
'Options',
'-T, --no_colors',
'-TA,--force_ansi_colors'
'--version',
]

fn test_help() {
flags := ['--help', '-h']

for flag in flags {
result := os.execute_or_panic(os.join_path(os.getwd(), "cht") + ' ${flag}')

assert result.exit_code == 0
for term in output_search_terms {
assert result.output.contains(term)
}
}
}

fn test_version() {
flags := ['--version', '-V']

for flag in flags {
result := os.execute_or_panic(os.join_path(os.getwd(), "cht") + ' ${flag}')

assert result.exit_code == 0
for term in ['Panjtar', 'version'] {
assert result.output.contains(term)
}
}
}

fn test_wrong_option() {
flags := ['--Unsuported_long_option_with_agrument arg1', '--Unsuported_long_option', '-QWER']

for flag in flags {
result := os.execute(os.join_path(os.getwd(), "cht") + ' ${flag}')

assert result.exit_code == 1
assert result.output.contains('Unknown')
}
}

0 comments on commit 4112bfa

Please sign in to comment.