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

WIP: Test page's code blocks #74

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 3 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
61 changes: 61 additions & 0 deletions spec/code_block_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
require 'spec_helper'
require 'kramdown'
require 'ap'

content = File.join(File.dirname(__FILE__), '..','content', '**', '*.md')
PAGES = Dir.glob(content)

def extract_code(parent)
codespans = []
parent.children.each do |child|

# Checks ... parent value hasn't got any sibling or begin with '\n'
#<<< TODO: ^^^ Why?
if child.type == :codespan \
&& !child.value.nil? \ #<<< remove?, investigate
&& !codespans.include?(child.value) \ #<<< remove, keep context
&& ((parent.children.size == 1) || (child.value[/^\n/])) #<<< use start_with?

codespans.push child.value.gsub "\n",' ' #<<< .split and add to codespans
#<<< add .trim - white space in the beginning and end
end

codespans += extract_code(child)
end
codespans
end

PAGES.each do |page|
generated_page = Kramdown::Document.new(File.read(page)) #<<< MD
codespans = extract_code(generated_page.root) #<<< lines of code, rename?
results = [] #<<< to Hash: {codespan => result}

describe 'Command in Markdown file' do

it 'has a good syntax' do #<<< passes syntax check
codespans.each do |code|
if code[/^\$/] #code starts with '$'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me like we want to have different tests for various code-lines (commands).
Meaning this logic could be deciding for the test enablement, but from the level above.

results.push([code,system('bash', '-n', '-c', code, "&>/dev/null")]) #<<< do not execute here
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now it occured to me we could also do a lazy evaluation. Meaning we'll define custom default for the Hash .

expect(results[-1][1]).to be_truthy,"Something wrong with: '#{code}'"
elsif code[/^\#/] #<<< code.starts_with? ?#
#ap code
else #code starts with something else
#ap code
end
end
end

it 'does not begin with #' do
skip
end

it 'starts with $' do
skip
end

it 'runs dnf with sudo' do
skip
end

end
end